Skip to content

Commit c051426

Browse files
[Bridge/PhpUnit] add SetUpTearDownTrait
1 parent b9ddb6f commit c051426

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

SetUpTearDownTrait.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
// 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\Bridge\PhpUnit;
21+
22+
trait SetUpTearDownTrait
23+
{
24+
private function doSetUp(): void
25+
{
26+
parent::setUp();
27+
}
28+
29+
private function doTearDown(): void
30+
{
31+
parent::tearDown();
32+
}
33+
34+
protected function setUp(): void
35+
{
36+
$this->doSetUp();
37+
}
38+
39+
protected function tearDown(): void
40+
{
41+
$this->doTearDown();
42+
}
43+
}
44+
');
45+
} else {
46+
trait SetUpTearDownTrait
47+
{
48+
/**
49+
* @return void
50+
*/
51+
private function doSetUp()
52+
{
53+
parent::setUp();
54+
}
55+
56+
/**
57+
* @return void
58+
*/
59+
private function doTearDown()
60+
{
61+
parent::tearDown();
62+
}
63+
64+
/**
65+
* @return void
66+
*/
67+
protected function setUp()
68+
{
69+
$this->doSetUp();
70+
}
71+
72+
/**
73+
* @return void
74+
*/
75+
protected function tearDown()
76+
{
77+
$this->doTearDown();
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)