PHPUnitManual:4.6: Difference between revisions

From 흡혈양파의 번역工房
Jump to navigation Jump to search
(PHPUnit 4.6 검증 페이지 중간내용추가)
 
(PHPUnit 4.6 검증 페이지 내용추가)
Line 1,570: Line 1,570:
Failed asserting that object of class "stdClass" has attribute "foo".
Failed asserting that object of class "stdClass" has attribute "foo".
/home/sb/ObjectHasAttributeTest.php:6
/home/sb/ObjectHasAttributeTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
</syntaxhighlight>
===assertTag()===
assertTag(array $matcher, string $actual[, string $message = '', boolean $isHtml = TRUE])
$actual 이 $matcher 와 매치되지 않는 경우, 에러 $message 를 보고합니다.
$matcher 는 associative array 로, 검증에 사용할 매치 조건을 지정합니다.
* id: 지정한 id 속성의 노드가 대응하는 값과 매치될 것
* tag: 노드의 형태가 대응하는 값과 매치될 것
* attributes: 노드의 속성이 대응하는 값의 associative array $attributes 과 매치될 것
* content: 텍스트의 내용이 지정한 값과 매치될 것
* parent: 노드의 parent 가 associative array $parent 과 매치될 것
* child: 노드를 직접 계승하는 child 중 적어도 하나가 associative array $child 의 조건을 만족시킬 것
* ancestor: 노드의 조상 중 적어도 하나가 associative array $ancestor 의 조건을 만족시킬 것
* descendant: 노드의 자손 중 적어도 하나가 associative array $descendant 의 조건을 만족시킬 것
* children: 노드의 child 의 숫자를 세기 위한 associative array
* count: 매치되는 child 의 숫자가 이 값과 일치할 것
* less_than: 매치되는 child 의 숫자가 이 값보다 작을 것
* greater_than: 매치되는 child 의 숫자가 이 값보다 많을 것
* only: associative array 로 child 매치용 키를 지정하고, 매치하는 child 숫자를 센다
assertNotTag() 은 이 검증과 반대 의미로, 같은 인수를 받습니다.
예4.54 assertTag() 사용법
<syntaxhighlight lang="php">
    <?php
    // id="my_id" 요소가 있음을 검증하는 matcher
    $matcher = array('id' => 'my_id');
// "span" 태그가 존재함을 검증하는 matcher
$matcher = array('tag' => 'span');
// 값이 "Hello World" 인 "span" 태그가 존재함을 검증한다
// matcher
$matcher = array('tag' => 'span', 'content' => 'Hello World');
// 정규표현으로 지정한 내용과 일치하는 값을 가지는 "span" 태그가
// 존재함을 검증하는 matcher
$matcher = array('tag' => 'span', 'content' => 'regexp:/Try P(HP|ython)/');
// class 속성으로 "list" 가 지정된 "span" 태그가 존재함을 검증하는 matcher
$matcher = array(
'tag' => 'span',
'attributes' => array('class' => 'list')
);
// "span" 이 "div" 의 내부에 존재함을 검증하는 matcher
$matcher = array(
'tag' => 'span',
'parent' => array('tag' => 'div')
);
// "span" 이 "table" 안의 어딘가에 존재함을 검증하는 matcher
$matcher = array(
'tag' => 'span',
'ancestor' => array('tag' => 'table')
);
// child 요소 중 적어도 하나의 "em" 을 가지는 "span" 이 존재함을 검증하는 matcher
$matcher = array(
'tag' => 'span',
'child' => array('tag' => 'em')
);
// "span" 의 안에 (몇 단계 하위 계층의 안에라도)
// "strong" 태그가 존재함을 검증하는 matcher
$matcher = array(
'tag' => 'span',
'descendant' => array('tag' => 'strong')
);
// 직접 계승하는 child 중, 5개에서 10개 사이의 "em" 태그를 가지는 "span"
// 존재함을 검증하는 matcher
$matcher = array(
'tag' => 'span',
'children' => array(
    'less_than' => 11,
    'greater_than' => 4,
    'only' => array('tag' => 'em')
    )
);
// "div" 태그가 존재하고, 조상으로 "ul", parent 로 "li"
// (class="enum") 을 가지며, id="my_test" 의 값이
// "Hello World" 인 "span" 을 자손으로 가짐을 검증하는 matcher
$matcher = array(
'tag' => 'div',
'ancestor' => array('tag' => 'ul'),
'parent' => array(
  'tag' => 'li',
  'attributes' => array('class' => 'enum')
  ),
'descendant' => array(
      'tag' => 'span',
      'child' => array(
'id' => 'my_test',
'content' => 'Hello World'
)
      )
);
// assertTag() 를 사용하여 $matcher 를 $html 에 적용합니다
$this->assertTag($matcher, $html);
// assertTag() 를 사용하여 $matcher 를 $xml 에 적용합니다
$this->assertTag($matcher, $xml, '', FALSE);
?>
</syntaxhighlight>
===assertThat()===
보다 복잡한 검증들이 PHPUnit_Framework_Constraint 클래스를 사용하여 만들어질 수 있습니다.
이렇게 만들어진 검증은 assertThat() 메소드를 사용하여 평가됩니다.
예4.55 는 logicalNot() 과 equalTo() 를 제약(constraint) 으로 사용하여 assertNotEquals()와 같은 검증을 만든 것입니다.
assertThat(mixed $value, PHPUnit_Framework_Constraint $constraint[, $message = ''])
$value 가 $constraint 와 매치되지 않을 경우, 에러 $message 를 보고합니다.
예4.55: Usage of assertThat()
<syntaxhighlight lang="php">
<?php
  class BiscuitTest extends PHPUnit_Framework_TestCase
{
  public function testEquals()
  {
    $theBiscuit = new Biscuit('Ginger');
    $myBiscuit = new Biscuit('Ginger');
    $this->assertThat(
      $theBiscuit,
      $this->logicalNot(
$this->equalTo($myBiscuit)
)
      );
  }
  66Writing Tests for PHPUnit
}
?>
</syntaxhighlight>
표4.3 제약 은 사용 가능한 PHPUnit_Framework_Constraint 클래스를 정리한 표입니다.
{| class = "collapsible collapsed" width=100% style = "border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; -khtml-border-radius: 10px; -icab-border-radius: 10px; -o-border-radius: 10px; border: 5px groove #000066;"
|- style="color: white; background-color: black;"
|'''제약'''||'''의미'''
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_Attribute attribute(PHPUnit_Framework_Constraint $constraint, $attributeName)||다른 제약을 클래스, 혹은 오브젝트의 속성으로 사용하기 위한 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsAnything anything()||다양한 입력값을 받아들이는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_ArrayHasKey arrayHasKey(mixed $key)||배열 안에 지정한 키값이 들어 있음을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_TraversableContains contains(mixed $value)||Iterator 인터페이스가 구현되어 있는 배열 또는 객체가, 지정한 값을 가지고 있음을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_TraversableContainsOnly containsOnly(string $type)||평가 대상의 array, 혹은 Iterator 인터페이스를 구현한 오브젝트가, 지정한 type 의 값만을 가짐을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_TraversableContainsOnlycontainsOnly InstancesOf(string $classname)||평가 대상의 array, 혹은 Iterator 인터페이스를 구현한 오브젝트가, 지정한 클래스의 인스턴스만을 가짐을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsEqual equalTo($value, $delta = 0, $maxDepth = 10)||하나의 값이 다른 값과 일치함을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_Attributeattribute EqualTo($attributeName,$value, $delta = 0, $maxDepth = 10)||하나의 값이 클래스 혹은 오브젝트의 속성과 같음을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_FileExists fileExists()||지정한 파일이 존재함을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_GreaterThan greaterThan(mixed $value)||평가 대상 값이 지정값보다 큼을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_OrgreaterThanOrEqual(mixed $value)||평가 대상 값이 지정값 이상임을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_ClassHasAttribute classHasAttribute(string $attributeName)||평가 대상 클래스가 지정 속성을 가짐을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_ClassHasStaticAttributeclass HasStaticAttribute(string $attributeName)||평가 대상 클래스가 지정한 static 속성을 가짐을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_ObjectHasAttributeh asAttribute(string $attributeName)||평가 대상 오브젝트가 지정한 속성을 가짐을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsIdentical identicalTo(mixed $value)||하나의 값이 다른 값과 동일함을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsFalse isFalse()||평가 대상 값이 FALSE 임을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsInstanceOf isInstanceOf(string $className)||평가 대상 오브젝트가 지정 클래스의 인스턴스임을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsNull isNull()||평가 대상 값이 NULL 임을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsTrue isTrue()||평가 대상 값이 TRUE 임을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_IsType isType(string $type)||평가 대상 값이 지정한 type 임을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_LessThan lessThan(mixed $value)||평가 대상 값이 지정값보다 작음을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_OrlessThanOrEqual(mixed $value)||평가 대상 값이 지정값 이하임을 검증하는 제약
|- style="vertical-align:top;"
|logicalAnd()||AND 연산
|- style="vertical-align:top;"
|logicalNot(PHPUnit_Framework_Constraint $constraint)||NOT 연산
|- style="vertical-align:top;"
|logicalOr()||OR 연산
|- style="vertical-align:top;"
|logicalXor()||XOR 연산
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_PCREMatch matchesRegularExpression(string $pattern)||평가 대상 문자열이 정규표현에 매치함을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_StringContains stringContains(string $string, bool $case)||평가 대상 문자열이 지정 문자열을 포함함을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_StringEndsWith stringEndsWith(string $suffix)||평가 대상 문자열이 지정 문자열로 끝남을 검증하는 제약
|- style="vertical-align:top;"
|PHPUnit_Framework_Constraint_StringStartsWith stringStartsWith(string $prefix)||평가 대상 문자열이 지정 문자열로 시작함을 검증하는 제약
|- style="color: black; background-color: gray;"
| colspan="2" |표4.3 제약
|}
===assertTrue()===
assertTrue(bool $condition[, string $message = ''])
$condition 이 FALSE 인 경우, 에러 $message 를 보고합니다.
예4.56 assertTrue() 사용법
<syntaxhighlight lang="php">
<?php
    class TrueTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertTrue(FALSE);
  }
}
?>
</syntaxhighlight>
<syntaxhighlight lang="text">
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) TrueTest::testFailure
Failed asserting that false is true.
/home/sb/TrueTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit TrueTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) TrueTest::testFailure
Failed asserting that false is true.
/home/sb/TrueTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
</syntaxhighlight>
===assertXmlFileEqualsXmlFile()===
assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile[, string $message = ''])
$actualFile 의 XML 문서가, $expectedFile 의 XML 문서와 일치하지 않을 경우, 에러 $message 를 보고합니다
assertXmlFileNotEqualsXmlFile() 는 이 검증의 반대 의미로, 같은 인수를 받습니다.
예4.57 assertXmlFileEqualsXmlFile() 사용법
<syntaxhighlight lang="php">
<?php
    class XmlFileEqualsXmlFileTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertXmlFileEqualsXmlFile(
      '/home/sb/expected.xml', '/home/sb/actual.xml');
  }
}
?>
</syntaxhighlight>
<syntaxhighlight lang="text">
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.phpunit XmlFileEqualsXmlFileTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
</syntaxhighlight>
===assertXmlStringEqualsXmlFile()===
assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml[, string $message = ''])
$actualXml 의 XML 문서가 $expectedFile 의 XML 문서와 일치하지 않을 경우, 에러 $message 를 보고합니다.
assertXmlStringNotEqualsXmlFile() 는 이 검증의 반대 의미로, 같은 인수를 받습니다.
예4.58 assertXmlStringEqualsXmlFile() 사용법
<syntaxhighlight lang="php">
<?php
    class XmlStringEqualsXmlFileTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertXmlStringEqualsXmlFile(
'/home/sb/expected.xml', '<foo><baz/></foo>');
  }
}
?>
</syntaxhighlight>
<syntaxhighlight lang="text">
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.phpunit XmlStringEqualsXmlFileTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
</syntaxhighlight>
===assertXmlStringEqualsXmlString()===
assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml[, string $message = ''])
$actualXml 의 XML 문서가 $expectedXml 의 XML 문서와 일치하지 않을 경우, 에러 $message 를 보고합니다.
assertXmlStringNotEqualsXmlString() 는 이 검증의 반대 의미로, 같은 인수를 받습니다.
예4.59 assertXmlStringEqualsXmlString() 사용법
<syntaxhighlight lang="php">
<?php
    class XmlStringEqualsXmlStringTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertXmlStringEqualsXmlString(
  '<foo><bar/></foo>', '<foo><baz/></foo>');
  }
}
?>
</syntaxhighlight>
<syntaxhighlight lang="text">
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit XmlStringEqualsXmlStringTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:7
FAILURES!
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Tests: 1, Assertions: 1, Failures: 1.

Revision as of 13:14, 1 July 2013

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.


assertTag()

assertTag(array $matcher, string $actual[, string $message = , boolean $isHtml = TRUE])


$actual 이 $matcher 와 매치되지 않는 경우, 에러 $message 를 보고합니다.

$matcher 는 associative array 로, 검증에 사용할 매치 조건을 지정합니다.

  • id: 지정한 id 속성의 노드가 대응하는 값과 매치될 것
  • tag: 노드의 형태가 대응하는 값과 매치될 것
  • attributes: 노드의 속성이 대응하는 값의 associative array $attributes 과 매치될 것
  • content: 텍스트의 내용이 지정한 값과 매치될 것
  • parent: 노드의 parent 가 associative array $parent 과 매치될 것
  • child: 노드를 직접 계승하는 child 중 적어도 하나가 associative array $child 의 조건을 만족시킬 것
  • ancestor: 노드의 조상 중 적어도 하나가 associative array $ancestor 의 조건을 만족시킬 것
  • descendant: 노드의 자손 중 적어도 하나가 associative array $descendant 의 조건을 만족시킬 것
  • children: 노드의 child 의 숫자를 세기 위한 associative array
  • count: 매치되는 child 의 숫자가 이 값과 일치할 것
  • less_than: 매치되는 child 의 숫자가 이 값보다 작을 것
  • greater_than: 매치되는 child 의 숫자가 이 값보다 많을 것
  • only: associative array 로 child 매치용 키를 지정하고, 매치하는 child 숫자를 센다


assertNotTag() 은 이 검증과 반대 의미로, 같은 인수를 받습니다.


예4.54 assertTag() 사용법

    <?php
    // id="my_id" 요소가 있음을 검증하는 matcher
    $matcher = array('id' => 'my_id');
// "span" 태그가 존재함을 검증하는 matcher
$matcher = array('tag' => 'span');
// 값이 "Hello World" 인 "span" 태그가 존재함을 검증한다
// matcher
$matcher = array('tag' => 'span', 'content' => 'Hello World');
// 정규표현으로 지정한 내용과 일치하는 값을 가지는 "span" 태그가
// 존재함을 검증하는 matcher
$matcher = array('tag' => 'span', 'content' => 'regexp:/Try P(HP|ython)/');
// class 속성으로 "list" 가 지정된 "span" 태그가 존재함을 검증하는 matcher
$matcher = array(
		 'tag' => 'span',
		 'attributes' => array('class' => 'list')
		 );
// "span" 이 "div" 의 내부에 존재함을 검증하는 matcher
$matcher = array(
		 'tag' => 'span',
		 'parent' => array('tag' => 'div')
		 );
// "span" 이 "table" 안의 어딘가에 존재함을 검증하는 matcher
$matcher = array(
		 'tag' => 'span',
		 'ancestor' => array('tag' => 'table')
		 );
// child 요소 중 적어도 하나의 "em" 을 가지는 "span" 이 존재함을 검증하는 matcher
$matcher = array(
		 'tag' => 'span',
		 'child' => array('tag' => 'em')
		 );
// "span" 의 안에 (몇 단계 하위 계층의 안에라도)
// "strong" 태그가 존재함을 검증하는 matcher
$matcher = array(
		 'tag' => 'span',
		 'descendant' => array('tag' => 'strong')
		 );
// 직접 계승하는 child 중, 5개에서 10개 사이의 "em" 태그를 가지는 "span"
// 존재함을 검증하는 matcher
$matcher = array(
		 'tag' => 'span',
		 'children' => array(
				     'less_than' => 11,
				     'greater_than' => 4,
				     'only' => array('tag' => 'em')
				     )
		 );
// "div" 태그가 존재하고, 조상으로 "ul", parent 로 "li"
// (class="enum") 을 가지며, id="my_test" 의 값이
// "Hello World" 인 "span" 을 자손으로 가짐을 검증하는 matcher
$matcher = array(
		 'tag' => 'div',
		 'ancestor' => array('tag' => 'ul'),
		 'parent' => array(
				   'tag' => 'li',
				   'attributes' => array('class' => 'enum')
				   ),
		 'descendant' => array(
				       'tag' => 'span',
				       'child' => array(
							'id' => 'my_test',
							'content' => 'Hello World'
							)
				       )
		 );
// assertTag() 를 사용하여 $matcher 를 $html 에 적용합니다
$this->assertTag($matcher, $html);
// assertTag() 를 사용하여 $matcher 를 $xml 에 적용합니다
$this->assertTag($matcher, $xml, '', FALSE);
?>


assertThat()

보다 복잡한 검증들이 PHPUnit_Framework_Constraint 클래스를 사용하여 만들어질 수 있습니다. 이렇게 만들어진 검증은 assertThat() 메소드를 사용하여 평가됩니다. 예4.55 는 logicalNot() 과 equalTo() 를 제약(constraint) 으로 사용하여 assertNotEquals()와 같은 검증을 만든 것입니다.

assertThat(mixed $value, PHPUnit_Framework_Constraint $constraint[, $message = ])

$value 가 $constraint 와 매치되지 않을 경우, 에러 $message 를 보고합니다.


예4.55: Usage of assertThat()

<?php
  class BiscuitTest extends PHPUnit_Framework_TestCase
{
  public function testEquals()
  {
    $theBiscuit = new Biscuit('Ginger');
    $myBiscuit = new Biscuit('Ginger');
    $this->assertThat(
		      $theBiscuit,
		      $this->logicalNot(
					$this->equalTo($myBiscuit)
					)
		      );
  }
  66Writing Tests for PHPUnit
}
?>


표4.3 제약 은 사용 가능한 PHPUnit_Framework_Constraint 클래스를 정리한 표입니다.


assertTrue()

assertTrue(bool $condition[, string $message = ])


$condition 이 FALSE 인 경우, 에러 $message 를 보고합니다.


예4.56 assertTrue() 사용법

<?php
    class TrueTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertTrue(FALSE);
  }
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) TrueTest::testFailure
Failed asserting that false is true.
/home/sb/TrueTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit TrueTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There was 1 failure:
1) TrueTest::testFailure
Failed asserting that false is true.
/home/sb/TrueTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.


assertXmlFileEqualsXmlFile()

assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile[, string $message = ])


$actualFile 의 XML 문서가, $expectedFile 의 XML 문서와 일치하지 않을 경우, 에러 $message 를 보고합니다

assertXmlFileNotEqualsXmlFile() 는 이 검증의 반대 의미로, 같은 인수를 받습니다.


예4.57 assertXmlFileEqualsXmlFile() 사용법

<?php
    class XmlFileEqualsXmlFileTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertXmlFileEqualsXmlFile(
				      '/home/sb/expected.xml', '/home/sb/actual.xml');
  }
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.phpunit XmlFileEqualsXmlFileTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.


assertXmlStringEqualsXmlFile()

assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml[, string $message = ])


$actualXml 의 XML 문서가 $expectedFile 의 XML 문서와 일치하지 않을 경우, 에러 $message 를 보고합니다.

assertXmlStringNotEqualsXmlFile() 는 이 검증의 반대 의미로, 같은 인수를 받습니다.


예4.58 assertXmlStringEqualsXmlFile() 사용법

<?php
    class XmlStringEqualsXmlFileTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertXmlStringEqualsXmlFile(
					'/home/sb/expected.xml', '<foo><baz/></foo>');
  }
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.phpunit XmlStringEqualsXmlFileTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.25Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.


assertXmlStringEqualsXmlString()

assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml[, string $message = ])


$actualXml 의 XML 문서가 $expectedXml 의 XML 문서와 일치하지 않을 경우, 에러 $message 를 보고합니다.

assertXmlStringNotEqualsXmlString() 는 이 검증의 반대 의미로, 같은 인수를 받습니다.


예4.59 assertXmlStringEqualsXmlString() 사용법

<?php
     class XmlStringEqualsXmlStringTest extends PHPUnit_Framework_TestCase
{
  public function testFailure()
  {
    $this->assertXmlStringEqualsXmlString(
					  '<foo><bar/></foo>', '<foo><baz/></foo>');
  }
}
?>
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.phpunit XmlStringEqualsXmlStringTest
PHPUnit 3.7.0 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 5.00Mb
There 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:7
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.


Notes