PHPUnit assertXmlFileNotEqualsXmlFile() Function
Last Updated :
09 Aug, 2020
The assertXmlFileNotEqualsXmlFile() function is a builtin function in PHPUnit and is used to assert whether the actual XML file Content is not equals to expected XML file content. This assertion will return true in the case if the expected XML file content is not the same as the actual XML file content else returns false. In case of true the asserted test case got passed else test case got failed.
Syntax:
assertXmlFileNotEqualsXmlFile(string $expectedFile,
string $actualFile[, string $message = ''])
Parameters: This function accepts three parameters as mentioned above and described below:
- $expectedFile: This parameter is of any type which represents the expected XML File Path.
- $actualFile: This parameter is of any type which represents the actual XML File Path.
- $message: This parameter takes a string value. When the test case got failed this string message got displayed as an error message.
Below examples illustrate the assertXmlFileNotEqualsXmlFile() function in PHPUnit:
Example 1:
PHP
<?php
use PHPUnit\Framework\TestCase;
class GeeksPhpunitTestCase extends TestCase
{
public function testNegativeTestcaseForassertXmlFileNotEqualsXmlFile()
{
$actualFile = '/home/lovely/Documents/php/actual.xml' ;
$expectedFile = '/home/lovely/Documents/php/expected.xml' ;
$this ->assertXmlFileNotEqualsXmlFile(
$actualFile ,
$expectedFile ,
"actual xml file is not equal to expected xml file"
);
}
}
?>
|
Output:
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 89 ms, Memory: 10.00 MB
There was 1 failure:
1) GeeksPhpunitTestCase::testNegativeTestcaseForassertXmlFileNotEqualsXmlFile
actual xml file is not equal to expected xml file
Failed asserting that DOMDocument Object &000000000788a1260000000067204f26
() is not equal to DOMDocument Object &000000000788a1210000000067204f26 ().
/home/lovely/Documents/php/test.php:16
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Example 2:
PHP
<?php
use PHPUnit\Framework\TestCase;
class GeeksPhpunitTestCase extends TestCase
{
public function testPositiveTestcaseForassertXmlFileNotEqualsXmlFile()
{
$actualFile = '/home/lovely/Documents/php/actual.xml' ;
$expectedFile = '/home/lovely/Documents/php/expected.xml' ;
$this ->assertXmlFileNotEqualsXmlFile(
$actualFile ,
$expectedFile ,
"actual xml file is not equal to expected xml file"
);
}
}
?>
|
Output:
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 88 ms, Memory: 10.00 MB
OK (1 test, 1 assertion)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...