【http://www.phpunit.cn/manual/5.7/zh_cn/appendixes.assertions.html】
本附录列举可用的各种断言方法。
assertArrayHasKey()
assertArrayHasKey(mixed $key, array $array[, string $message = ''])
当 $array
不包含 $key
时报告错误,错误讯息由 $message
指定。
assertArrayNotHasKey()
是与之相反的断言,接受相同的参数。
例 A.1: assertArrayHasKey() 的用法
assertArrayHasKey('foo', ['bar' => 'baz']); } } ?>
phpunit ArrayHasKeyTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ArrayHasKeyTest::testFailureFailed 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 = ''])
当 $className::attributeName
不存在时报告错误,错误讯息由 $message
指定。
assertClassNotHasAttribute()
是与之相反的断言,接受相同的参数。
例 A.2: assertClassHasAttribute() 的用法
assertClassHasAttribute('foo', stdClass::class); } } ?>
phpunit ClassHasAttributeTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) ClassHasAttributeTest::testFailureFailed 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 = ''])
当 $array
不包含 $subset
时报告错误,错误讯息由 $message
指定。
$strict
是一个标志,用于表明是否需要对数组中的对象进行全等判定。
例 A.3: assertArraySubset() 的用法
assertArraySubset(['config' => ['key-a', 'key-b']], ['config' => ['key-a']]); } } ?>
phpunit ArrayHasKeyTestPHPUnit 4.4.0 by Sebastian Bergmann.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) Epilog\EpilogTest::testNoFollowOptionFailed 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 = ''])
当 $className::attributeName
不存在时报告错误,错误讯息由 $message
指定。
assertClassNotHasStaticAttribute()
是与之相反的断言,接受相同的参数。
例 A.4: assertClassHasStaticAttribute() 的用法
assertClassHasStaticAttribute('foo', stdClass::class); } } ?>
phpunit ClassHasStaticAttributeTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) ClassHasStaticAttributeTest::testFailureFailed 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 = ''])
当 $needle
不是 $haystack
的元素时报告错误,错误讯息由 $message
指定。
assertNotContains()
是与之相反的断言,接受相同的参数。
assertAttributeContains()
和 assertAttributeNotContains()
是便捷包装(convenience wrapper),以某个类或对象的 public
、protected
或 private
属性为搜索范围。
例 A.5: assertContains() 的用法
assertContains(4, [1, 2, 3]); } } ?>
phpunit ContainsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsTest::testFailureFailed 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])
当 $needle
不是 $haystack
的子字符串时报告错误,错误讯息由 $message
指定。
如果 $ignoreCase
为 true
,测试将按大小写不敏感的方式进行。
例 A.6: assertContains() 的用法
assertContains('baz', 'foobar'); } } ?>
phpunit ContainsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsTest::testFailureFailed asserting that 'foobar' contains "baz"./home/sb/ContainsTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
例 A.7: 带有 $ignoreCase 参数的 assertContains() 的用法
assertContains('foo', 'FooBar'); } public function testOK() { $this->assertContains('foo', 'FooBar', '', true); } } ?>
phpunit ContainsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.F.Time: 0 seconds, Memory: 2.75MbThere was 1 failure:1) ContainsTest::testFailureFailed 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 = ''])
当 $haystack
并非仅包含类型为 $type
的变量时报告错误,错误讯息由 $message
指定。
$isNativeType
是一个标志,用来表明 $type
是否是原生 PHP 类型。
assertNotContainsOnly()
是与之相反的断言,并接受相同的参数。
assertAttributeContainsOnly()
和 assertAttributeNotContainsOnly()
是便捷包装(convenience wrapper),以某个类或对象的 public
、protected
或 private
属性为搜索范围。
例 A.8: assertContainsOnly() 的用法
assertContainsOnly('string', ['1', '2', 3]); } } ?>
phpunit ContainsOnlyTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsOnlyTest::testFailureFailed 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 = ''])
当 $haystack
并非仅包含类 $classname
的实例时报告错误,错误讯息由 $message
指定。
例 A.9: assertContainsOnlyInstancesOf() 的用法
assertContainsOnlyInstancesOf( Foo::class, [new Foo, new Bar, new Foo] ); } } ?>
phpunit ContainsOnlyInstancesOfTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) ContainsOnlyInstancesOfTest::testFailureFailed 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 = ''])
当 $haystack
中的元素数量不是 $expectedCount
时报告错误,错误讯息由 $message
指定。
assertNotCount()
是与之相反的断言,接受相同的参数。
例 A.10: assertCount() 的用法
assertCount(0, ['foo']); } } ?>
phpunit CountTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) CountTest::testFailureFailed 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 = ''])
当 $directory
所指定的目录不存在时报告错误,错误讯息由 $message
指定。
assertDirectoryNotExists()
是与之相反的断言,并接受相同的参数。
例 A.11: assertDirectoryExists() 的用法
assertDirectoryExists('/path/to/directory'); } } ?>
phpunit DirectoryExistsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) DirectoryExistsTest::testFailureFailed asserting that directory "/path/to/directory" exists./home/sb/DirectoryExistsTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertDirectoryIsReadable()
assertDirectoryIsReadable(string $directory[, string $message = ''])
当 $directory
所指定的目录不是个目录或不可读时报告错误,错误讯息由 $message
指定。
assertDirectoryNotIsReadable()
是与之相反的断言,并接受相同的参数。
例 A.12: assertDirectoryIsReadable() 的用法
assertDirectoryIsReadable('/path/to/directory'); } } ?>
phpunit DirectoryIsReadableTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) DirectoryIsReadableTest::testFailureFailed asserting that "/path/to/directory" is readable./home/sb/DirectoryIsReadableTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertDirectoryIsWritable()
assertDirectoryIsWritable(string $directory[, string $message = ''])
当 $directory
所指定的目录不是个目录或不可写时报告错误,错误讯息由 $message
指定。
assertDirectoryNotIsWritable()
是与之相反的断言,并接受相同的参数。
例 A.13: assertDirectoryIsWritable() 的用法
assertDirectoryIsWritable('/path/to/directory'); } } ?>
phpunit DirectoryIsWritableTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) DirectoryIsWritableTest::testFailureFailed asserting that "/path/to/directory" is writable./home/sb/DirectoryIsWritableTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertEmpty()
assertEmpty(mixed $actual[, string $message = ''])
当 $actual
非空时报告错误,错误讯息由 $message
指定。
assertNotEmpty()
是与之相反的断言,接受相同的参数。
assertAttributeEmpty()
和 assertAttributeNotEmpty()
是便捷包装(convenience wrapper),可以应用于某个类或对象的某个 public
、protected
或 private
属性。
例 A.14: assertEmpty() 的用法
assertEmpty(['foo']); } } ?>
phpunit EmptyTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) EmptyTest::testFailureFailed 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 = ''])
当 $actualElement
中 DOMElement 的 XML 结构与 $expectedElement
中 DOMElement的 XML 结构不相同时报告错误,错误讯息由 $message
指定。
例 A.15: assertEqualXMLStructure() 的用法
assertEqualXMLStructure($expected, $actual); } public function testFailureWithDifferentNodeAttributes() { $expected = new DOMDocument; $expected->loadXML(''); $actual = new DOMDocument; $actual->loadXML(' '); $this->assertEqualXMLStructure( $expected->firstChild, $actual->firstChild, true ); } public function testFailureWithDifferentChildrenCount() { $expected = new DOMDocument; $expected->loadXML(' '); $actual = new DOMDocument; $actual->loadXML(' '); $this->assertEqualXMLStructure( $expected->firstChild, $actual->firstChild ); } public function testFailureWithDifferentChildren() { $expected = new DOMDocument; $expected->loadXML(' '); $actual = new DOMDocument; $actual->loadXML(' '); $this->assertEqualXMLStructure( $expected->firstChild, $actual->firstChild ); } } ?>
phpunit EqualXMLStructureTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FFFFTime: 0 seconds, Memory: 5.75MbThere were 4 failures:1) EqualXMLStructureTest::testFailureWithDifferentNodeNamesFailed asserting that two strings are equal.--- Expected+++ Actual@@ @@-'foo'+'bar'/home/sb/EqualXMLStructureTest.php:92) EqualXMLStructureTest::testFailureWithDifferentNodeAttributesNumber of attributes on node "foo" does not matchFailed asserting that 0 matches expected 1./home/sb/EqualXMLStructureTest.php:223) EqualXMLStructureTest::testFailureWithDifferentChildrenCountNumber of child nodes of "foo" differsFailed asserting that 1 matches expected 3./home/sb/EqualXMLStructureTest.php:354) EqualXMLStructureTest::testFailureWithDifferentChildrenFailed 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 = ''])
当两个变量 $expected
和 $actual
不相等时报告错误,错误讯息由 $message
指定。
assertNotEquals()
是与之相反的断言,接受相同的参数。
assertAttributeEquals()
和 assertAttributeNotEquals()
是便捷包装(convenience wrapper),以某个类或对象的某个 public
、protected
或 private
属性作为实际值来进行比较。
例 A.16: assertEquals() 的用法
assertEquals(1, 0); } public function testFailure2() { $this->assertEquals('bar', 'baz'); } public function testFailure3() { $this->assertEquals("foo\nbar\nbaz\n", "foo\nbah\nbaz\n"); } } ?>
phpunit EqualsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FFFTime: 0 seconds, Memory: 5.25MbThere were 3 failures:1) EqualsTest::testFailureFailed asserting that 0 matches expected 1./home/sb/EqualsTest.php:62) EqualsTest::testFailure2Failed asserting that two strings are equal.--- Expected+++ Actual@@ @@-'bar'+'baz'/home/sb/EqualsTest.php:113) EqualsTest::testFailure3Failed asserting that two strings are equal.--- Expected+++ Actual@@ @@ 'foo-bar+bah baz '/home/sb/EqualsTest.php:16FAILURES!Tests: 3, Assertions: 3, Failures: 3.
如果 $expected
和 $actual
是某些特定的类型,将使用更加专门的比较方式,参阅下文。
assertEquals(float $expected, float $actual[, string $message = '', float $delta = 0])
当两个浮点数 $expected
和 $actual
之间的差值(的绝对值)大于 $delta
时报告错误,错误讯息由 $message
指定。
关于为什么 $delta
参数是必须的,请阅读《》。
例 A.17: 将assertEquals()用于浮点数时的用法
assertEquals(1.0, 1.1, '', 0.2); } public function testFailure() { $this->assertEquals(1.0, 1.1); } } ?>
phpunit EqualsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors..FTime: 0 seconds, Memory: 5.75MbThere was 1 failure:1) EqualsTest::testFailureFailed 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 = ''])
当 $expected
和 $actual
这两个 DOMDocument 对象所表示的 XML 文档对应的无注释规范形式不相同时报告错误,错误讯息由 $message
指定。
例 A.18: assertEquals()应用于 DOMDocument 对象时的用法
loadXML(''); $actual = new DOMDocument; $actual->loadXML(' '); $this->assertEquals($expected, $actual); } } ?>
phpunit EqualsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) EqualsTest::testFailureFailed asserting that two DOM documents are equal.--- Expected+++ Actual@@ @@ -- +- + /home/sb/EqualsTest.php:12FAILURES!Tests: 1, Assertions: 1, Failures: 1.+
assertEquals(object $expected, object $actual[, string $message = ''])
当 $expected
和 $actual
这两个对象的属性值不相等时报告错误,错误讯息由 $message
指定。
例 A.19: assertEquals()应用于对象时的用法
foo = 'foo'; $expected->bar = 'bar'; $actual = new stdClass; $actual->foo = 'bar'; $actual->baz = 'bar'; $this->assertEquals($expected, $actual); } } ?>
phpunit EqualsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) EqualsTest::testFailureFailed 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 = ''])
当 $expected
和 $actual
这两个数组不相等时报告错误,错误讯息由 $message
指定。
例 A.20: assertEquals() 应用于数组时的用法
assertEquals(['a', 'b', 'c'], ['a', 'c', 'd']); } } ?>
phpunit EqualsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) EqualsTest::testFailureFailed 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 = ''])
当 $condition
为 true
时报告错误,错误讯息由 $message
指定。
assertNotFalse()
是与之相反的断言,接受相同的参数。
例 A.21: assertFalse() 的用法
assertFalse(true); } } ?>
phpunit FalseTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) FalseTest::testFailureFailed asserting that true is false./home/sb/FalseTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertFileEquals()
assertFileEquals(string $expected, string $actual[, string $message = ''])
当 $expected
所指定的文件与 $actual
所指定的文件内容不同时报告错误,错误讯息由 $message
指定。
assertFileNotEquals()
是与之相反的断言,接受相同的参数。
例 A.22: assertFileEquals() 的用法
assertFileEquals('/home/sb/expected', '/home/sb/actual'); } } ?>
phpunit FileEqualsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) FileEqualsTest::testFailureFailed 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 = ''])
当 $filename
所指定的文件不存在时报告错误,错误讯息由 $message
指定。
assertFileNotExists()
是与之相反的断言,接受相同的参数。
例 A.23: assertFileExists() 的用法
assertFileExists('/path/to/file'); } } ?>
phpunit FileExistsTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) FileExistsTest::testFailureFailed asserting that file "/path/to/file" exists./home/sb/FileExistsTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertFileIsReadable()
assertFileIsReadable(string $filename[, string $message = ''])
当 $filename
所指定的文件不是个文件或不可读时报告错误,错误讯息由 $message
指定。
assertFileNotIsReadable()
是与之相反的断言,并接受相同的参数。
例 A.24: assertFileIsReadable() 的用法
assertFileIsReadable('/path/to/file'); } } ?>
phpunit FileIsReadableTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) FileIsReadableTest::testFailureFailed asserting that "/path/to/file" is readable./home/sb/FileIsReadableTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertFileIsWritable()
assertFileIsWritable(string $filename[, string $message = ''])
当 $filename
所指定的文件不是个文件或不可写时报告错误,错误讯息由 $message
指定。
assertFileNotIsWritable()
是与之相反的断言,并接受相同的参数。
例 A.25: assertFileIsWritable() 的用法
assertFileIsWritable('/path/to/file'); } } ?>
phpunit FileIsWritableTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) FileIsWritableTest::testFailureFailed 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 = ''])
当 $actual
的值不大于 $expected
的值时报告错误,错误讯息由 $message
指定。
assertAttributeGreaterThan()
是便捷包装(convenience wrapper),以某个类或对象的某个 public
、protected
或 private
属性作为实际值来进行比较。
例 A.26: assertGreaterThan() 的用法
assertGreaterThan(2, 1); } } ?>
phpunit GreaterThanTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) GreaterThanTest::testFailureFailed 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 = ''])
当 $actual
的值不大于且不等于 $expected
的值时报告错误,错误讯息由 $message
指定。
assertAttributeGreaterThanOrEqual()
是便捷包装(convenience wrapper),以某个类或对象的某个 public
、protected
或 private
属性作为实际值来进行比较。
例 A.27: assertGreaterThanOrEqual() 的用法
assertGreaterThanOrEqual(2, 1); } } ?>
phpunit GreaterThanOrEqualTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) GreatThanOrEqualTest::testFailureFailed 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 = ''])
当 $actual
不是 INF
时报告错误,错误讯息由 $message
指定。
assertFinite()
是与之相反的断言,接受相同的参数。
例 A.28: assertInfinite() 的用法
assertInfinite(1); } } ?>
phpunit InfiniteTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) InfiniteTest::testFailureFailed asserting that 1 is infinite./home/sb/InfiniteTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertInstanceOf()
assertInstanceOf($expected, $actual[, $message = ''])
当 $actual
不是 $expected
的实例时报告错误,错误讯息由 $message
指定。
assertNotInstanceOf()
是与之相反的断言,接受相同的参数。
assertAttributeInstanceOf()
和 assertAttributeNotInstanceOf()
是便捷包装(convenience wrapper),可以应用于某个类或对象的某个 public
、protected
或 private
属性。
例 A.29: assertInstanceOf() 的用法
assertInstanceOf(RuntimeException::class, new Exception); } } ?>
phpunit InstanceOfTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) InstanceOfTest::testFailureFailed 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 = ''])
当 $actual
不是 $expected
所指明的类型时报告错误,错误讯息由 $message
指定。
assertNotInternalType()
是与之相反的断言,接受相同的参数。
assertAttributeInternalType()
和 assertAttributeNotInternalType()
是便捷包装(convenience wrapper),可以应用于某个类或对象的某个 public
、protected
或 private
属性。
例 A.30: assertInternalType() 的用法
assertInternalType('string', 42); } } ?>
phpunit InternalTypeTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) InternalTypeTest::testFailureFailed asserting that 42 is of type "string"./home/sb/InternalTypeTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertIsReadable()
assertIsReadable(string $filename[, string $message = ''])
当 $filename
所指定的文件或目录不可读时报告错误,错误讯息由 $message
指定。
assertNotIsReadable()
是与之相反的断言,并接受相同的参数。
例 A.31: assertIsReadable() 的用法
assertIsReadable('/path/to/unreadable'); } } ?>
phpunit IsReadableTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) IsReadableTest::testFailureFailed asserting that "/path/to/unreadable" is readable./home/sb/IsReadableTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertIsWritable()
assertIsWritable(string $filename[, string $message = ''])
当 $filename
所指定的文件或目录不可写时报告错误,错误讯息由 $message
指定。
assertNotIsWritable()
是与之相反的断言,并接受相同的参数。
例 A.32: assertIsWritable() 的用法
assertIsWritable('/path/to/unwritable'); } } ?>
phpunit IsWritableTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) IsWritableTest::testFailureFailed 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 = ''])
当 $actualFile
对应的值与 $expectedFile
对应的值不匹配时报告错误,错误讯息由 $message
指定。
例 A.33: assertJsonFileEqualsJsonFile() 的用法
assertJsonFileEqualsJsonFile( 'path/to/fixture/file', 'path/to/actual/file'); } } ?>
phpunit JsonFileEqualsJsonFileTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) JsonFileEqualsJsonFile::testFailureFailed 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 = ''])
当 $actualJson
对应的值与 $expectedFile
对应的值不匹配时报告错误,错误讯息由 $message
指定。
例 A.34: assertJsonStringEqualsJsonFile() 的用法
assertJsonStringEqualsJsonFile( 'path/to/fixture/file', json_encode(['Mascot' => 'ux']) ); } } ?>
phpunit JsonStringEqualsJsonFileTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) JsonStringEqualsJsonFile::testFailureFailed 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 = ''])
当 $actualJson
对应的值与 $expectedJson
对应的值不匹配时报告错误,错误讯息由 $message
指定。
例 A.35: assertJsonStringEqualsJsonString() 的用法
assertJsonStringEqualsJsonString( json_encode(['Mascot' => 'Tux']), json_encode(['Mascot' => 'ux']) ); } } ?>
phpunit JsonStringEqualsJsonStringTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) JsonStringEqualsJsonStringTest::testFailureFailed 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 = ''])
当 $actual
的值不小于 $expected
的值时报告错误,错误讯息由 $message
指定。
assertAttributeLessThan()
是便捷包装(convenience wrapper),以某个类或对象的某个 public
、protected
或 private
属性作为实际值来进行比较。
例 A.36: assertLessThan() 的用法
assertLessThan(1, 2); } } ?>
phpunit LessThanTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) LessThanTest::testFailureFailed 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 = ''])
当 $actual
的值不小于且不等于 $expected
的值时报告错误,错误讯息由 $message
指定。
assertAttributeLessThanOrEqual()
是便捷包装(convenience wrapper),以某个类或对象的某个 public
、protected
或 private
属性作为实际值来进行比较。
例 A.37: assertLessThanOrEqual() 的用法
assertLessThanOrEqual(1, 2); } } ?>
phpunit LessThanOrEqualTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) LessThanOrEqualTest::testFailureFailed 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 = ''])
当 $variable
不是 NAN
时报告错误,错误讯息由 $message
指定。
例 A.38: assertNan() 的用法
assertNan(1); } } ?>
phpunit NanTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) NanTest::testFailureFailed asserting that 1 is nan./home/sb/NanTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertNull()
assertNull(mixed $variable[, string $message = ''])
当 $actual
不是 null
时报告错误,错误讯息由 $message
指定。
assertNotNull()
是与之相反的断言,接受相同的参数。
例 A.39: assertNull() 的使用
assertNull('foo'); } } ?>
phpunit NotNullTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) NullTest::testFailureFailed asserting that 'foo' is null./home/sb/NotNullTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertObjectHasAttribute()
assertObjectHasAttribute(string $attributeName, object $object[, string $message = ''])
当 $object->attributeName
不存在时报告错误,错误讯息由 $message
指定。
assertObjectNotHasAttribute()
是与之相反的断言,接受相同的参数。
例 A.40: assertObjectHasAttribute() 的用法
assertObjectHasAttribute('foo', new stdClass); } } ?>
phpunit ObjectHasAttributeTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) ObjectHasAttributeTest::testFailureFailed 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 = ''])
当 $string
不匹配于正则表达式 $pattern
时报告错误,错误讯息由 $message
指定。
assertNotRegExp()
是与之相反的断言,接受相同的参数。
例 A.41: assertRegExp() 的用法
assertRegExp('/foo/', 'bar'); } } ?>
phpunit RegExpTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) RegExpTest::testFailureFailed 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 = ''])
当 $string
不匹配于 $format
定义的格式时报告错误,错误讯息由 $message
指定。
assertStringNotMatchesFormat()
是与之相反的断言,接受相同的参数。
例 A.42: assertStringMatchesFormat() 的用法
assertStringMatchesFormat('%i', 'foo'); } } ?>
phpunit StringMatchesFormatTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) StringMatchesFormatTest::testFailureFailed asserting that 'foo' matches PCRE pattern "/^[+-]?\d+$/s"./home/sb/StringMatchesFormatTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
格式定义字符串中可以使用如下占位符:
-
%e
:表示目录分隔符,例如在 Linux 系统中是/
。 -
%s
:一个或多个除了换行符以外的任意字符(非空白字符或者空白字符)。 -
%S
:零个或多个除了换行符以外的任意字符(非空白字符或者空白字符)。 -
%a
:一个或多个包括换行符在内的任意字符(非空白字符或者空白字符)。 -
%A
:零个或多个包括换行符在内的任意字符(非空白字符或者空白字符)。 -
%w
:零个或多个空白字符。 -
%i
:带符号整数值,例如+3142
、-3142
。 -
%d
:无符号整数值,例如123456
。 -
%x
:一个或多个十六进制字符。所谓十六进制字符,指的是在以下范围内的字符:0-9
、a-f
、A-F
。 -
%f
:浮点数,例如3.142
、-3.142
、3.142E-10
、3.142e+10
。 -
%c
:单个任意字符。
assertStringMatchesFormatFile()
assertStringMatchesFormatFile(string $formatFile, string $string[, string $message = ''])
当 $string
不匹配于 $formatFile
的内容所定义的格式时报告错误,错误讯息由 $message
指定。
assertStringNotMatchesFormatFile()
是与之相反的断言,接受相同的参数。
例 A.43: assertStringMatchesFormatFile() 的用法
assertStringMatchesFormatFile('/path/to/expected.txt', 'foo'); } } ?>
phpunit StringMatchesFormatFileTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) StringMatchesFormatFileTest::testFailureFailed 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 = ''])
当两个变量 $expected
和 $actual
的值与类型不完全相同时报告错误,错误讯息由 $message
指定。
assertNotSame()
是与之相反的断言,接受相同的参数。
assertAttributeSame()
和 assertAttributeNotSame()
是便捷包装(convenience wrapper),以某个类或对象的某个 public
、protected
或 private
属性作为实际值来进行比较。
例 A.44: assertSame() 的用法
assertSame('2204', 2204); } } ?>
phpunit SameTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) SameTest::testFailureFailed 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 = ''])
当两个变量 $expected
和 $actual
不是指向同一个对象的引用时报告错误,错误讯息由 $message
指定。
例 A.45: assertSame() 应用于对象时的用法
assertSame(new stdClass, new stdClass); } } ?>
phpunit SameTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 4.75MbThere was 1 failure:1) SameTest::testFailureFailed 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 = ''])
当 $string
不以 $suffix
结尾时报告错误,错误讯息由 $message
指定。
assertStringEndsNotWith()
是与之相反的断言,接受相同的参数。
例 A.46: assertStringEndsWith() 的用法
assertStringEndsWith('suffix', 'foo'); } } ?>
phpunit StringEndsWithTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 1 second, Memory: 5.00MbThere was 1 failure:1) StringEndsWithTest::testFailureFailed 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 = ''])
当 $expectedFile
所指定的文件其内容不是 $actualString
时报告错误,错误讯息由 $message
指定。
assertStringNotEqualsFile()
是与之相反的断言,接受相同的参数。
例 A.47: assertStringEqualsFile() 的用法
assertStringEqualsFile('/home/sb/expected', 'actual'); } } ?>
phpunit StringEqualsFileTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) StringEqualsFileTest::testFailureFailed 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 = ''])
当 $string
不以 $prefix
开头时报告错误,错误讯息由 $message
指定。
assertStringStartsNotWith()
是与之相反的断言,并接受相同的参数。
例 A.48: assertStringStartsWith() 的用法
assertStringStartsWith('prefix', 'foo'); } } ?>
phpunit StringStartsWithTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) StringStartsWithTest::testFailureFailed asserting that 'foo' starts with "prefix"./home/sb/StringStartsWithTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertThat()
可以用 PHPUnit_Framework_Constraint
类来订立更加复杂的断言。随后可以用 assertThat()
方法来评定这些断言。 展示了如何用 logicalNot()
和 equalTo()
约束条件来表达与 assertNotEquals()
等价的断言。
assertThat(mixed $value, PHPUnit_Framework_Constraint $constraint[, $message = ''])
当 $value
不符合约束条件 $constraint
时报告错误,错误讯息由 $message
指定。
例 A.49: assertThat() 的用法
assertThat( $theBiscuit, $this->logicalNot( $this->equalTo($myBiscuit) ) ); } } ?>
列举了所有可用的 PHPUnit_Framework_Constraint
类。
表 A.1. 约束条件
约束条件 | 含义 |
---|---|
PHPUnit_Framework_Constraint_Attribute attribute(PHPUnit_Framework_Constraint $constraint, $attributeName) | 此约束将另外一个约束应用于某个类或对象的某个属性。 |
PHPUnit_Framework_Constraint_IsAnything anything() | 此约束接受任意输入值。 |
PHPUnit_Framework_Constraint_ArrayHasKey arrayHasKey(mixed $key) | 此约束断言所评定的数组拥有指定键名。 |
PHPUnit_Framework_Constraint_TraversableContains contains(mixed $value) | 此约束断言所评定的 array 或实现了 Iterator 接口的对象包含有给定值。 |
PHPUnit_Framework_Constraint_TraversableContainsOnly containsOnly(string $type) | 此约束断言所评定的 array 或实现了 Iterator 接口的对象仅包含给定类型的值。 |
PHPUnit_Framework_Constraint_TraversableContainsOnly containsOnlyInstancesOf(string $classname) | 此约束断言所评定的 array 或实现了 Iterator 接口的对象仅包含给定类名的类的实例。 |
PHPUnit_Framework_Constraint_IsEqual equalTo($value, $delta = 0, $maxDepth = 10) | 此约束检验一个值是否等于另外一个。 |
PHPUnit_Framework_Constraint_Attribute attributeEqualTo($attributeName, $value, $delta = 0, $maxDepth = 10) | 此约束检验一个值是否等于某个类或对象的某个属性。 |
PHPUnit_Framework_Constraint_DirectoryExists directoryExists() | 此约束检验所评定的目录是否存在。 |
PHPUnit_Framework_Constraint_FileExists fileExists() | 此约束检验所评定的文件名对应的文件是否存在。 |
PHPUnit_Framework_Constraint_IsReadable isReadable() | 此约束检验所评定的文件名对应的文件是否可读。 |
PHPUnit_Framework_Constraint_IsWritable isWritable() | 此约束检验所评定的文件名对应的文件是否可写。 |
PHPUnit_Framework_Constraint_GreaterThan greaterThan(mixed $value) | 此约束断言所评定的值大于给定值。 |
PHPUnit_Framework_Constraint_Or greaterThanOrEqual(mixed $value) | 此约束断言所评定的值大于或等于给定值。 |
PHPUnit_Framework_Constraint_ClassHasAttribute classHasAttribute(string $attributeName) | 此约束断言所评定的类具有给定属性。 |
PHPUnit_Framework_Constraint_ClassHasStaticAttribute classHasStaticAttribute(string $attributeName) | 此约束断言所评定的类具有给定静态属性。 |
PHPUnit_Framework_Constraint_ObjectHasAttribute hasAttribute(string $attributeName) | 此约束断言所评定的对象具有给定属性。 |
PHPUnit_Framework_Constraint_IsIdentical identicalTo(mixed $value) | 此约束断言所评定的值与另外一个值全等。 |
PHPUnit_Framework_Constraint_IsFalse isFalse() | 此约束断言所评定的值为 false 。 |
PHPUnit_Framework_Constraint_IsInstanceOf isInstanceOf(string $className) | 此约束断言所评定的对象是给定类的实例。 |
PHPUnit_Framework_Constraint_IsNull isNull() | 此约束断言所评定的值为 null 。 |
PHPUnit_Framework_Constraint_IsTrue isTrue() | 此约束断言所评定的值为 true 。 |
PHPUnit_Framework_Constraint_IsType isType(string $type) | 此约束断言所评定的值是指定类型的。 |
PHPUnit_Framework_Constraint_LessThan lessThan(mixed $value) | 此约束断言所评定的值小于给定值。 |
PHPUnit_Framework_Constraint_Or lessThanOrEqual(mixed $value) | 此约束断言所评定的值小于或等于给定值。 |
logicalAnd() | 逻辑与(AND)。 |
logicalNot(PHPUnit_Framework_Constraint $constraint) | 逻辑非(NOT)。 |
logicalOr() | 逻辑或(OR)。 |
logicalXor() | 逻辑异或(XOR)。 |
PHPUnit_Framework_Constraint_PCREMatch matchesRegularExpression(string $pattern) | 此约束断言所评定的字符串匹配于正则表达式。 |
PHPUnit_Framework_Constraint_StringContains stringContains(string $string, bool $case) | 此约束断言所评定的字符串包含指定字符串。 |
PHPUnit_Framework_Constraint_StringEndsWith stringEndsWith(string $suffix) | 此约束断言所评定的字符串以给定后缀结尾。 |
PHPUnit_Framework_Constraint_StringStartsWith stringStartsWith(string $prefix) | 此约束断言所评定的字符串以给定前缀开头。 |
assertTrue()
assertTrue(bool $condition[, string $message = ''])
当 $condition
为 false
时报告错误,错误讯息由 $message
指定。
assertNotTrue()
是与之相反的断言,接受相同的参数。
例 A.50: assertTrue() 的用法
assertTrue(false); } } ?>
phpunit TrueTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) TrueTest::testFailureFailed asserting that false is true./home/sb/TrueTest.php:6FAILURES!Tests: 1, Assertions: 1, Failures: 1.
assertXmlFileEqualsXmlFile()
assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile[, string $message = ''])
当 $actualFile
对应的 XML 文档与 $expectedFile
对应的 XML 文档不相同时报告错误,错误讯息由 $message
指定。
assertXmlFileNotEqualsXmlFile()
是与之相反的断言,接受相同的参数。
例 A.51: assertXmlFileEqualsXmlFile() 的用法
assertXmlFileEqualsXmlFile( '/home/sb/expected.xml', '/home/sb/actual.xml'); } } ?>
phpunit XmlFileEqualsXmlFileTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) XmlFileEqualsXmlFileTest::testFailureFailed asserting that two DOM documents are equal.--- Expected+++ Actual@@ @@- /home/sb/XmlFileEqualsXmlFileTest.php:7FAILURES!Tests: 1, Assertions: 3, Failures: 1.+
assertXmlStringEqualsXmlFile()
assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml[, string $message = ''])
当 $actualXml
对应的 XML 文档与 $expectedFile
对应的 XML 文档不相同时报告错误,错误讯息由 $message
指定。
assertXmlStringNotEqualsXmlFile()
是与之相反的断言,并接受相同的参数。
例 A.52: assertXmlStringEqualsXmlFile() 的用法
assertXmlStringEqualsXmlFile( '/home/sb/expected.xml', ''); } } ?>
phpunit XmlStringEqualsXmlFileTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.25MbThere was 1 failure:1) XmlStringEqualsXmlFileTest::testFailureFailed asserting that two DOM documents are equal.--- Expected+++ Actual@@ @@- /home/sb/XmlStringEqualsXmlFileTest.php:7FAILURES!Tests: 1, Assertions: 2, Failures: 1.+
assertXmlStringEqualsXmlString()
assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml[, string $message = ''])
当 $actualXml
对应的 XML 文档与 $expectedXml
对应的 XML 文档不相同时报告错误,错误讯息由 $message
指定。
assertXmlStringNotEqualsXmlString()
是与之相反的断言,接受相同的参数。
例 A.53: assertXmlStringEqualsXmlString() 的用法
assertXmlStringEqualsXmlString( '', ' '); } } ?>
phpunit XmlStringEqualsXmlStringTestPHPUnit 5.7.0 by Sebastian Bergmann and contributors.FTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) XmlStringEqualsXmlStringTest::testFailureFailed asserting that two DOM documents are equal.--- Expected+++ Actual@@ @@- /home/sb/XmlStringEqualsXmlStringTest.php:7FAILURES!Tests: 1, Assertions: 1, Failures: 1.+