您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertXmlFileEqualsXmlFile
发布时间:2021-10-06 11:40:15编辑:雪饮阅读()
assertXmlFileEqualsXmlFile断言用于断言一个xml文件的内容与另外一个xml文件的内容是否相同。
先看看参与实例的3个xml,1.xml,2.xml,3.xml的内容:
C:\Users\Administrator>type D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
C:\Users\Administrator>type D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\2.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
C:\Users\Administrator>type D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\3.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George3</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
那么具体的实例:
XmlFileEqualsXmlFileTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class XmlFileEqualsXmlFileTest extends TestCase
{
public function testFailure(): void
{
$this->assertXmlFileEqualsXmlFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.xml', 'D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\3.xml');
}
public function testSuccess(): void
{
$this->assertXmlFileEqualsXmlFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.xml', 'D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\2.xml');
}
}
use PHPUnit\Framework\TestCase;
final class XmlFileEqualsXmlFileTest extends TestCase
{
public function testFailure(): void
{
$this->assertXmlFileEqualsXmlFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.xml', 'D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\3.xml');
}
public function testSuccess(): void
{
$this->assertXmlFileEqualsXmlFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.xml', 'D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\2.xml');
}
}
运行结果如:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\XmlFileEqualsXmlFileTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.013, Memory: 6.00 MB
There was 1 failure:
1) XmlFileEqualsXmlFileTest::testFailure
Failed asserting that two DOM documents are equal.
--- Expected
+++ Actual
@@ @@
<?xml version="1.0"?>
<note>
- <to>George</to>
+ <to>George3</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\XmlFileEqualsXmlFileTest.php:8
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
关键字词:phpunit,assertXmlFileEqualsXmlFile
相关文章
- phpunit断言-assertTrue
- phpunit断言-assertStringStartsWith
- phpunit断言-assertStringEqualsFile
- phpunit断言-assertStringEndsWith
- phpunit断言-assertSame-对象断言
- phpunit断言-assertSame
- phpunit断言-assertStringMatchesFormatFile
- phpunit断言-assertStringMatchesFormat
- phpunit断言-assertMatchesRegularExpression
- phpunit断言-assertObjectHasAttribute