assertXmlStringEqualsXmlString()


assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml[, string $message = ''])

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

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


例 A.53: assertXmlStringEqualsXmlString() 的用法

  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3.  
  4. class XmlStringEqualsXmlStringTest extends TestCase
  5. {
  6. public function testFailure()
  7. {
  8. $this->assertXmlStringEqualsXmlString(
  9. '<foo><bar/></foo>', '<foo><baz/></foo>');
  10. }
  11. }
  12. ?>
  1. phpunit XmlStringEqualsXmlStringTest
  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) XmlStringEqualsXmlStringTest::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/XmlStringEqualsXmlStringTest.php:7
  22.  
  23. FAILURES!
  24. Tests: 1, Assertions: 1, Failures: 1.

原文: https://phpunit.de/manual/6.5/zh_cn/appendixes.assertions.html