Tuesday, September 16, 2025
HomeLanguagesPHPUnit assertXmlFileEqualsXmlFile() Function

PHPUnit assertXmlFileEqualsXmlFile() Function

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

assertXmlFileEqualsXmlFile(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 assertXmlFileEqualsXmlFile() function in PHPUnit:

Example 1:

PHP




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
{ 
    public function testNegativeTestcaseForassertXmlFileEqualsXmlFile()
    { 
        $actualFile =  '/home/lovely/Documents/php/actual.xml';
        $expectedFile     = '/home/lovely/Documents/php/expected.xml'; 
        
        // Assert function to test whether given 
        // expected xml file is equal to actual xml file or not
        $this->assertXmlFileEqualsXmlFile(
            $actualFile,
            $expectedFile, 
            "actual xml file equal to expected xml file or not"
        ); 
    } 
} 
    
?> 


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::testNegativeTestcaseForassertXmlFileEqualsXmlFile
actual xml file equal to expected xml file or not
Failed asserting that two DOM documents are equal.
--- Expected
+++ Actual
@@ @@
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
-    <price>444.95</price>
+    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications
      with XML.</description>

/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 testPositiveTestcaseForassertXmlFileEqualsXmlFile()
    { 
        $actualFile =  '/home/lovely/Documents/php/actual.xml';
        $expectedFile    = '/home/lovely/Documents/php/expected.xml'; 
        // Assert function to test whether given 
        // expected xml file is equal to actual xml file or not
        $this->assertXmlFileEqualsXmlFile(
            $actualFile,
            $expectedFile, 
            "actual xml file equal to expected xml file or not"
        ); 
    } 
} 
    
?> 


Example:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                                 1 / 1 (100%)

Time: 87 ms, Memory: 10.00 MB

OK (1 test, 1 assertion)

Reference:https://phpunit.readthedocs.io/en/9.2/assertions.html#assertxmlfileequalsxmlfile

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
32293 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6656 POSTS0 COMMENTS
Nicole Veronica
11826 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11892 POSTS0 COMMENTS
Shaida Kate Naidoo
6773 POSTS0 COMMENTS
Ted Musemwa
7044 POSTS0 COMMENTS
Thapelo Manthata
6729 POSTS0 COMMENTS
Umr Jansen
6739 POSTS0 COMMENTS