|
11 | 11 |
|
12 | 12 | namespace Symfony\Bridge\PhpUnit\Legacy;
|
13 | 13 |
|
| 14 | +use PHPUnit\Framework\Error\Error; |
| 15 | +use PHPUnit\Framework\Error\Notice; |
| 16 | +use PHPUnit\Framework\Error\Warning; |
14 | 17 | use PHPUnit\Framework\MockObject\MockObject;
|
15 | 18 | use PHPUnit\Framework\TestCase;
|
16 | 19 |
|
@@ -66,9 +69,7 @@ protected function createPartialMock($originalClassName, array $methods)
|
66 | 69 | */
|
67 | 70 | public function expectException($exception)
|
68 | 71 | {
|
69 |
| - $property = new \ReflectionProperty(TestCase::class, 'expectedException'); |
70 |
| - $property->setAccessible(true); |
71 |
| - $property->setValue($this, $exception); |
| 72 | + $this->doExpectException($exception); |
72 | 73 | }
|
73 | 74 |
|
74 | 75 | /**
|
@@ -116,4 +117,95 @@ public function expectExceptionMessageRegExp($messageRegExp)
|
116 | 117 | $property->setAccessible(true);
|
117 | 118 | $property->setValue($this, $messageRegExp);
|
118 | 119 | }
|
| 120 | + |
| 121 | + /** |
| 122 | + * @return void |
| 123 | + */ |
| 124 | + public function expectNotice() |
| 125 | + { |
| 126 | + $this->doExpectException(Notice::class); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @param string $message |
| 131 | + * |
| 132 | + * @return void |
| 133 | + */ |
| 134 | + public function expectNoticeMessage($message) |
| 135 | + { |
| 136 | + $this->expectExceptionMessage($message); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * @param string $regularExpression |
| 141 | + * |
| 142 | + * @return void |
| 143 | + */ |
| 144 | + public function expectNoticeMessageMatches($regularExpression) |
| 145 | + { |
| 146 | + $this->expectExceptionMessageMatches($regularExpression); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * @return void |
| 151 | + */ |
| 152 | + public function expectWarning() |
| 153 | + { |
| 154 | + $this->doExpectException(Warning::class); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * @param string $message |
| 159 | + * |
| 160 | + * @return void |
| 161 | + */ |
| 162 | + public function expectWarningMessage($message) |
| 163 | + { |
| 164 | + $this->expectExceptionMessage($message); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * @param string $regularExpression |
| 169 | + * |
| 170 | + * @return void |
| 171 | + */ |
| 172 | + public function expectWarningMessageMatches($regularExpression) |
| 173 | + { |
| 174 | + $this->expectExceptionMessageMatches($regularExpression); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @return void |
| 179 | + */ |
| 180 | + public function expectError() |
| 181 | + { |
| 182 | + $this->doExpectException(Error::class); |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * @param string $message |
| 187 | + * |
| 188 | + * @return void |
| 189 | + */ |
| 190 | + public function expectErrorMessage($message) |
| 191 | + { |
| 192 | + $this->expectExceptionMessage($message); |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * @param string $regularExpression |
| 197 | + * |
| 198 | + * @return void |
| 199 | + */ |
| 200 | + public function expectErrorMessageMatches($regularExpression) |
| 201 | + { |
| 202 | + $this->expectExceptionMessageMatches($regularExpression); |
| 203 | + } |
| 204 | + |
| 205 | + private function doExpectException($exception) |
| 206 | + { |
| 207 | + $property = new \ReflectionProperty(TestCase::class, 'expectedException'); |
| 208 | + $property->setAccessible(true); |
| 209 | + $property->setValue($this, $exception); |
| 210 | + } |
119 | 211 | }
|
0 commit comments