| 148 |
lars |
1 |
<?php
|
|
|
2 |
namespace Hamcrest\Core;
|
|
|
3 |
|
|
|
4 |
class IsInstanceOfTest extends \Hamcrest\AbstractMatcherTest
|
|
|
5 |
{
|
|
|
6 |
|
|
|
7 |
private $_baseClassInstance;
|
|
|
8 |
private $_subClassInstance;
|
|
|
9 |
|
|
|
10 |
protected function setUp()
|
|
|
11 |
{
|
|
|
12 |
$this->_baseClassInstance = new \Hamcrest\Core\SampleBaseClass('good');
|
|
|
13 |
$this->_subClassInstance = new \Hamcrest\Core\SampleSubClass('good');
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
protected function createMatcher()
|
|
|
17 |
{
|
|
|
18 |
return \Hamcrest\Core\IsInstanceOf::anInstanceOf('stdClass');
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
public function testEvaluatesToTrueIfArgumentIsInstanceOfASpecificClass()
|
|
|
22 |
{
|
|
|
23 |
assertThat($this->_baseClassInstance, anInstanceOf('Hamcrest\Core\SampleBaseClass'));
|
|
|
24 |
assertThat($this->_subClassInstance, anInstanceOf('Hamcrest\Core\SampleSubClass'));
|
|
|
25 |
assertThat(null, not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
26 |
assertThat(new \stdClass(), not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
public function testEvaluatesToFalseIfArgumentIsNotAnObject()
|
|
|
30 |
{
|
|
|
31 |
assertThat(null, not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
32 |
assertThat(false, not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
33 |
assertThat(5, not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
34 |
assertThat('foo', not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
35 |
assertThat(array(1, 2, 3), not(anInstanceOf('Hamcrest\Core\SampleBaseClass')));
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public function testHasAReadableDescription()
|
|
|
39 |
{
|
|
|
40 |
$this->assertDescription('an instance of stdClass', anInstanceOf('stdClass'));
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public function testDecribesActualClassInMismatchMessage()
|
|
|
44 |
{
|
|
|
45 |
$this->assertMismatchDescription(
|
|
|
46 |
'[Hamcrest\Core\SampleBaseClass] <good>',
|
|
|
47 |
anInstanceOf('Hamcrest\Core\SampleSubClass'),
|
|
|
48 |
$this->_baseClassInstance
|
|
|
49 |
);
|
|
|
50 |
}
|
|
|
51 |
}
|