assertFileEquals()


assertFileEquals(string $expected, string $actual[, string $message = ''])

$expected 所指定的文件与 $actual 所指定的文件内容不同时报告错误,错误讯息由 $message 指定。

assertFileNotEquals() 是与之相反的断言,接受相同的参数。


例 A.19: assertFileEquals() 的用法

  1. <?php
  2. class FileEqualsTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testFailure()
  5. {
  6. $this->assertFileEquals('/home/sb/expected', '/home/sb/actual');
  7. }
  8. }
  9. ?>
  1. phpunit FileEqualsTest
  2. PHPUnit 4.8.0 by Sebastian Bergmann and contributors.
  3.  
  4. F
  5.  
  6. Time: 0 seconds, Memory: 5.25Mb
  7.  
  8. There was 1 failure:
  9.  
  10. 1) FileEqualsTest::testFailure
  11. Failed asserting that two strings are equal.
  12. --- Expected
  13. +++ Actual
  14. @@ @@
  15. -'expected
  16. +'actual
  17. '
  18.  
  19. /home/sb/FileEqualsTest.php:6
  20.  
  21. FAILURES!
  22. Tests: 1, Assertions: 3, Failures: 1.