Skip to content

Commit dc7a2d7

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

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
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 $forwardCompatExpectedExceptionMessage = '';
23+
private $forwardCompatExpectedExceptionCode = null;
24+
2125
/**
2226
* @return void
2327
*/
@@ -210,4 +214,68 @@ public static function assertIsIterable($actual, $message = '')
210214
{
211215
static::assertInternalType('iterable', $actual, $message);
212216
}
217+
218+
/**
219+
* @param string $exception
220+
*
221+
* @return void
222+
*/
223+
public function expectException($exception)
224+
{
225+
if (method_exists(TestCase::class, 'expectException')) {
226+
parent::expectException($exception);
227+
228+
return;
229+
}
230+
231+
parent::setExpectedException($exception, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
232+
}
233+
234+
/**
235+
* @return void
236+
*/
237+
public function expectExceptionCode($code)
238+
{
239+
if (method_exists(TestCase::class, 'expectExceptionCode')) {
240+
parent::expectExceptionCode($code);
241+
242+
return;
243+
}
244+
245+
$this->forwardCompatExpectedExceptionCode = $code;
246+
parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
247+
}
248+
249+
/**
250+
* @param string $message
251+
*
252+
* @return void
253+
*/
254+
public function expectExceptionMessage($message)
255+
{
256+
if (method_exists(TestCase::class, 'expectExceptionMessage')) {
257+
parent::expectExceptionMessage($message);
258+
259+
return;
260+
}
261+
262+
$this->forwardCompatExpectedExceptionMessage = $message;
263+
parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
264+
}
265+
266+
/**
267+
* @param string $messageRegExp
268+
*
269+
* @return void
270+
*/
271+
public function expectExceptionMessageRegExp($messageRegExp)
272+
{
273+
if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) {
274+
parent::expectExceptionMessageRegExp($messageRegExp);
275+
276+
return;
277+
}
278+
279+
parent::setExpectedExceptionRegExp(parent::getExpectedException(), $messageRegExp, $this->forwardCompatExpectedExceptionCode);
280+
}
213281
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy