assertJsonStringEqualsJsonString()


assertJsonStringEqualsJsonString(mixed $expectedJson, mixed $actualJson[, string $message = ''])

$actualJson 对应的值与 $expectedJson 对应的值不匹配时报告错误,错误讯息由 $message 指定。


例 A.27: assertJsonStringEqualsJsonString() 的用法

  1. <?php
  2. class JsonStringEqualsJsonStringTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testFailure()
  5. {
  6. $this->assertJsonStringEqualsJsonString(
  7. json_encode(array("Mascot" => "Tux")), json_encode(array("Mascott" => "ux"))
  8. );
  9. }
  10. }
  11. ?>
  1. phpunit JsonStringEqualsJsonStringTest
  2. PHPUnit 4.8.0 by Sebastian Bergmann and contributors.
  3.  
  4. F
  5.  
  6. Time: 0 seconds, Memory: 5.00Mb
  7.  
  8. There was 1 failure:
  9.  
  10. 1) JsonStringEqualsJsonStringTest::testFailure
  11. Failed asserting that two objects are equal.
  12. --- Expected
  13. +++ Actual
  14. @@ @@
  15. stdClass Object (
  16. - 'Mascot' => 'Tux'
  17. + 'Mascot' => 'ux'
  18. )
  19.  
  20. /home/sb/JsonStringEqualsJsonStringTest.php:5
  21.  
  22. FAILURES!
  23. Tests: 1, Assertions: 3, Failures: 1.