PHPUnitManual:4.6
- 4.6 검증
검증 (assertion)
이 절에서는 사용 가능한 검증 메소드들을 설명합니다.
assertArrayHasKey()
assertArrayHasKey(mixed $key, array $array[, string $message = ])
$array 에 키 $key 가 존재하지 않을 경우, 에러 $message 를 보고합니다.
assertArrayNotHasKey() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
예제 4.14 assertArrayHasKey() 사용법
<?php
class ArrayHasKeyTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertArrayHasKey('foo', array('bar' => 'baz'));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ArrayHasKeyTest::testFailure
Failed asserting that an array has the key 'foo'.
/home/sb/ArrayHasKeyTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ArrayHasKeyTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ArrayHasKeyTest::testFailure
Failed asserting that an array has the key 'foo'.
/home/sb/ArrayHasKeyTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertClassHasAttribute()
assertClassHasAttribute(string $attributeName, string $className[, string $message = ])
$className::attributeName 이 존재하지 않을 경우, 에러 $message 를 보고합니다.
assertClassNotHasAttribute() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
예제 4.15 assertClassHasAttribute() 사용법
<?php
class ClassHasAttributeTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertClassHasAttribute('foo', 'stdClass');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) ClassHasAttributeTest::testFailure
Failed asserting that class "stdClass" has attribute "foo".
/home/sb/ClassHasAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ClassHasAttributeTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) ClassHasAttributeTest::testFailure
Failed asserting that class "stdClass" has attribute "foo".
/home/sb/ClassHasAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertClassHasStaticAttribute()
assertClassHasStaticAttribute(string $attributeName, string $className[, string $message = ])
$className::attributeName 이 존재하지 않을 경우, 에러 $message 를 보고합니다.
assertClassNotHasStaticAttribute() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
예제 4.16 assertClassNotHasAttribute() 사용법
<?php
class ClassHasStaticAttributeTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertClassHasStaticAttribute('foo', 'stdClass');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) ClassHasStaticAttributeTest::testFailure
Failed asserting that class "stdClass" has static attribute "foo".
/home/sb/ClassHasStaticAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ClassHasStaticAttributeTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) ClassHasStaticAttributeTest::testFailure
Failed asserting that class "stdClass" has static attribute "foo".
/home/sb/ClassHasStaticAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertContains()
assertContains(mixed $needle, Iterator|array $haystack[, string $message = ])
$needle 이 $haystack 의 요소가 아닐 경우, 에러 $message 를 보고합니다.
assertNotContains() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
assertAttributeContains() 와 assertAttributeNotContains() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 $haystack 으로 사용할 수 있습니다.
예제 4.17 assertContains() 사용법
<?php
class ContainsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertContains(4, array(1, 2, 3));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ContainsTest::testFailure
Failed asserting that an array contains 4.
/home/sb/ContainsTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ContainsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ContainsTest::testFailure
Failed asserting that an array contains 4.
/home/sb/ContainsTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertContains(string $needle, string $haystack[, string $message = ])
$needle 이 $haystack 의 부분 문자열이 아닌 경우, 에러 $message 를 보고합니다.
예제 4.18 assertContains() 사용법
<?php
class ContainsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertContains('baz', 'foobar');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ContainsTest::testFailure
Failed asserting that 'foobar' contains "baz".
/home/sb/ContainsTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ContainsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ContainsTest::testFailure
Failed asserting that 'foobar' contains "baz".
/home/sb/ContainsTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertContainsOnly()
assertContainsOnly(string $type, Iterator|array $haystack[, boolean $isNativeType = NULL, string $message = ])
$haystack 에 $type 이외의 형을 가지는 데이터가 들어 있는 경우, 에러 $message 를 보고합니다.
assertNotContainsOnly() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
assertAttributeContainsOnly() 와 assertAttributeNotContainsOnly() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 haystack 으로 사용할 수 있습니다.
예제 4.19 assertContainsOnly() 사용법
<?php
class ContainsOnlyTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertContainsOnly('string', array('1', '2', 3));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ContainsOnlyTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertContainsOnlyInstancesOf()
assertContainsOnlyInstancesOf(string $classname, Traversable|array $haystack[, string $message = ])
$haystack 이 $classname 클래스의 인스턴스 이외를 포함한 경우, 에러 $message 를 보고합니다.
예제 4.20 assertContainsOnlyInstancesOf() 사용법
<?php
class ContainsOnlyInstancesOfTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertContainsOnlyInstancesOf('Foo', array(new Foo(), new Bar(), new Foo()
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ContainsOnlyInstancesOfTest::testFailure
Failed asserting that Array ([0]=> Bar Object(...)) is an instance of class "Foo".
/home/sb/ContainsOnlyInstancesOfTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ContainsOnlyInstancesOfTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) ContainsOnlyInstancesOfTest::testFailure
Failed asserting that Array ([0]=> Bar Object(...)) is an instance of class "Foo".
/home/sb/ContainsOnlyInstancesOfTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertCount()
assertCount($expectedCount, $haystack[, string $message = ])
$heystack 의 요소 숫자가 $expectedCount 와 다른 경우, 에러 $message 를 보고합니다.
assertNotCount() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
예제 4.21 assertCount() 사용법
<?php
class CountTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertCount(0, array('foo'));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) CountTest::testFailure
Failed asserting that actual size 1 matches expected size 0.
/home/sb/CountTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit CountTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) CountTest::testFailure
Failed asserting that actual size 1 matches expected size 0.
/home/sb/CountTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertEmpty()
assertEmpty(mixed $actual[, string $message = ])
$actual 이 비어있지 않은 경우, 에러 $message 를 보고합니다.
assertNotEmpty() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
assertAttributeEmpty() 및 assertAttributeNotEmpty() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 haystack 으로 사용할 수 있습니다.
예제 4.22 assertEmpty() 사용법
<?php
class EmptyTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertEmpty(array('foo'));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) EmptyTest::testFailure
Failed asserting that an array is empty.
/home/sb/EmptyTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit EmptyTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) EmptyTest::testFailure
Failed asserting that an array is empty.
/home/sb/EmptyTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertEqualXMLStructure()
assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement[, boolean $checkAttributes = FALSE, string $message = ])
$actualElement 의 DOMElement 의 XML 구조가 $expectedElement 의 DOMElement 의 XML 구조와 같지 않은 경우, 에러 $message 를 보고합니다.
예제 4.23 assertEqualXMLStructure() 사용법
<?php
class EqualXMLStructureTest extends PHPUnit_Framework_TestCase
{
public function testFailureWithDifferentNodeNames()
{
$expected = new DOMElement('foo');
$actual = new DOMElement('bar');
$this->assertEqualXMLStructure($expected, $actual);
}
public function testFailureWithDifferentNodeAttributes()
{
$expected = new DOMDocument;
$expected->loadXML('<foo bar="true" />');
$actual = new DOMDocument;
$actual->loadXML('<foo/>');
$this->assertEqualXMLStructure(
$expected->firstChild, $actual->firstChild, TRUE
);
}
public function testFailureWithDifferentChildrenCount()
{
$expected = new DOMDocument;
$expected->loadXML('<foo><bar/><bar/><bar/></foo>');
$actual = new DOMDocument;
$actual->loadXML('<foo><bar/></foo>');
$this->assertEqualXMLStructure(
$expected->firstChild, $actual->firstChild
);
}
public function testFailureWithDifferentChildren()
{
$expected = new DOMDocument;
$expected->loadXML('<foo><bar/><bar/><bar/></foo>');
$actual = new DOMDocument;
$actual->loadXML('<foo><baz/><baz/><baz/></foo>');
$this->assertEqualXMLStructure(
$expected->firstChild, $actual->firstChild
);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
FFFF
Time: 0 seconds, Memory: 5.75Mb
There were 4 failures:
1) EqualXMLStructureTest::testFailureWithDifferentNodeNames
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'foo'
+'bar'
/home/sb/EqualXMLStructureTest.php:9
2) EqualXMLStructureTest::testFailureWithDifferentNodeAttributes
Number of attributes on node "foo" does not match
Failed asserting that 0 matches expected 1.
/home/sb/EqualXMLStructureTest.php:22
3) EqualXMLStructureTest::testFailureWithDifferentChildrenCount
Number of child nodes of "foo" differs
Failed asserting that 1 matches expected 3.
/home/sb/EqualXMLStructureTest.php:35
4) EqualXMLStructureTest::testFailureWithDifferentChildren
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'bar'
+'baz'
/home/sb/EqualXMLStructureTest.php:48
FAILURES!
Tests: 4, Assertions: 8, Failures: 4.phpunit EqualXMLStructureTest
PHPUnit 3.7.0 by Sebastian Bergmann.
FFFF
Time: 0 seconds, Memory: 5.75Mb
There were 4 failures:
1) EqualXMLStructureTest::testFailureWithDifferentNodeNames
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'foo'
+'bar'
/home/sb/EqualXMLStructureTest.php:9
2) EqualXMLStructureTest::testFailureWithDifferentNodeAttributes
Number of attributes on node "foo" does not match
Failed asserting that 0 matches expected 1.
/home/sb/EqualXMLStructureTest.php:22
3) EqualXMLStructureTest::testFailureWithDifferentChildrenCount
Number of child nodes of "foo" differs
Failed asserting that 1 matches expected 3.
/home/sb/EqualXMLStructureTest.php:35
4) EqualXMLStructureTest::testFailureWithDifferentChildren
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'bar'
+'baz'
/home/sb/EqualXMLStructureTest.php:48
FAILURES!
Tests: 4, Assertions: 8, Failures: 4.
assertEquals()
assertEquals(mixed $expected, mixed $actual[, string $message = ])
2개의 요소 $expected 와 $actual 이 같지 않은 경우, 에러 $message 를 보고합니다.
assertNotEquals() 는 이 검증과 반대의 의미로, 같은 인수를 받습니다.
assertAttributeEquals() 및 assertAttributeNotEquals() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.24 assertEquals() 사용법
<?php
class EqualsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertEquals(1, 0);
}
public function testFailure2()
{
$this->assertEquals('bar', 'baz');
}
public function testFailure3()
{
$this->assertEquals("foo\nbar\nbaz\n", "foo\nbah\nbaz\n");
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
FFF
Time: 0 seconds, Memory: 5.25Mb
There were 3 failures:
1) EqualsTest::testFailure
Failed asserting that 0 matches expected 1.
/home/sb/EqualsTest.php:6
2) EqualsTest::testFailure2
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'bar'
+'baz'
/home/sb/EqualsTest.php:11
3) EqualsTest::testFailure3
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
'foo
-bar
+bah
baz
'
/home/sb/EqualsTest.php:16
FAILURES!
Tests: 3, Assertions: 3, Failures: 3.phpunit EqualsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
FFF
Time: 0 seconds, Memory: 5.25Mb
There were 3 failures:
1) EqualsTest::testFailure
Failed asserting that 0 matches expected 1.
/home/sb/EqualsTest.php:6
2) EqualsTest::testFailure2
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'bar'
+'baz'
/home/sb/EqualsTest.php:11
3) EqualsTest::testFailure3
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
'foo
-bar
+bah
baz
'
/home/sb/EqualsTest.php:16
FAILURES!
Tests: 3, Assertions: 3, Failures: 3.
인수 $expected 와 $actual 의 형에 특화된 비교에 관해서는 다음을 참조하십시오.
assertEquals(float $expected, float $actual[, string $message = , float $delta = 0])
2개의 float 형 $expected 와 $actual 의 오차가 $delta 보다 큰 경우, 에러 $message 를 보고합니다.
$delta 가 필요한 이유에 관해서는 "What Every Computer Scientist Should Know About Floating-Point Arithmetic [1]" 를 참조하십시오.
예제 4.25 float 형에 관한 assertEquals() 사용법
<?php
class EqualsTest extends PHPUnit_Framework_TestCase
{
public function testSuccess()
{
$this->assertEquals(1.0, 1.1, '', 0.2);
}
public function testFailure()
{
$this->assertEquals(1.0, 1.1);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
.F
Time: 0 seconds, Memory: 5.75Mb
There was 1 failure:
1) EqualsTest::testFailure
Failed asserting that 1.1 matches expected 1.0.
/home/sb/EqualsTest.php:11
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.phpunit EqualsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
.F
Time: 0 seconds, Memory: 5.75Mb
There was 1 failure:
1) EqualsTest::testFailure
Failed asserting that 1.1 matches expected 1.0.
/home/sb/EqualsTest.php:11
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
assertEquals(DOMDocument $expected, DOMDocument $actual[, string $message = ])
2개의 DOMDocument 오브젝트 $expected 와 $actual 로 표현되는 XML 문서가 (주석을 제거하고 정규화시킨 상태에서) 동등하지 않은 경우, 에러 $message 를 보고합니다.
예제 4.26 DOMDocument 오브젝트에 관한 assertEquals() 사용법
<?php
class EqualsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$expected = new DOMDocument;
$expected->loadXML('<foo><bar/></foo>');
$actual = new DOMDocument;
$actual->loadXML('<bar><foo/></bar>');
$this->assertEquals($expected, $actual);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:12
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit EqualsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:12
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertEquals(object $expected, object $actual[, string $message = ])
2개의 오브젝트 $expected 와 $actual 이 같은 속성값을 가지지 않는 경우, 에러 $message 를 보고합니다.
예제 4.27 오브젝트에 관한 assertEquals() 사용법
<?php
class EqualsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$expected = new stdClass;
$expected->foo = 'foo';
$expected->bar = 'bar';
$actual = new stdClass;
$actual->foo = 'bar';
$actual->baz = 'bar';
$this->assertEquals($expected, $actual);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:14
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit EqualsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:14
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertEquals(array $expected, array $actual[, string $message = ])
2개의 배열 $expected 와 $actual 이 같지 않은 경우, 에러 $message 를 보고합니
예제 4.28 배열에 관한 assertEquals() 사용법
<?php
class EqualsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit EqualsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertFalse()
assertFalse(bool $condition[, string $message = ])
$condition 이 TRUE 인 경우, 에러 $message 를 보고합니
예제 4.29 assertFalse() 사용법
<?php
class FalseTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertFalse(TRUE);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) FalseTest::testFailure
Failed asserting that true is false.
/home/sb/FalseTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit FalseTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) FalseTest::testFailure
Failed asserting that true is false.
/home/sb/FalseTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertFileEquals()
assertFileEquals(string $expected, string $actual[, string $message = ])
$expected 로 지정한 파일과 $actual 로 지정한 파일의 내용이 다른 경우, 에러 $message 를 보고합니다.
assertFileNotEquals() 는 이 검증과 반대 의미로, 같은 인수를 받습니다.
예제 4.30 assertFileEquals() 사용법
<?php
class FileEqualsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertFileEquals('/home/sb/expected', '/home/sb/actual');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There was 1 failure:
1) FileEqualsTest::testFailure
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'expected
+'actual
'
/home/sb/FileEqualsTest.php:6
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.phpunit FileEqualsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There was 1 failure:
1) FileEqualsTest::testFailure
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'expected
+'actual
'
/home/sb/FileEqualsTest.php:6
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
assertFileExists()
assertFileExists(string $filename[, string $message = ])
파일 $filename 이 존재하지 않을 경우, 에러 $message 를 보고합니다.
assertFileNotExists() 는 이 검증과 반대 의미로, 같은 인수를 받습니다.
예제 4.31 assertFileExists() 사용법
<?php
class FileExistsTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertFileExists('/path/to/file');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) FileExistsTest::testFailure
Failed asserting that file "/path/to/file" exists.
/home/sb/FileExistsTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit FileExistsTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) FileExistsTest::testFailure
Failed asserting that file "/path/to/file" exists.
/home/sb/FileExistsTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertGreaterThan()
assertGreaterThan(mixed $expected, mixed $actual[, string $message = ])
$actual 값이 $expected 보다 크지 않을 경우, 에러 $message 를 보고합니다.
assertAttributeGreaterThan() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.32 assertAttributeGreaterThan() 사용법
<?php
class GreaterThanTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertGreaterThan(2, 1);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) GreaterThanTest::testFailure
Failed asserting that 1 is greater than 2.
/home/sb/GreaterThanTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit GreaterThanTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) GreaterThanTest::testFailure
Failed asserting that 1 is greater than 2.
/home/sb/GreaterThanTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertGreaterThanOrEqual()
assertGreaterThanOrEqual(mixed $expected, mixed $actual[, string $message = ])
$actual 값이 $expected 이상이 아닐 경우 (보다 작을 경우), 에러 $message 를 보고합니다.
assertAttributeGreaterThanOrEqual() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.33 assertAttributeGreaterThanOrEqual() 사용법
<?php
class GreatThanOrEqualTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertGreaterThanOrEqual(2, 1);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There was 1 failure:
1) GreatThanOrEqualTest::testFailure
Failed asserting that 1 is equal to 2 or is greater than 2.
/home/sb/GreaterThanOrEqualTest.php:6
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.phpunit GreaterThanOrEqualTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There was 1 failure:
1) GreatThanOrEqualTest::testFailure
Failed asserting that 1 is equal to 2 or is greater than 2.
/home/sb/GreaterThanOrEqualTest.php:6
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
assertInstanceOf()
assertInstanceOf($expected, $actual[, $message = ])
$actual 이 $expected 의 인스턴스가 아닐 경우, 에러 $message 를 보고합니다.
assertNotInstanceOf() 는 이 검증과 반대 의미로, 같은 인수를 받습니다.
assertAttributeInstanceOf() 및 assertAttributeNotInstanceOf() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.34 assertAttributeInstanceOf() 사용법
<?php
class InstanceOfTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertInstanceOf('RuntimeException', new Exception);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) InstanceOfTest::testFailure
Failed asserting that Exception Object (...) is an instance of class "RuntimeException".
/home/sb/InstanceOfTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit InstanceOfTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) InstanceOfTest::testFailure
Failed asserting that Exception Object (...) is an instance of class "RuntimeException".
/home/sb/InstanceOfTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertInternalType()
assertInternalType($expected, $actual[, $message = ])
$actual 의 형(type)이 $expected 이 아닌 경우, 에러 $message 를 보고합니다.
assertNotInternalType() 는 이 검증과 반대 의미로, 같은 인수를 받습니다.
assertAttributeInternalType() 및 assertAttributeNotInternalType() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.35 assertInternalType() 사용법
<?php
class InternalTypeTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertInternalType('string', 42);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) InternalTypeTest::testFailure
Failed asserting that 42 is of type "string".
/home/sb/InternalTypeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit InternalTypeTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) InternalTypeTest::testFailure
Failed asserting that 42 is of type "string".
/home/sb/InternalTypeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertJsonFileEqualsJsonFile()
assertJsonFileEqualsJsonFile(mixed $expectedFile, mixed $actualFile[, string $message = ])
$actualFile 의 값이 $expectedFile 의 값과 일치하지 않는 경우, 에러 $message 를 보고합니다.
예제 4.36 assertJsonFileEqualsJsonFile() 사용법
<?php
class JsonFileEqualsJsonFileTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertJsonFileEqualsJsonFile(
'path/to/fixture/file', 'path/to/actual/file');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) JsonFileEqualsJsonFile::testFailure
Failed asserting that '{"Mascott":"Tux"}' matches JSON string "["Mascott", "Tux", "OS", "
/home/sb/JsonFileEqualsJsonFileTest.php:5
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.phpunit JsonFileEqualsJsonFileTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) JsonFileEqualsJsonFile::testFailure
Failed asserting that '{"Mascott":"Tux"}' matches JSON string "["Mascott", "Tux", "OS", "
/home/sb/JsonFileEqualsJsonFileTest.php:5
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
assertJsonStringEqualsJsonFile()
assertJsonStringEqualsJsonFile(mixed $expectedFile, mixed $actualJson[, string $message = ])
$actualJson 의 값이 $expectedFile 의 값과 일치하지 않는 경우, 에러 $message 를 보고합니다.
예제 4.37 assertJsonStringEqualsJsonFile() 사용법
<?php
class JsonStringEqualsJsonFileTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertJsonStringEqualsJsonFile(
'path/to/fixture/file', json_encode(array("Mascott" => "ux"));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) JsonStringEqualsJsonFile::testFailure
Failed asserting that '{"Mascott":"ux"}' matches JSON string "{"Mascott":"Tux"}".
/home/sb/JsonStringEqualsJsonFileTest.php:5
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.phpunit JsonStringEqualsJsonFileTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) JsonStringEqualsJsonFile::testFailure
Failed asserting that '{"Mascott":"ux"}' matches JSON string "{"Mascott":"Tux"}".
/home/sb/JsonStringEqualsJsonFileTest.php:5
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
assertJsonStringEqualsJsonString()
assertJsonStringEqualsJsonString(mixed $expectedJson, mixed $actualJson[, string $message = ])
$actualJson 의 값이 $expectedJson 의 값과 일치하지 않는 경우, 에러 $message 를 보고합니다.
예제 4.38 assertJsonStringEqualsJsonString() 사용법
<?php
class JsonStringEqualsJsonStringTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertJsonStringEqualsJsonString(
json_encode(array("Mascott" => "Tux"), json_encode(array("Mascott" => "ux"));
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) JsonStringEqualsJsonStringTest::testFailure
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
stdClass Object (
-
'Mascott' => 'Tux'
+
'Mascott' => 'ux'
)
/home/sb/JsonStringEqualsJsonStringTest.php:5
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.phpunit JsonStringEqualsJsonStringTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) JsonStringEqualsJsonStringTest::testFailure
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
stdClass Object (
-
'Mascott' => 'Tux'
+
'Mascott' => 'ux'
)
/home/sb/JsonStringEqualsJsonStringTest.php:5
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
assertLessThan()
assertLessThan(mixed $expected, mixed $actual[, string $message = ])
$actual 의 값이 $expected 의 값보다 작지 않은 경우, 에러 $message 를 보고합니다.
assertAttributeLessThan() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.39 assertLessThan() 사용법
<?php
class LessThanTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertLessThan(1, 2);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) LessThanTest::testFailure
Failed asserting that 2 is less than 1.
/home/sb/LessThanTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit LessThanTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) LessThanTest::testFailure
Failed asserting that 2 is less than 1.
/home/sb/LessThanTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertLessThanOrEqual()
assertLessThanOrEqual(mixed $expected, mixed $actual[, string $message = ])
$actual 의 값이 $expected 의 값 이하가 아닌 경우 (보다 큰 경우), 에러 $message 를 보고합니다.
assertAttributeLessThanOrEqual() 는 편리한 wrapper 로, 클래스나 오브젝트의 public, protected, private 속성을 실제 값으로 사용할 수 있습니다.
예제 4.40 assertLessThanOrEqual() 사용법
<?php
class LessThanOrEqualTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertLessThanOrEqual(1, 2);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There was 1 failure:
1) LessThanOrEqualTest::testFailure
Failed asserting that 2 is equal to 1 or is less than 1.
/home/sb/LessThanOrEqualTest.php:6
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.phpunit LessThanOrEqualTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There was 1 failure:
1) LessThanOrEqualTest::testFailure
Failed asserting that 2 is equal to 1 or is less than 1.
/home/sb/LessThanOrEqualTest.php:6
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
assertNull()
assertNull(mixed $variable[, string $message = ])
$variable 이 NULL 이 아닌 경우, 에러 $message 를 보고합니다.
assertNotNull() 는 이 검증과 반대 의미로, 같은 인수를 받습니다.
예제 4.41 assertNull() 사용법
<?php
class NullTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertNull('foo');
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) NullTest::testFailure
Failed asserting that 'foo' is null.
/home/sb/NotNullTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit NotNullTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) NullTest::testFailure
Failed asserting that 'foo' is null.
/home/sb/NotNullTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
assertObjectHasAttribute()
assertObjectHasAttribute(string $attributeName, object $object[, string $message = ])
$object->attributeName 이 존재하지 않을 경우, 에러 $message 를 보고합니다.
assertObjectNotHasAttribute() 는 이 검증과 반대 의미로, 같은 인수를 받습니다.
예제 4.42 assertObjectHasAttribute() 사용법
<?php
class ObjectHasAttributeTest extends PHPUnit_Framework_TestCase
{
public function testFailure()
{
$this->assertObjectHasAttribute('foo', new stdClass);
}
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) ObjectHasAttributeTest::testFailure
Failed asserting that object of class "stdClass" has attribute "foo".
/home/sb/ObjectHasAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit ObjectHasAttributeTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 4.75Mb
There was 1 failure:
1) ObjectHasAttributeTest::testFailure
Failed asserting that object of class "stdClass" has attribute "foo".
/home/sb/ObjectHasAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.