assertXmlStringEqualsXmlFile()


assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml[, string $message = ''])

$actualXml 对应的 XML 文档与 $expectedFile 对应的 XML 文档不相同时报告错误,错误讯息由 $message 指定。

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


例 A.43: assertXmlStringEqualsXmlFile() 的用法

  1. <?php
  2. class XmlStringEqualsXmlFileTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testFailure()
  5. {
  6. $this->assertXmlStringEqualsXmlFile(
  7. '/home/sb/expected.xml', '<foo><baz/></foo>');
  8. }
  9. }
  10. ?>
  1. phpunit XmlStringEqualsXmlFileTest
  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) XmlStringEqualsXmlFileTest::testFailure
  11. Failed asserting that two DOM documents are equal.
  12. --- Expected
  13. +++ Actual
  14. @@ @@
  15. <?xml version="1.0"?>
  16. <foo>
  17. - <bar/>
  18. + <baz/>
  19. </foo>
  20.  
  21. /home/sb/XmlStringEqualsXmlFileTest.php:7
  22.  
  23. FAILURES!
  24. Tests: 1, Assertions: 2, Failures: 1.