assertJsonStringEqualsJsonFile()


assertJsonStringEqualsJsonFile(mixed $expectedFile, mixed $actualJson[, string $message = ''])

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


例 A.26: assertJsonStringEqualsJsonFile() 的用法

  1. <?php
  2. class JsonStringEqualsJsonFileTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testFailure()
  5. {
  6. $this->assertJsonStringEqualsJsonFile(
  7. 'path/to/fixture/file', json_encode(array("Mascot" => "ux"))
  8. );
  9. }
  10. }
  11. ?>
  1. phpunit JsonStringEqualsJsonFileTest
  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) JsonStringEqualsJsonFile::testFailure
  11. Failed asserting that '{"Mascot":"ux"}' matches JSON string "{"Mascott":"Tux"}".
  12.  
  13. /home/sb/JsonStringEqualsJsonFileTest.php:5
  14.  
  15. FAILURES!
  16. Tests: 1, Assertions: 3, Failures: 1.