PHPUnit-附录 A. 断言 (assert)
【http://www.phpunit.cn/manual/5.7/zh_cn/appendixes.assertions.html】
?
本附錄列舉可用的各種斷言方法。
assertArrayHasKey()
assertArrayHasKey(mixed $key, array $array[, string $message = ''])
當(dāng) $array 不包含 $key 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertArrayNotHasKey() 是與之相反的斷言,接受相同的參數(shù)。
例 A.1: assertArrayHasKey() 的用法
phpunit ArrayHasKeyTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ArrayHasKeyTest::testFailure Failed asserting that an array has the key 'foo'./home/sb/ArrayHasKeyTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertClassHasAttribute()
assertClassHasAttribute(string $attributeName, string $className[, string $message = ''])
當(dāng) $className::attributeName 不存在時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertClassNotHasAttribute() 是與之相反的斷言,接受相同的參數(shù)。
例 A.2: assertClassHasAttribute() 的用法
phpunit ClassHasAttributeTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) ClassHasAttributeTest::testFailure Failed asserting that class "stdClass" has attribute "foo"./home/sb/ClassHasAttributeTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertArraySubset()
assertArraySubset(array $subset, array $array[, bool $strict = '', string $message = ''])
當(dāng) $array 不包含 $subset 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
$strict 是一個(gè)標(biāo)志,用于表明是否需要對(duì)數(shù)組中的對(duì)象進(jìn)行全等判定。
例 A.3: assertArraySubset() 的用法
phpunit ArrayHasKeyTest PHPUnit 4.4.0 by Sebastian Bergmann.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) Epilog\EpilogTest::testNoFollowOption Failed asserting that an array has the subset Array &0 ('config' => Array &1 (0 => 'key-a'1 => 'key-b') )./home/sb/ArraySubsetTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertClassHasStaticAttribute()
assertClassHasStaticAttribute(string $attributeName, string $className[, string $message = ''])
當(dāng) $className::attributeName 不存在時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertClassNotHasStaticAttribute() 是與之相反的斷言,接受相同的參數(shù)。
例 A.4: assertClassHasStaticAttribute() 的用法
phpunit ClassHasStaticAttributeTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) ClassHasStaticAttributeTest::testFailure Failed asserting that class "stdClass" has static attribute "foo"./home/sb/ClassHasStaticAttributeTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertContains()
assertContains(mixed $needle, Iterator|array $haystack[, string $message = ''])
當(dāng) $needle 不是 $haystack的元素時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotContains() 是與之相反的斷言,接受相同的參數(shù)。
assertAttributeContains() 和 assertAttributeNotContains() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮?public、protected 或 private 屬性為搜索范圍。
例 A.5: assertContains() 的用法
phpunit ContainsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsTest::testFailure Failed asserting that an array contains 4./home/sb/ContainsTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertContains(string $needle, string $haystack[, string $message = '', boolean $ignoreCase = false])
當(dāng) $needle 不是 $haystack 的子字符串時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
如果 $ignoreCase 為 true,測(cè)試將按大小寫不敏感的方式進(jìn)行。
例 A.6: assertContains() 的用法
phpunit ContainsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsTest::testFailure Failed asserting that 'foobar' contains "baz"./home/sb/ContainsTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.例 A.7: 帶有 $ignoreCase 參數(shù)的 assertContains() 的用法
phpunit ContainsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.F.Time: 0 seconds, Memory: 2.75MbThere was 1 failure:1) ContainsTest::testFailure Failed asserting that 'FooBar' contains "foo"./home/sb/ContainsTest.php:6FAILURES! Tests: 2, Assertions: 2, Failures: 1.assertContainsOnly()
assertContainsOnly(string $type, Iterator|array $haystack[, boolean $isNativeType = null, string $message = ''])
當(dāng) $haystack 并非僅包含類型為 $type 的變量時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
$isNativeType 是一個(gè)標(biāo)志,用來(lái)表明 $type 是否是原生 PHP 類型。
assertNotContainsOnly() 是與之相反的斷言,并接受相同的參數(shù)。
assertAttributeContainsOnly() 和 assertAttributeNotContainsOnly() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮?public、protected 或 private 屬性為搜索范圍。
例 A.8: assertContainsOnly() 的用法
phpunit ContainsOnlyTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsOnlyTest::testFailure Failed asserting that Array (0 => '1'1 => '2'2 => 3 ) contains only values of type "string"./home/sb/ContainsOnlyTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertContainsOnlyInstancesOf()
assertContainsOnlyInstancesOf(string $classname, Traversable|array $haystack[, string $message = ''])
當(dāng) $haystack 并非僅包含類 $classname 的實(shí)例時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.9: assertContainsOnlyInstancesOf() 的用法
phpunit ContainsOnlyInstancesOfTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsOnlyInstancesOfTest::testFailure Failed asserting that Array ([0]=> Bar Object(...)) is an instance of class "Foo"./home/sb/ContainsOnlyInstancesOfTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertCount()
assertCount($expectedCount, $haystack[, string $message = ''])
當(dāng) $haystack 中的元素?cái)?shù)量不是 $expectedCount 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotCount() 是與之相反的斷言,接受相同的參數(shù)。
例 A.10: assertCount() 的用法
phpunit CountTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) CountTest::testFailure Failed asserting that actual size 1 matches expected size 0./home/sb/CountTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertDirectoryExists()
assertDirectoryExists(string $directory[, string $message = ''])
當(dāng) $directory 所指定的目錄不存在時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertDirectoryNotExists() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.11: assertDirectoryExists() 的用法
phpunit DirectoryExistsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) DirectoryExistsTest::testFailure Failed asserting that directory "/path/to/directory" exists./home/sb/DirectoryExistsTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertDirectoryIsReadable()
assertDirectoryIsReadable(string $directory[, string $message = ''])
當(dāng) $directory 所指定的目錄不是個(gè)目錄或不可讀時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertDirectoryNotIsReadable() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.12: assertDirectoryIsReadable() 的用法
phpunit DirectoryIsReadableTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) DirectoryIsReadableTest::testFailure Failed asserting that "/path/to/directory" is readable./home/sb/DirectoryIsReadableTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertDirectoryIsWritable()
assertDirectoryIsWritable(string $directory[, string $message = ''])
當(dāng) $directory 所指定的目錄不是個(gè)目錄或不可寫時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertDirectoryNotIsWritable() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.13: assertDirectoryIsWritable() 的用法
phpunit DirectoryIsWritableTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) DirectoryIsWritableTest::testFailure Failed asserting that "/path/to/directory" is writable./home/sb/DirectoryIsWritableTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertEmpty()
assertEmpty(mixed $actual[, string $message = ''])
當(dāng) $actual 非空時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotEmpty() 是與之相反的斷言,接受相同的參數(shù)。
assertAttributeEmpty() 和 assertAttributeNotEmpty() 是便捷包裝(convenience wrapper),可以應(yīng)用于某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性。
例 A.14: assertEmpty() 的用法
phpunit EmptyTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) EmptyTest::testFailure Failed asserting that an array is empty./home/sb/EmptyTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertEqualXMLStructure()
assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement[, boolean $checkAttributes = false, string $message = ''])
當(dāng) $actualElement 中 DOMElement 的 XML 結(jié)構(gòu)與 $expectedElement 中 DOMElement的 XML 結(jié)構(gòu)不相同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.15: assertEqualXMLStructure() 的用法
phpunit EqualXMLStructureTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FFFFTime: 0 seconds, Memory: 5.75MbThere were 4 failures:1) EqualXMLStructureTest::testFailureWithDifferentNodeNames Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'foo' +'bar'/home/sb/EqualXMLStructureTest.php:92) EqualXMLStructureTest::testFailureWithDifferentNodeAttributes Number of attributes on node "foo" does not match Failed asserting that 0 matches expected 1./home/sb/EqualXMLStructureTest.php:223) EqualXMLStructureTest::testFailureWithDifferentChildrenCount Number of child nodes of "foo" differs Failed asserting that 1 matches expected 3./home/sb/EqualXMLStructureTest.php:354) EqualXMLStructureTest::testFailureWithDifferentChildren Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'bar' +'baz'/home/sb/EqualXMLStructureTest.php:48FAILURES! Tests: 4, Assertions: 8, Failures: 4.assertEquals()
assertEquals(mixed $expected, mixed $actual[, string $message = ''])
當(dāng)兩個(gè)變量 $expected 和 $actual 不相等時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotEquals() 是與之相反的斷言,接受相同的參數(shù)。
assertAttributeEquals() 和 assertAttributeNotEquals() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性作為實(shí)際值來(lái)進(jìn)行比較。
例 A.16: assertEquals() 的用法
phpunit EqualsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FFFTime: 0 seconds, Memory: 5.25MbThere were 3 failures:1) EqualsTest::testFailure Failed asserting that 0 matches expected 1./home/sb/EqualsTest.php:62) EqualsTest::testFailure2 Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'bar' +'baz'/home/sb/EqualsTest.php:113) EqualsTest::testFailure3 Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@'foo -bar +bahbaz'/home/sb/EqualsTest.php:16FAILURES! Tests: 3, Assertions: 3, Failures: 3.如果 $expected 和 $actual 是某些特定的類型,將使用更加專門的比較方式,參閱下文。
assertEquals(float $expected, float $actual[, string $message = '', float $delta = 0])
當(dāng)兩個(gè)浮點(diǎn)數(shù) $expected 和 $actual 之間的差值(的絕對(duì)值)大于 $delta 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
關(guān)于為什么 $delta 參數(shù)是必須的,請(qǐng)閱讀《關(guān)于浮點(diǎn)運(yùn)算,每一位計(jì)算機(jī)科學(xué)從業(yè)人員都應(yīng)該知道的事實(shí)》。
例 A.17: 將assertEquals()用于浮點(diǎn)數(shù)時(shí)的用法
phpunit EqualsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors..FTime: 0 seconds, Memory: 5.75MbThere was 1 failure:1) EqualsTest::testFailure Failed asserting that 1.1 matches expected 1.0./home/sb/EqualsTest.php:11FAILURES! Tests: 2, Assertions: 2, Failures: 1.assertEquals(DOMDocument $expected, DOMDocument $actual[, string $message = ''])
當(dāng) $expected 和 $actual 這兩個(gè) DOMDocument 對(duì)象所表示的 XML 文檔對(duì)應(yīng)的無(wú)注釋規(guī)范形式不相同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.18: assertEquals()應(yīng)用于 DOMDocument 對(duì)象時(shí)的用法
phpunit EqualsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) EqualsTest::testFailure Failed asserting that two DOM documents are equal. --- Expected +++ Actual @@ @@<?xml version="1.0"?> -<foo> - <bar/> -</foo> +<bar> + <foo/> +</bar>/home/sb/EqualsTest.php:12FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertEquals(object $expected, object $actual[, string $message = ''])
當(dāng) $expected 和 $actual 這兩個(gè)對(duì)象的屬性值不相等時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.19: assertEquals()應(yīng)用于對(duì)象時(shí)的用法
phpunit EqualsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) EqualsTest::testFailure Failed asserting that two objects are equal. --- Expected +++ Actual @@ @@stdClass Object ( - 'foo' => 'foo' - 'bar' => 'bar' + 'foo' => 'bar' + 'baz' => 'bar')/home/sb/EqualsTest.php:14FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertEquals(array $expected, array $actual[, string $message = ''])
當(dāng) $expected 和 $actual 這兩個(gè)數(shù)組不相等時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.20: assertEquals() 應(yīng)用于數(shù)組時(shí)的用法
phpunit EqualsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) EqualsTest::testFailure Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@Array (0 => 'a' - 1 => 'b' - 2 => 'c' + 1 => 'c' + 2 => 'd')/home/sb/EqualsTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertFalse()
assertFalse(bool $condition[, string $message = ''])
當(dāng) $condition 為 true 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotFalse() 是與之相反的斷言,接受相同的參數(shù)。
例 A.21: assertFalse() 的用法
phpunit FalseTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) FalseTest::testFailure Failed asserting that true is false./home/sb/FalseTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertFileEquals()
assertFileEquals(string $expected, string $actual[, string $message = ''])
當(dāng) $expected 所指定的文件與 $actual 所指定的文件內(nèi)容不同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertFileNotEquals() 是與之相反的斷言,接受相同的參數(shù)。
例 A.22: assertFileEquals() 的用法
phpunit FileEqualsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) FileEqualsTest::testFailure Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'expected +'actual'/home/sb/FileEqualsTest.php:6FAILURES! Tests: 1, Assertions: 3, Failures: 1.assertFileExists()
assertFileExists(string $filename[, string $message = ''])
當(dāng) $filename 所指定的文件不存在時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertFileNotExists() 是與之相反的斷言,接受相同的參數(shù)。
例 A.23: assertFileExists() 的用法
phpunit FileExistsTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) FileExistsTest::testFailure Failed asserting that file "/path/to/file" exists./home/sb/FileExistsTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertFileIsReadable()
assertFileIsReadable(string $filename[, string $message = ''])
當(dāng) $filename 所指定的文件不是個(gè)文件或不可讀時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertFileNotIsReadable() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.24: assertFileIsReadable() 的用法
phpunit FileIsReadableTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) FileIsReadableTest::testFailure Failed asserting that "/path/to/file" is readable./home/sb/FileIsReadableTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertFileIsWritable()
assertFileIsWritable(string $filename[, string $message = ''])
當(dāng) $filename 所指定的文件不是個(gè)文件或不可寫時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertFileNotIsWritable() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.25: assertFileIsWritable() 的用法
phpunit FileIsWritableTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) FileIsWritableTest::testFailure Failed asserting that "/path/to/file" is writable./home/sb/FileIsWritableTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertGreaterThan()
assertGreaterThan(mixed $expected, mixed $actual[, string $message = ''])
當(dāng) $actual 的值不大于 $expected 的值時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertAttributeGreaterThan() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性作為實(shí)際值來(lái)進(jìn)行比較。
例 A.26: assertGreaterThan() 的用法
phpunit GreaterThanTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) GreaterThanTest::testFailure Failed asserting that 1 is greater than 2./home/sb/GreaterThanTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertGreaterThanOrEqual()
assertGreaterThanOrEqual(mixed $expected, mixed $actual[, string $message = ''])
當(dāng) $actual 的值不大于且不等于 $expected 的值時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertAttributeGreaterThanOrEqual() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性作為實(shí)際值來(lái)進(jìn)行比較。
例 A.27: assertGreaterThanOrEqual() 的用法
phpunit GreaterThanOrEqualTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) GreatThanOrEqualTest::testFailure Failed asserting that 1 is equal to 2 or is greater than 2./home/sb/GreaterThanOrEqualTest.php:6FAILURES! Tests: 1, Assertions: 2, Failures: 1.assertInfinite()
assertInfinite(mixed $variable[, string $message = ''])
當(dāng) $actual 不是 INF 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertFinite() 是與之相反的斷言,接受相同的參數(shù)。
例 A.28: assertInfinite() 的用法
phpunit InfiniteTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) InfiniteTest::testFailure Failed asserting that 1 is infinite./home/sb/InfiniteTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertInstanceOf()
assertInstanceOf($expected, $actual[, $message = ''])
當(dāng) $actual 不是 $expected 的實(shí)例時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotInstanceOf() 是與之相反的斷言,接受相同的參數(shù)。
assertAttributeInstanceOf() 和 assertAttributeNotInstanceOf() 是便捷包裝(convenience wrapper),可以應(yīng)用于某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性。
例 A.29: assertInstanceOf() 的用法
phpunit InstanceOfTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) InstanceOfTest::testFailure Failed asserting that Exception Object (...) is an instance of class "RuntimeException"./home/sb/InstanceOfTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertInternalType()
assertInternalType($expected, $actual[, $message = ''])
當(dāng) $actual 不是 $expected 所指明的類型時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotInternalType() 是與之相反的斷言,接受相同的參數(shù)。
assertAttributeInternalType() 和 assertAttributeNotInternalType() 是便捷包裝(convenience wrapper),可以應(yīng)用于某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性。
例 A.30: assertInternalType() 的用法
phpunit InternalTypeTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) InternalTypeTest::testFailure Failed asserting that 42 is of type "string"./home/sb/InternalTypeTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertIsReadable()
assertIsReadable(string $filename[, string $message = ''])
當(dāng) $filename 所指定的文件或目錄不可讀時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotIsReadable() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.31: assertIsReadable() 的用法
phpunit IsReadableTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) IsReadableTest::testFailure Failed asserting that "/path/to/unreadable" is readable./home/sb/IsReadableTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertIsWritable()
assertIsWritable(string $filename[, string $message = ''])
當(dāng) $filename 所指定的文件或目錄不可寫時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotIsWritable() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.32: assertIsWritable() 的用法
phpunit IsWritableTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) IsWritableTest::testFailure Failed asserting that "/path/to/unwritable" is writable./home/sb/IsWritableTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertJsonFileEqualsJsonFile()
assertJsonFileEqualsJsonFile(mixed $expectedFile, mixed $actualFile[, string $message = ''])
當(dāng) $actualFile 對(duì)應(yīng)的值與 $expectedFile 對(duì)應(yīng)的值不匹配時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.33: assertJsonFileEqualsJsonFile() 的用法
phpunit JsonFileEqualsJsonFileTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) JsonFileEqualsJsonFile::testFailure Failed asserting that '{"Mascot":"Tux"}' matches JSON string "["Mascott", "Tux", "OS", "Linux"]"./home/sb/JsonFileEqualsJsonFileTest.php:5FAILURES! Tests: 1, Assertions: 3, Failures: 1.assertJsonStringEqualsJsonFile()
assertJsonStringEqualsJsonFile(mixed $expectedFile, mixed $actualJson[, string $message = ''])
當(dāng) $actualJson 對(duì)應(yīng)的值與 $expectedFile 對(duì)應(yīng)的值不匹配時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.34: assertJsonStringEqualsJsonFile() 的用法
phpunit JsonStringEqualsJsonFileTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) JsonStringEqualsJsonFile::testFailure Failed asserting that '{"Mascot":"ux"}' matches JSON string "{"Mascott":"Tux"}"./home/sb/JsonStringEqualsJsonFileTest.php:5FAILURES! Tests: 1, Assertions: 3, Failures: 1.assertJsonStringEqualsJsonString()
assertJsonStringEqualsJsonString(mixed $expectedJson, mixed $actualJson[, string $message = ''])
當(dāng) $actualJson 對(duì)應(yīng)的值與 $expectedJson 對(duì)應(yīng)的值不匹配時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.35: assertJsonStringEqualsJsonString() 的用法
phpunit JsonStringEqualsJsonStringTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) JsonStringEqualsJsonStringTest::testFailure Failed asserting that two objects are equal. --- Expected +++ Actual @@ @@stdClass Object (- 'Mascot' => 'Tux'+ 'Mascot' => 'ux' )/home/sb/JsonStringEqualsJsonStringTest.php:5FAILURES! Tests: 1, Assertions: 3, Failures: 1.assertLessThan()
assertLessThan(mixed $expected, mixed $actual[, string $message = ''])
當(dāng) $actual 的值不小于 $expected 的值時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertAttributeLessThan() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性作為實(shí)際值來(lái)進(jìn)行比較。
例 A.36: assertLessThan() 的用法
phpunit LessThanTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) LessThanTest::testFailure Failed asserting that 2 is less than 1./home/sb/LessThanTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertLessThanOrEqual()
assertLessThanOrEqual(mixed $expected, mixed $actual[, string $message = ''])
當(dāng) $actual 的值不小于且不等于 $expected 的值時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertAttributeLessThanOrEqual() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性作為實(shí)際值來(lái)進(jìn)行比較。
例 A.37: assertLessThanOrEqual() 的用法
phpunit LessThanOrEqualTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) LessThanOrEqualTest::testFailure Failed asserting that 2 is equal to 1 or is less than 1./home/sb/LessThanOrEqualTest.php:6FAILURES! Tests: 1, Assertions: 2, Failures: 1.assertNan()
assertNan(mixed $variable[, string $message = ''])
當(dāng) $variable 不是 NAN 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.38: assertNan() 的用法
phpunit NanTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) NanTest::testFailure Failed asserting that 1 is nan./home/sb/NanTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertNull()
assertNull(mixed $variable[, string $message = ''])
當(dāng) $actual 不是 null 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotNull() 是與之相反的斷言,接受相同的參數(shù)。
例 A.39: assertNull() 的使用
phpunit NotNullTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) NullTest::testFailure Failed asserting that 'foo' is null./home/sb/NotNullTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertObjectHasAttribute()
assertObjectHasAttribute(string $attributeName, object $object[, string $message = ''])
當(dāng) $object->attributeName 不存在時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertObjectNotHasAttribute() 是與之相反的斷言,接受相同的參數(shù)。
例 A.40: assertObjectHasAttribute() 的用法
phpunit ObjectHasAttributeTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) ObjectHasAttributeTest::testFailure Failed asserting that object of class "stdClass" has attribute "foo"./home/sb/ObjectHasAttributeTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertRegExp()
assertRegExp(string $pattern, string $string[, string $message = ''])
當(dāng) $string 不匹配于正則表達(dá)式 $pattern 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotRegExp() 是與之相反的斷言,接受相同的參數(shù)。
例 A.41: assertRegExp() 的用法
phpunit RegExpTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) RegExpTest::testFailure Failed asserting that 'bar' matches PCRE pattern "/foo/"./home/sb/RegExpTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertStringMatchesFormat()
assertStringMatchesFormat(string $format, string $string[, string $message = ''])
當(dāng) $string 不匹配于 $format 定義的格式時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertStringNotMatchesFormat() 是與之相反的斷言,接受相同的參數(shù)。
例 A.42: assertStringMatchesFormat() 的用法
phpunit StringMatchesFormatTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) StringMatchesFormatTest::testFailure Failed asserting that 'foo' matches PCRE pattern "/^[+-]?\d+$/s"./home/sb/StringMatchesFormatTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.格式定義字符串中可以使用如下占位符:
-
%e:表示目錄分隔符,例如在 Linux 系統(tǒng)中是 /。
-
%s:一個(gè)或多個(gè)除了換行符以外的任意字符(非空白字符或者空白字符)。
-
%S:零個(gè)或多個(gè)除了換行符以外的任意字符(非空白字符或者空白字符)。
-
%a:一個(gè)或多個(gè)包括換行符在內(nèi)的任意字符(非空白字符或者空白字符)。
-
%A:零個(gè)或多個(gè)包括換行符在內(nèi)的任意字符(非空白字符或者空白字符)。
-
%w:零個(gè)或多個(gè)空白字符。
-
%i:帶符號(hào)整數(shù)值,例如 +3142、-3142。
-
%d:無(wú)符號(hào)整數(shù)值,例如 123456。
-
%x:一個(gè)或多個(gè)十六進(jìn)制字符。所謂十六進(jìn)制字符,指的是在以下范圍內(nèi)的字符:0-9、a-f、A-F。
-
%f:浮點(diǎn)數(shù),例如 3.142、-3.142、3.142E-10、3.142e+10。
-
%c:單個(gè)任意字符。
assertStringMatchesFormatFile()
assertStringMatchesFormatFile(string $formatFile, string $string[, string $message = ''])
當(dāng) $string 不匹配于 $formatFile 的內(nèi)容所定義的格式時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertStringNotMatchesFormatFile() 是與之相反的斷言,接受相同的參數(shù)。
例 A.43: assertStringMatchesFormatFile() 的用法
phpunit StringMatchesFormatFileTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) StringMatchesFormatFileTest::testFailure Failed asserting that 'foo' matches PCRE pattern "/^[+-]?\d+ $/s"./home/sb/StringMatchesFormatFileTest.php:6FAILURES! Tests: 1, Assertions: 2, Failures: 1.assertSame()
assertSame(mixed $expected, mixed $actual[, string $message = ''])
當(dāng)兩個(gè)變量 $expected 和 $actual 的值與類型不完全相同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotSame() 是與之相反的斷言,接受相同的參數(shù)。
assertAttributeSame() 和 assertAttributeNotSame() 是便捷包裝(convenience wrapper),以某個(gè)類或?qū)ο蟮哪硞€(gè) public、protected 或 private 屬性作為實(shí)際值來(lái)進(jìn)行比較。
例 A.44: assertSame() 的用法
phpunit SameTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) SameTest::testFailure Failed asserting that 2204 is identical to '2204'./home/sb/SameTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertSame(object $expected, object $actual[, string $message = ''])
當(dāng)兩個(gè)變量 $expected 和 $actual 不是指向同一個(gè)對(duì)象的引用時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.45: assertSame() 應(yīng)用于對(duì)象時(shí)的用法
phpunit SameTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) SameTest::testFailure Failed asserting that two variables reference the same object./home/sb/SameTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertStringEndsWith()
assertStringEndsWith(string $suffix, string $string[, string $message = ''])
當(dāng) $string 不以 $suffix 結(jié)尾時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertStringEndsNotWith() 是與之相反的斷言,接受相同的參數(shù)。
例 A.46: assertStringEndsWith() 的用法
phpunit StringEndsWithTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 1 second, Memory: 5.00MbThere was 1 failure:1) StringEndsWithTest::testFailure Failed asserting that 'foo' ends with "suffix"./home/sb/StringEndsWithTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertStringEqualsFile()
assertStringEqualsFile(string $expectedFile, string $actualString[, string $message = ''])
當(dāng) $expectedFile 所指定的文件其內(nèi)容不是 $actualString 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertStringNotEqualsFile() 是與之相反的斷言,接受相同的參數(shù)。
例 A.47: assertStringEqualsFile() 的用法
phpunit StringEqualsFileTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) StringEqualsFileTest::testFailure Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'expected -' +'actual'/home/sb/StringEqualsFileTest.php:6FAILURES! Tests: 1, Assertions: 2, Failures: 1.assertStringStartsWith()
assertStringStartsWith(string $prefix, string $string[, string $message = ''])
當(dāng) $string 不以 $prefix 開(kāi)頭時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertStringStartsNotWith() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.48: assertStringStartsWith() 的用法
phpunit StringStartsWithTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) StringStartsWithTest::testFailure Failed asserting that 'foo' starts with "prefix"./home/sb/StringStartsWithTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertThat()
可以用 PHPUnit_Framework_Constraint 類來(lái)訂立更加復(fù)雜的斷言。隨后可以用 assertThat() 方法來(lái)評(píng)定這些斷言。例 A.49 展示了如何用 logicalNot() 和 equalTo() 約束條件來(lái)表達(dá)與 assertNotEquals() 等價(jià)的斷言。
assertThat(mixed $value, PHPUnit_Framework_Constraint $constraint[, $message = ''])
當(dāng) $value 不符合約束條件 $constraint 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
例 A.49: assertThat() 的用法
表 A.1列舉了所有可用的 PHPUnit_Framework_Constraint 類。
表?A.1.?約束條件
| PHPUnit_Framework_Constraint_Attribute attribute(PHPUnit_Framework_Constraint $constraint, $attributeName) | 此約束將另外一個(gè)約束應(yīng)用于某個(gè)類或?qū)ο蟮哪硞€(gè)屬性。 |
| PHPUnit_Framework_Constraint_IsAnything anything() | 此約束接受任意輸入值。 |
| PHPUnit_Framework_Constraint_ArrayHasKey arrayHasKey(mixed $key) | 此約束斷言所評(píng)定的數(shù)組擁有指定鍵名。 |
| PHPUnit_Framework_Constraint_TraversableContains contains(mixed $value) | 此約束斷言所評(píng)定的 array 或?qū)崿F(xiàn)了 Iterator 接口的對(duì)象包含有給定值。 |
| PHPUnit_Framework_Constraint_TraversableContainsOnly containsOnly(string $type) | 此約束斷言所評(píng)定的 array 或?qū)崿F(xiàn)了 Iterator 接口的對(duì)象僅包含給定類型的值。 |
| PHPUnit_Framework_Constraint_TraversableContainsOnly containsOnlyInstancesOf(string $classname) | 此約束斷言所評(píng)定的 array 或?qū)崿F(xiàn)了 Iterator 接口的對(duì)象僅包含給定類名的類的實(shí)例。 |
| PHPUnit_Framework_Constraint_IsEqual equalTo($value, $delta = 0, $maxDepth = 10) | 此約束檢驗(yàn)一個(gè)值是否等于另外一個(gè)。 |
| PHPUnit_Framework_Constraint_Attribute attributeEqualTo($attributeName, $value, $delta = 0, $maxDepth = 10) | 此約束檢驗(yàn)一個(gè)值是否等于某個(gè)類或?qū)ο蟮哪硞€(gè)屬性。 |
| PHPUnit_Framework_Constraint_DirectoryExists directoryExists() | 此約束檢驗(yàn)所評(píng)定的目錄是否存在。 |
| PHPUnit_Framework_Constraint_FileExists fileExists() | 此約束檢驗(yàn)所評(píng)定的文件名對(duì)應(yīng)的文件是否存在。 |
| PHPUnit_Framework_Constraint_IsReadable isReadable() | 此約束檢驗(yàn)所評(píng)定的文件名對(duì)應(yīng)的文件是否可讀。 |
| PHPUnit_Framework_Constraint_IsWritable isWritable() | 此約束檢驗(yàn)所評(píng)定的文件名對(duì)應(yīng)的文件是否可寫。 |
| PHPUnit_Framework_Constraint_GreaterThan greaterThan(mixed $value) | 此約束斷言所評(píng)定的值大于給定值。 |
| PHPUnit_Framework_Constraint_Or greaterThanOrEqual(mixed $value) | 此約束斷言所評(píng)定的值大于或等于給定值。 |
| PHPUnit_Framework_Constraint_ClassHasAttribute classHasAttribute(string $attributeName) | 此約束斷言所評(píng)定的類具有給定屬性。 |
| PHPUnit_Framework_Constraint_ClassHasStaticAttribute classHasStaticAttribute(string $attributeName) | 此約束斷言所評(píng)定的類具有給定靜態(tài)屬性。 |
| PHPUnit_Framework_Constraint_ObjectHasAttribute hasAttribute(string $attributeName) | 此約束斷言所評(píng)定的對(duì)象具有給定屬性。 |
| PHPUnit_Framework_Constraint_IsIdentical identicalTo(mixed $value) | 此約束斷言所評(píng)定的值與另外一個(gè)值全等。 |
| PHPUnit_Framework_Constraint_IsFalse isFalse() | 此約束斷言所評(píng)定的值為 false。 |
| PHPUnit_Framework_Constraint_IsInstanceOf isInstanceOf(string $className) | 此約束斷言所評(píng)定的對(duì)象是給定類的實(shí)例。 |
| PHPUnit_Framework_Constraint_IsNull isNull() | 此約束斷言所評(píng)定的值為 null。 |
| PHPUnit_Framework_Constraint_IsTrue isTrue() | 此約束斷言所評(píng)定的值為 true。 |
| PHPUnit_Framework_Constraint_IsType isType(string $type) | 此約束斷言所評(píng)定的值是指定類型的。 |
| PHPUnit_Framework_Constraint_LessThan lessThan(mixed $value) | 此約束斷言所評(píng)定的值小于給定值。 |
| PHPUnit_Framework_Constraint_Or lessThanOrEqual(mixed $value) | 此約束斷言所評(píng)定的值小于或等于給定值。 |
| logicalAnd() | 邏輯與(AND)。 |
| logicalNot(PHPUnit_Framework_Constraint $constraint) | 邏輯非(NOT)。 |
| logicalOr() | 邏輯或(OR)。 |
| logicalXor() | 邏輯異或(XOR)。 |
| PHPUnit_Framework_Constraint_PCREMatch matchesRegularExpression(string $pattern) | 此約束斷言所評(píng)定的字符串匹配于正則表達(dá)式。 |
| PHPUnit_Framework_Constraint_StringContains stringContains(string $string, bool $case) | 此約束斷言所評(píng)定的字符串包含指定字符串。 |
| PHPUnit_Framework_Constraint_StringEndsWith stringEndsWith(string $suffix) | 此約束斷言所評(píng)定的字符串以給定后綴結(jié)尾。 |
| PHPUnit_Framework_Constraint_StringStartsWith stringStartsWith(string $prefix) | 此約束斷言所評(píng)定的字符串以給定前綴開(kāi)頭。 |
assertTrue()
assertTrue(bool $condition[, string $message = ''])
當(dāng) $condition 為 false 時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertNotTrue() 是與之相反的斷言,接受相同的參數(shù)。
例 A.50: assertTrue() 的用法
phpunit TrueTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) TrueTest::testFailure Failed asserting that false is true./home/sb/TrueTest.php:6FAILURES! Tests: 1, Assertions: 1, Failures: 1.assertXmlFileEqualsXmlFile()
assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile[, string $message = ''])
當(dāng) $actualFile 對(duì)應(yīng)的 XML 文檔與 $expectedFile 對(duì)應(yīng)的 XML 文檔不相同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertXmlFileNotEqualsXmlFile() 是與之相反的斷言,接受相同的參數(shù)。
例 A.51: assertXmlFileEqualsXmlFile() 的用法
phpunit XmlFileEqualsXmlFileTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) XmlFileEqualsXmlFileTest::testFailure Failed asserting that two DOM documents are equal. --- Expected +++ Actual @@ @@<?xml version="1.0"?><foo> - <bar/> + <baz/></foo>/home/sb/XmlFileEqualsXmlFileTest.php:7FAILURES! Tests: 1, Assertions: 3, Failures: 1.assertXmlStringEqualsXmlFile()
assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml[, string $message = ''])
當(dāng) $actualXml 對(duì)應(yīng)的 XML 文檔與 $expectedFile 對(duì)應(yīng)的 XML 文檔不相同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertXmlStringNotEqualsXmlFile() 是與之相反的斷言,并接受相同的參數(shù)。
例 A.52: assertXmlStringEqualsXmlFile() 的用法
phpunit XmlStringEqualsXmlFileTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) XmlStringEqualsXmlFileTest::testFailure Failed asserting that two DOM documents are equal. --- Expected +++ Actual @@ @@<?xml version="1.0"?><foo> - <bar/> + <baz/></foo>/home/sb/XmlStringEqualsXmlFileTest.php:7FAILURES! Tests: 1, Assertions: 2, Failures: 1.assertXmlStringEqualsXmlString()
assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml[, string $message = ''])
當(dāng) $actualXml 對(duì)應(yīng)的 XML 文檔與 $expectedXml 對(duì)應(yīng)的 XML 文檔不相同時(shí)報(bào)告錯(cuò)誤,錯(cuò)誤訊息由 $message 指定。
assertXmlStringNotEqualsXmlString() 是與之相反的斷言,接受相同的參數(shù)。
例 A.53: assertXmlStringEqualsXmlString() 的用法
phpunit XmlStringEqualsXmlStringTest PHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) XmlStringEqualsXmlStringTest::testFailure Failed asserting that two DOM documents are equal. --- Expected +++ Actual @@ @@<?xml version="1.0"?><foo> - <bar/> + <baz/></foo>/home/sb/XmlStringEqualsXmlStringTest.php:7FAILURES! Tests: 1, Assertions: 1, Failures: 1.?
轉(zhuǎn)載于:https://www.cnblogs.com/rxbook/p/6767121.html
總結(jié)
以上是生活随笔為你收集整理的PHPUnit-附录 A. 断言 (assert)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: cmake中的变量和命令的大小写
- 下一篇: BZOJ 4070 [Apio2015]