1 | <?php |
||
15 | abstract class TestCase extends \PHPUnit\Framework\TestCase |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $expectedException; |
||
|
|||
21 | |||
22 | /** |
||
23 | * @inheritDoc |
||
24 | */ |
||
25 | 7 | protected function tearDown() |
|
30 | |||
31 | /** |
||
32 | * Returns whether the class' parent method exists. |
||
33 | * |
||
34 | * @param string $name |
||
35 | * @return bool |
||
36 | * |
||
37 | * @internal |
||
38 | */ |
||
39 | 3 | protected function isParentMethod($name) |
|
43 | |||
44 | /** |
||
45 | * Returns a test double for the specified class. |
||
46 | * |
||
47 | * @param string $originalClassName |
||
48 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
49 | */ |
||
50 | 2 | protected function createMock($originalClassName) |
|
51 | { |
||
52 | 2 | if ($this->isParentMethod(__FUNCTION__)) { |
|
53 | 2 | return parent::createMock($originalClassName); |
|
54 | } |
||
55 | |||
56 | 1 | return $this |
|
57 | 2 | ->getMockBuilder($originalClassName) |
|
58 | 2 | ->disableOriginalConstructor() |
|
59 | 2 | ->disableOriginalClone() |
|
60 | 2 | ->disableArgumentCloning() |
|
61 | 2 | ->getMock(); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Sets an exception expected. |
||
66 | * |
||
67 | * @param string $exception |
||
68 | * @throws Exception|\PHPUnit_Framework_Exception |
||
69 | */ |
||
70 | 7 | public function expectException($exception) |
|
71 | { |
||
72 | 7 | if ($this->isParentMethod(__FUNCTION__)) { |
|
73 | 2 | parent::expectException($exception); |
|
74 | 2 | return; |
|
75 | } |
||
76 | |||
77 | 5 | if (!is_string($exception)) { |
|
78 | 3 | if (class_exists('PHPUnit\Util\InvalidArgumentHelper')) { |
|
79 | 1 | throw InvalidArgumentHelper::factory(1, 'string'); |
|
80 | } else { |
||
81 | 2 | throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); |
|
82 | } |
||
83 | } |
||
84 | |||
85 | 2 | $this->expectedException = $exception; |
|
86 | 2 | $this->setExpectedException($this->expectedException); |
|
87 | 2 | } |
|
88 | |||
89 | /** |
||
90 | * Sets an exception code expected. |
||
91 | * |
||
92 | * @param int|string $code |
||
93 | * @throws Exception|\PHPUnit_Framework_Exception |
||
94 | */ |
||
95 | 7 | public function expectExceptionCode($code) |
|
96 | { |
||
97 | 7 | if ($this->isParentMethod(__FUNCTION__)) { |
|
98 | 3 | parent::expectExceptionCode($code); |
|
99 | 3 | return; |
|
100 | } |
||
101 | |||
102 | 5 | if (!is_int($code) && !is_string($code)) { |
|
103 | 3 | if (class_exists('PHPUnit\Util\InvalidArgumentHelper')) { |
|
104 | 1 | throw InvalidArgumentHelper::factory(1, 'integer or string'); |
|
105 | } else { |
||
106 | 2 | throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer or string'); |
|
107 | } |
||
108 | } |
||
109 | |||
110 | 2 | $this->setExpectedException($this->expectedException, '', $code); |
|
111 | 2 | } |
|
112 | |||
113 | /** |
||
114 | * Returns the reflected property. |
||
115 | * |
||
116 | * @param object|string $object |
||
117 | * @param string $name |
||
118 | * @return \ReflectionProperty |
||
119 | */ |
||
120 | 6 | protected function getProperty($object, $name) |
|
128 | |||
129 | /** |
||
130 | * Returns the private/protected property by its name. |
||
131 | * |
||
132 | * @param object|string $object |
||
133 | * @param string $name |
||
134 | * @return mixed |
||
135 | */ |
||
136 | 6 | protected function getInaccessibleProperty($object, $name) |
|
142 | |||
143 | /** |
||
144 | * Sets the private/protected property value by its name. |
||
145 | * |
||
146 | * @param object|string $object |
||
147 | * @param string $name |
||
148 | * @param mixed $value |
||
149 | */ |
||
150 | 6 | protected function setInaccessibleProperty($object, $name, $value) |
|
156 | |||
157 | /** |
||
158 | * Invokes the private/protected method by its name and returns its result. |
||
159 | * |
||
160 | * @param object|string $object |
||
161 | * @param string $name |
||
162 | * @param array $args |
||
163 | * @return mixed |
||
164 | */ |
||
165 | 6 | protected function invokeInaccessibleMethod($object, $name, array $args = []) |
|
171 | } |
||
172 |