1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPKitchen\CodeSpecsCore\Expectation\Matcher; |
4
|
|
|
|
5
|
|
|
use DOMElement; |
6
|
|
|
use PHPKitchen\CodeSpecsCore\Expectation\Internal\ObjectExceptionMatcher; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ObjectMatcher is designed to check given object matches expectation. |
10
|
|
|
* |
11
|
|
|
* @package PHPKitchen\CodeSpecsCore\Expectation |
12
|
|
|
* @author Dmitry Kolodko <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class ObjectMatcher extends ValueMatcher { |
15
|
|
|
/** |
16
|
|
|
* @return $this |
17
|
|
|
*/ |
18
|
|
|
public function isInstanceOf($class): self { |
19
|
|
|
$this->startStep('is instance of "' . $class . '"') |
20
|
|
|
->assertInstanceOf($class); |
21
|
|
|
return $this; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return $this |
26
|
|
|
*/ |
27
|
|
|
public function isNotInstanceOf($class): self { |
28
|
|
|
$this->startStep('is not instance of "' . $class . '"') |
29
|
|
|
->assertNotInstanceOf($class); |
30
|
|
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Asserts that a hierarchy of DOMElements matches. |
35
|
|
|
*/ |
36
|
|
|
/** |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
|
public function isEqualToXmlStructure($expectedElement): self { |
40
|
|
|
$this->isInstanceOf(DOMElement::class); |
41
|
|
|
$this->startStep('is equal to expected DOMElement') |
42
|
|
|
->assertEqualXMLStructure($expectedElement, false); |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Asserts that a hierarchy of DOMElements matches and ensures attributes of structures also equals. |
48
|
|
|
* |
49
|
|
|
* @param DOMElement $expectedElement |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
/** |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function isEqualToXmlStructureAndItsAttributes($expectedElement): self { |
56
|
|
|
$this->isInstanceOf(DOMElement::class); |
57
|
|
|
$this->startStep('is equal to xml structure and it\'s attributes in DOMElement') |
58
|
|
|
->assertEqualXMLStructure($expectedElement, true); |
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
public function hasAttribute($attribute): self { |
66
|
|
|
$this->startStep('has attribute "' . $attribute . '"') |
67
|
|
|
->assertObjectHasAttribute($attribute); |
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function doesNotHaveAttribute($attribute): self { |
75
|
|
|
$this->startStep('does not have attribute "' . $attribute . '"') |
76
|
|
|
->assertObjectNotHasAttribute($attribute); |
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function throwsException($exceptionClass): ObjectExceptionMatcher { |
81
|
|
|
$this->startStep('throws exception "' . $exceptionClass . '"') |
82
|
|
|
->expectException($exceptionClass); |
83
|
|
|
|
84
|
|
|
return $this->createInternalMatcherWithDescription(ObjectExceptionMatcher::class, 'I see that exception "' . $exceptionClass . '"'); |
85
|
|
|
} |
86
|
|
|
} |