Skip to content

Commit 2958141

Browse files
Make tests support phpunit 8
1 parent 8f1f27c commit 2958141

File tree

5 files changed

+177
-3
lines changed

5 files changed

+177
-3
lines changed

ForwardCompatTestTrait.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
// A trait to provide forward compatibility with newest PHPUnit versions
17+
18+
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
19+
trait ForwardCompatTestTrait
20+
{
21+
use Legacy\ForwardCompatTestTraitForV8;
22+
}
23+
} else {
24+
trait ForwardCompatTestTrait
25+
{
26+
use Legacy\ForwardCompatTestTraitForV5;
27+
}
28+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
/**
15+
* @internal
16+
*/
17+
trait ForwardCompatTestTraitForV5
18+
{
19+
/**
20+
* @return void
21+
*/
22+
public static function setUpBeforeClass()
23+
{
24+
self::doSetUpBeforeClass();
25+
}
26+
27+
/**
28+
* @return void
29+
*/
30+
public static function tearDownAfterClass()
31+
{
32+
self::doTearDownAfterClass();
33+
}
34+
35+
/**
36+
* @return void
37+
*/
38+
protected function setUp()
39+
{
40+
self::doSetUp();
41+
}
42+
43+
/**
44+
* @return void
45+
*/
46+
protected function tearDown()
47+
{
48+
self::doTearDown();
49+
}
50+
51+
/**
52+
* @return void
53+
*/
54+
private static function doSetUpBeforeClass()
55+
{
56+
parent::setUpBeforeClass();
57+
}
58+
59+
/**
60+
* @return void
61+
*/
62+
private static function doTearDownAfterClass()
63+
{
64+
parent::tearDownAfterClass();
65+
}
66+
67+
/**
68+
* @return void
69+
*/
70+
private function doSetUp()
71+
{
72+
parent::setUp();
73+
}
74+
75+
/**
76+
* @return void
77+
*/
78+
private function doTearDown()
79+
{
80+
parent::tearDown();
81+
}
82+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
/**
15+
* @internal
16+
*/
17+
trait ForwardCompatTestTraitForV8
18+
{
19+
public static function setUpBeforeClass(): void
20+
{
21+
self::doSetUpBeforeClass();
22+
}
23+
24+
public static function tearDownAfterClass(): void
25+
{
26+
self::doTearDownAfterClass();
27+
}
28+
29+
protected function setUp(): void
30+
{
31+
self::doSetUp();
32+
}
33+
34+
protected function tearDown(): void
35+
{
36+
self::doTearDown();
37+
}
38+
39+
private static function doSetUpBeforeClass(): void
40+
{
41+
parent::setUpBeforeClass();
42+
}
43+
44+
private static function doTearDownAfterClass(): void
45+
{
46+
parent::tearDownAfterClass();
47+
}
48+
49+
private function doSetUp(): void
50+
{
51+
parent::setUp();
52+
}
53+
54+
private function doTearDown(): void
55+
{
56+
parent::tearDown();
57+
}
58+
}

Tests/ClockMockTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ClockMock;
16+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1617

1718
/**
1819
* @author Dominic Tubach <[email protected]>
@@ -21,12 +22,14 @@
2122
*/
2223
class ClockMockTest extends TestCase
2324
{
24-
public static function setUpBeforeClass()
25+
use ForwardCompatTestTrait;
26+
27+
private static function doSetUpBeforeClass()
2528
{
2629
ClockMock::register(__CLASS__);
2730
}
2831

29-
protected function setUp()
32+
private function doSetUp()
3033
{
3134
ClockMock::withClockMock(1234567890.125);
3235
}

Tests/DnsMockTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\DnsMock;
16+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1617

1718
class DnsMockTest extends TestCase
1819
{
19-
protected function tearDown()
20+
use ForwardCompatTestTrait;
21+
22+
private function doTearDown()
2023
{
2124
DnsMock::withMockedHosts(array());
2225
}

0 commit comments

Comments
 (0)