Skip to content

Commit 951f008

Browse files
committed
Add a polyfill for setException
1 parent 625fb52 commit 951f008

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php

+70
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

1414
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
1516

1617
/**
1718
* @internal
1819
*/
1920
trait ForwardCompatTestTraitForV5
2021
{
22+
private $forwardCompatExpectedException = null;
23+
private $forwardCompatExpectedExceptionMessage = '';
24+
private $forwardCompatExpectedExceptionCode = null;
25+
2126
/**
2227
* @return void
2328
*/
@@ -210,4 +215,69 @@ public static function assertIsIterable($actual, $message = '')
210215
{
211216
static::assertInternalType('iterable', $actual, $message);
212217
}
218+
219+
/**
220+
* @param string $exception
221+
*
222+
* @return void
223+
*/
224+
public function expectException($exception)
225+
{
226+
if (method_exists(TestCase::class, 'expectException')) {
227+
parent::expectException($exception);
228+
229+
return;
230+
}
231+
232+
$this->forwardCompatExpectedException = $exception;
233+
parent::setExpectedException($this->forwardCompatExpectedException, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
234+
}
235+
236+
/**
237+
* @return void
238+
*/
239+
public function expectExceptionCode($code)
240+
{
241+
if (method_exists(TestCase::class, 'expectExceptionCode')) {
242+
parent::expectExceptionCode($code);
243+
244+
return;
245+
}
246+
247+
$this->forwardCompatExpectedExceptionCode = $code;
248+
parent::setExpectedException($this->forwardCompatExpectedException, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
249+
}
250+
251+
/**
252+
* @param string $message
253+
*
254+
* @return void
255+
*/
256+
public function expectExceptionMessage($message)
257+
{
258+
if (method_exists(TestCase::class, 'expectExceptionMessage')) {
259+
parent::expectExceptionMessage($message);
260+
261+
return;
262+
}
263+
264+
$this->forwardCompatExpectedExceptionMessage = $message;
265+
parent::setExpectedException($this->forwardCompatExpectedException, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
266+
}
267+
268+
/**
269+
* @param string $messageRegExp
270+
*
271+
* @return void
272+
*/
273+
public function expectExceptionMessageRegExp($messageRegExp)
274+
{
275+
if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) {
276+
parent::expectExceptionMessageRegExp($messageRegExp);
277+
278+
return;
279+
}
280+
281+
parent::setExpectedExceptionRegExp($this->forwardCompatExpectedException, $messageRegExp, $this->forwardCompatExpectedExceptionCode);
282+
}
213283
}

0 commit comments

Comments
 (0)