assertJsonStringEqualsJsonFile()


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

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


例 A.34: assertJsonStringEqualsJsonFile() 的用法

  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3.  
  4. class JsonStringEqualsJsonFileTest extends TestCase
  5. {
  6. public function testFailure()
  7. {
  8. $this->assertJsonStringEqualsJsonFile(
  9. 'path/to/fixture/file', json_encode(['Mascot' => 'ux'])
  10. );
  11. }
  12. }
  13. ?>
  1. phpunit JsonStringEqualsJsonFileTest
  2. PHPUnit 6.5.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.