Skip to content

Commit 1db6f01

Browse files
committed
compatibility with phpunit8
1 parent 6bb023f commit 1db6f01

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

Test/ConstraintValidatorTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
abstract class ConstraintValidatorTestCase extends TestCase
3131
{
32+
use TestCaseSetUpTearDownTrait;
33+
3234
/**
3335
* @var ExecutionContextInterface
3436
*/
@@ -48,7 +50,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
4850
protected $constraint;
4951
protected $defaultTimezone;
5052

51-
protected function setUp()
53+
private function doSetUp()
5254
{
5355
$this->group = 'MyGroup';
5456
$this->metadata = null;
@@ -70,7 +72,7 @@ protected function setUp()
7072
$this->setDefaultTimezone('UTC');
7173
}
7274

73-
protected function tearDown()
75+
private function doTearDown()
7476
{
7577
$this->restoreDefaultTimezone();
7678
}

Test/TestCaseSetUpTearDownTrait.php

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\Component\Validator\Test;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the setUp/tearDown methods
17+
18+
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
19+
eval('
20+
namespace Symfony\Component\Validator\Test;
21+
22+
/**
23+
* @internal
24+
*/
25+
trait TestCaseSetUpTearDownTrait
26+
{
27+
private function doSetUp(): void
28+
{
29+
}
30+
31+
private function doTearDown(): void
32+
{
33+
}
34+
35+
protected function setUp(): void
36+
{
37+
$this->doSetUp();
38+
}
39+
40+
protected function tearDown(): void
41+
{
42+
$this->doTearDown();
43+
}
44+
}
45+
');
46+
} else {
47+
/**
48+
* @internal
49+
*/
50+
trait TestCaseSetUpTearDownTrait
51+
{
52+
/**
53+
* @return void
54+
*/
55+
private function doSetUp()
56+
{
57+
}
58+
59+
/**
60+
* @return void
61+
*/
62+
private function doTearDown()
63+
{
64+
}
65+
66+
/**
67+
* @return void
68+
*/
69+
protected function setUp()
70+
{
71+
$this->doSetUp();
72+
}
73+
74+
/**
75+
* @return void
76+
*/
77+
protected function tearDown()
78+
{
79+
$this->doTearDown();
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)