📜  PHPUnit assertXmlStringNotEqualsXmlFile()函数

📅  最后修改于: 2022-05-13 01:56:52.176000             🧑  作者: Mango

PHPUnit assertXmlStringNotEqualsXmlFile()函数

assertXmlStringNotEqualsXmlFile()函数是 PHPUnit 中的内置函数,用于断言实际的 XML 文件内容是否不等于预期的 XML字符串。如果预期的 XML字符串与实际的 XML 文件内容不同,则此断言将返回 true,否则返回 false。如果为真,则断言的测试用例通过,否则测试用例失败。

句法:

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

参数:此函数接受三个参数,如上所述,如下所述:

  • $expectedXmlString:这个参数是代表期望的 XML字符串的任何类型。
  • $actualXmlFile:此参数是表示实际 XML 文件路径的任何类型。
  • $message:此参数采用字符串值。当测试用例失败时,此字符串消息显示为错误消息。

下面的示例说明了 PHPUnit 中的 assertXmlstringNotEqualsXmlFile()函数:

示例 1:

PHP
'; 
        $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"
        ); 
    } 
} 
    
?>


PHP
'; 
        $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"
        ); 
    } 
} 
    
?>


输出:

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.

示例 2:

PHP

'; 
        $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"
        ); 
    } 
} 
    
?> 

输出:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                                 1 / 1 (100%)

Time: 87 ms, Memory: 10.00 MB

OK (1 test, 1 assertion)