Skip to content

Commit edbc69f

Browse files
Merge branch '4.3' into 4.4
* 4.3: cs fix Replace calls to setExpectedException by Pollyfill
2 parents b837d6c + 80593eb commit edbc69f

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

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
}

Legacy/ForwardCompatTestTraitForV7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ protected function createMock($originalClassName): MockObject
3030
->disableOriginalClone()
3131
->disableArgumentCloning()
3232
->disallowMockingUnknownTypes()
33-
->getMock();
33+
->getMock();
3434
}
3535
}

Tests/ProcessIsolationTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Bridge\PhpUnit\Tests;
44

55
use PHPUnit\Framework\TestCase;
6+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
67

78
/**
89
* Don't remove this test case, it tests the legacy group.
@@ -13,6 +14,8 @@
1314
*/
1415
class ProcessIsolationTest extends TestCase
1516
{
17+
use ForwardCompatTestTrait;
18+
1619
/**
1720
* @expectedDeprecation Test abc
1821
*/
@@ -25,12 +28,8 @@ public function testIsolation()
2528
public function testCallingOtherErrorHandler()
2629
{
2730
$class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception';
28-
if (method_exists($this, 'expectException')) {
29-
$this->expectException($class);
30-
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
31-
} else {
32-
$this->setExpectedException($class, 'Test that PHPUnit\'s error handler fires.');
33-
}
31+
$this->expectException($class);
32+
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
3433

3534
trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING);
3635
}

0 commit comments

Comments
 (0)