Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d583f80

Browse files
committed
bug #30474 compatibility with phpunit8 (garak)
This PR was merged into the 3.4 branch. Discussion ---------- compatibility with phpunit8 This basically adds the same phpunit8 compatibility layer added in #30084 (but for other test classes) See also discussion in #30071 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30071 | License | MIT | Doc PR | none Commits ------- 5ef254f compatibility with phpunit8
2 parents cf728a5 + 5ef254f commit d583f80

File tree

5 files changed

+175
-5
lines changed

5 files changed

+175
-5
lines changed

src/Symfony/Component/Form/Test/FormIntegrationTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
*/
2121
abstract class FormIntegrationTestCase extends TestCase
2222
{
23+
use TestCaseSetUpTearDownTrait;
24+
2325
/**
2426
* @var FormFactoryInterface
2527
*/
2628
protected $factory;
2729

28-
protected function setUp()
30+
private function doSetUp()
2931
{
3032
$this->factory = Forms::createFormFactoryBuilder()
3133
->addExtensions($this->getExtensions())
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\Form\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\Form\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+
}

src/Symfony/Component/Form/Test/TypeTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
abstract class TypeTestCase extends FormIntegrationTestCase
1919
{
20+
use TestCaseSetUpTearDownTrait;
21+
2022
/**
2123
* @var FormBuilder
2224
*/
@@ -27,15 +29,15 @@ abstract class TypeTestCase extends FormIntegrationTestCase
2729
*/
2830
protected $dispatcher;
2931

30-
protected function setUp()
32+
private function doSetUp()
3133
{
3234
parent::setUp();
3335

3436
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
3537
$this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory);
3638
}
3739

38-
protected function tearDown()
40+
private function doTearDown()
3941
{
4042
if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) {
4143
$this->validator = null;

src/Symfony/Component/Validator/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
}
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)