Saturday, November 22, 2025
HomeLanguagesPHPUnit assertXmlStringNotEqualsXmlFile() Function

PHPUnit assertXmlStringNotEqualsXmlFile() Function

The assertXmlStringNotEqualsXmlFile() function is a builtin function in PHPUnit and is used to assert whether the actual XML file Content is not equals to expected XML string. This assertion will return true in the case if the expected XML string 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:

assertXmlStringNotEqualsXmlFile(string $expectedFile, 
string $actualFile[, string $message = ''])

Parameters: This function accepts three parameters as mentioned above and described below:

  •  $expectedXmlString: This parameter is of any type which represents the expected XML string.
  •  $actualXmlFile: 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 assertXmlstringNotEqualsXmlFile() function in PHPUnit:

Example 1:

PHP




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
{ 
    public function testNegativeTestcaseForassertXmlStringNotEqualsXmlFile()
    { 
        $expectedxmlString  =  '<foo><baz></baz></foo>'; 
        $actualxmlFilePath    =  '/home/lovely/Documents/php/actual.xml';
        // Assert function to test whether given 
        // expected xml string is not equal to actual xml file path
        $this->assertXmlStringNotEqualsXmlFile(
            $actualxmlFilePath,
            $expectedxmlString,
            "actual xml file path is not equal to expected xml string"
        ); 
    } 
} 
    
?> 


Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

F                                                                1 / 1 (100%)

Time: 88 ms, Memory: 10.00 MB

There was 1 failure:

1) GeeksPhpunitTestCase::testPositiveTestcaseForassertXmlFileNotEqualsXmlFile
actual xml file path is equal to expected xml string
Failed asserting that DOMDocument Object &00000000619c324c000000000e19116f 
() is not equal to DOMDocument Object &00000000619c324b000000000e19116f ().

/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 testPositiveTestcaseForassertXmlStringNotEqualsXmlFile()
    { 
        $expectedxmlString  =  '<foo><baza></baza></foo>'; 
        $actualxmlFilePath    =  '/home/lovely/Documents/php/actual.xml';
        // Assert function to test whether given 
        // expected xml string is not equal to actual xml file path
        $this->assertXmlStringNotEqualsXmlFile(
            $actualxmlFilePath,
            $expectedxmlString,
            "actual xml file path is not equal to expected xml string"
        ); 
    } 
} 
    
?> 


Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                                 1 / 1 (100%)

Time: 87 ms, Memory: 10.00 MB

OK (1 test, 1 assertion)
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS