ObjectMatcher::isNotInstanceOf()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace PHPKitchen\CodeSpecs\Expectation\Matcher;
4
5
use DOMElement;
6
use PHPKitchen\CodeSpecs\Expectation\Internal\ObjectExceptionMatcher;
7
8
/**
9
 * ObjectMatcher is designed to check given object matches expectation.
10
 *
11
 * @package PHPKitchen\CodeSpecs\Expectation
12
 * @author Dima 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
22
        return $this;
23
    }
24
25
    /**
26
     * @return $this
27
     */
28
    public function isNotInstanceOf($class): self {
29
        $this->startStep('is not instance of "' . $class . '"')
30
             ->assertNotInstanceOf($class);
31
32
        return $this;
33
    }
34
35
    /**
36
     * Asserts that a hierarchy of DOMElements matches.
37
     */
38
    /**
39
     * @return $this
40
     */
41
    public function isEqualToXmlStructure($expectedElement): self {
42
        $this->isInstanceOf(DOMElement::class);
43
        $this->startStep('is equal to expected DOMElement')
44
             ->assertEqualXMLStructure($expectedElement, false);
45
46
        return $this;
47
    }
48
49
    /**
50
     * Asserts that a hierarchy of DOMElements matches and ensures attributes of structures also equals.
51
     *
52
     * @param DOMElement $expectedElement
53
     *
54
     * @return $this
55
     */
56
    /**
57
     * @return $this
58
     */
59
    public function isEqualToXmlStructureAndItsAttributes($expectedElement): self {
60
        $this->isInstanceOf(DOMElement::class);
61
        $this->startStep('is equal to xml structure and it\'s attributes in DOMElement')
62
             ->assertEqualXMLStructure($expectedElement, true);
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return $this
69
     */
70
    public function hasAttribute($attribute): self {
71
        $this->startStep('has attribute "' . $attribute . '"')
72
             ->assertObjectHasAttribute($attribute);
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return $this
79
     */
80
    public function doesNotHaveAttribute($attribute): self {
81
        $this->startStep('does not have attribute "' . $attribute . '"')
82
             ->assertObjectNotHasAttribute($attribute);
83
84
        return $this;
85
    }
86
87
    /**
88
     * Start sub-chain of exception matcher.
89
     *
90
     * @param \Exception|string $exceptionClassOrObject exception class or object that going to be thrown by object
91
     *
92
     * @return ObjectExceptionMatcher
93
     */
94
    public function throwsException($exceptionClassOrObject): ObjectExceptionMatcher {
95
        $class = is_string($exceptionClassOrObject) ? $exceptionClassOrObject : get_class($exceptionClassOrObject);
96
        $matcher = $this->createInternalMatcherWithDescription(ObjectExceptionMatcher::class, 'I see that exception "' . $class . '"');
97
98
        $matcher->exceptionClassOrObject = $exceptionClassOrObject;
99
100
        return $matcher;
101
    }
102
}