assertJsonFileEqualsJsonFile()


assertJsonFileEqualsJsonFile(mixed $expectedFile, mixed $actualFile[, string $message = ''])

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


例 A.33: assertJsonFileEqualsJsonFile() 的用法

  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3.  
  4. class JsonFileEqualsJsonFileTest extends TestCase
  5. {
  6. public function testFailure()
  7. {
  8. $this->assertJsonFileEqualsJsonFile(
  9. 'path/to/fixture/file', 'path/to/actual/file');
  10. }
  11. }
  12. ?>
  1. phpunit JsonFileEqualsJsonFileTest
  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) JsonFileEqualsJsonFile::testFailure
  11. Failed asserting that '{"Mascot":"Tux"}' matches JSON string "["Mascott", "Tux", "OS", "Linux"]".
  12.  
  13. /home/sb/JsonFileEqualsJsonFileTest.php:5
  14.  
  15. FAILURES!
  16. Tests: 1, Assertions: 3, Failures: 1.