1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11: namespace expect\matcher;
12:
13: use expect\FailedMessage;
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: final class ToBeAnInstanceOf implements ReportableMatcher
29: {
30: 31: 32:
33: private $actual;
34:
35: 36: 37:
38: private $expected;
39:
40: 41: 42:
43: private $className;
44:
45: 46: 47: 48: 49:
50: public function __construct($expected)
51: {
52: $this->expected = $expected;
53: }
54:
55: 56: 57:
58: public function match($actual)
59: {
60: $result = false;
61: $this->actual = $actual;
62:
63: if (is_object($this->actual)) {
64: $this->className = get_class($this->actual);
65: $result = $this->actual instanceof $this->expected;
66: } else {
67: $this->className = $actual;
68: }
69:
70: return $result;
71: }
72:
73: 74: 75:
76: public function reportFailed(FailedMessage $message)
77: {
78: $message->appendText('Expected ')
79: ->appendText($this->className)
80: ->appendText(' to be an instance of ')
81: ->appendText($this->expected)
82: ->appendText("\n\n")
83: ->appendText(' expected: ')
84: ->appendText($this->expected)
85: ->appendText("\n")
86: ->appendText(' got: ')
87: ->appendText($this->className);
88: }
89:
90: 91: 92:
93: public function reportNegativeFailed(FailedMessage $message)
94: {
95: $message->appendText('Expected ')
96: ->appendText($this->className)
97: ->appendText(' not to be an instance of ')
98: ->appendText($this->expected)
99: ->appendText("\n\n")
100: ->appendText(' expected not: ')
101: ->appendText($this->expected)
102: ->appendText("\n")
103: ->appendText(' got: ')
104: ->appendText($this->className);
105: }
106: }
107: