Skip to content

Commit c7bade2

Browse files
minor #32869 [PhpUnitBridge] Add polyfill for expectException* methods (jderusse)
This PR was merged into the 5.0-dev branch. Discussion ---------- [PhpUnitBridge] Add polyfill for expectException* methods | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32844 | License | MIT | Doc PR | NA this PR provides a polyfill for methods `setException`, `setExceptionMessage`, `setExceptionMessageRegExp` and `setExceptionCode` Commits ------- c7a8ce5 [Bridge/PhpUnit] Add polyfill for expectException*
2 parents 3d52d5a + c7a8ce5 commit c7bade2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

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

Lines changed: 93 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,93 @@ 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+
}
281+
282+
/**
283+
* @param string $exceptionMessage
284+
*
285+
* @return void
286+
*/
287+
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
288+
{
289+
$this->forwardCompatExpectedExceptionMessage = $exceptionMessage;
290+
$this->forwardCompatExpectedExceptionCode = $exceptionCode;
291+
292+
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
293+
}
294+
295+
/**
296+
* @param string $exceptionMessageRegExp
297+
*
298+
* @return void
299+
*/
300+
public function setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp = '', $exceptionCode = null)
301+
{
302+
$this->forwardCompatExpectedExceptionCode = $exceptionCode;
303+
304+
parent::setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp, $exceptionCode);
305+
}
213306
}

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