Friday, October 24, 2025
HomeLanguagesPHPUnit assertXmlStringNotEqualsXmlString() Function

PHPUnit assertXmlStringNotEqualsXmlString() Function

The assertXmlStringNotEqualsXmlString() function is a builtin function in PHPUnit and is used to assert whether the actual XML string 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 string else returns false. In case of true the asserted test case got passed else test case got failed.

Syntax:

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

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

  • $expectedXmlString: This parameter is of any type which represent the expected Xml string.
  • $actualXmlString: This parameter is of any type which represent the actual Xml String.
  • $message: This parameter takes string value. When the test case got failed this string message got displayed as error message.

Below examples illustrate the assertXmlStringNotEqualsXmlString() function in PHPUnit:

Example 1:

PHP




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
{ 
    public function testNegativeTestcaseForassertXmlStringNotEqualsXmlString()
    { 
        $expectedxmlString  =  '<foo><baz></baz></foo>'; 
        $actualxmlString    =  '<foo><baz></baz></foo>';
        // Assert function to test whether given 
        // expected xml string is not equal to actual xml string
        $this->assertXmlStringNotEqualsXmlString(
            $actualxmlString,
            $expectedxmlString,
            "actual xml string is not equal to expected xml string"
        ); 
    } 
} 
    
?> 


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::testPositiveTestcaseForassertXmlFileNotEqualsXmlFile
actual xml string is equal to expected xml string
Failed asserting that DOMDocument Object &000000007c4380e1000000004a99fb25 
() is not equal to DOMDocument Object &000000007c4380e6000000004a99fb25 ().

/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 testPositiveTestcaseForassertXmlStringNotEqualsXmlString()
    { 
        $expectedxmlString  =  '<foo><bazx></bazx></foo>'; 
        $actualxmlString    =  '<foo><baz></baz></foo>';
        // Assert function to test whether given 
        // expected xml string is not equal to actual xml string
        $this->assertXmlStringNotEqualsXmlString(
            $actualxmlString,
            $expectedxmlString,
            "actual xml string 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)

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS