Skip to content

Commit 2cf8904

Browse files
Make tests support phpunit 8
1 parent 0bb32ea commit 2cf8904

26 files changed

+155
-43
lines changed

Test/KernelShutdownOnTearDownTrait.php renamed to Test/ForwardCompatTestTrait.php

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

1414
use PHPUnit\Framework\TestCase;
1515

16-
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the tearDown method
16+
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the setUp/tearDown methods
1717

1818
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
1919
eval('
@@ -22,26 +22,61 @@
2222
/**
2323
* @internal
2424
*/
25-
trait KernelShutdownOnTearDownTrait
25+
trait ForwardCompatTestTrait
2626
{
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+
2740
protected function tearDown(): void
2841
{
29-
static::ensureKernelShutdown();
42+
$this->doTearDown();
3043
}
3144
}
3245
');
3346
} else {
3447
/**
3548
* @internal
3649
*/
37-
trait KernelShutdownOnTearDownTrait
50+
trait ForwardCompatTestTrait
3851
{
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+
3974
/**
4075
* @return void
4176
*/
4277
protected function tearDown()
4378
{
44-
static::ensureKernelShutdown();
79+
$this->doTearDown();
4580
}
4681
}
4782
}

Test/KernelTestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
abstract class KernelTestCase extends TestCase
2525
{
26-
use KernelShutdownOnTearDownTrait;
26+
use ForwardCompatTestTrait;
2727

2828
protected static $class;
2929

@@ -32,6 +32,11 @@ abstract class KernelTestCase extends TestCase
3232
*/
3333
protected static $kernel;
3434

35+
private function doTearDown()
36+
{
37+
static::ensureKernelShutdown();
38+
}
39+
3540
/**
3641
* Finds the directory where the phpunit.xml(.dist) is stored.
3742
*

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Doctrine\Common\Annotations\AnnotationReader;
66
use Doctrine\Common\Annotations\CachedReader;
77
use Doctrine\Common\Annotations\Reader;
8+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
89
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
910
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1011
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -15,17 +16,19 @@
1516

1617
class AnnotationsCacheWarmerTest extends TestCase
1718
{
19+
use ForwardCompatTestTrait;
20+
1821
private $cacheDir;
1922

20-
protected function setUp()
23+
private function doSetUp()
2124
{
2225
$this->cacheDir = sys_get_temp_dir().'/'.uniqid();
2326
$fs = new Filesystem();
2427
$fs->mkdir($this->cacheDir);
2528
parent::setUp();
2629
}
2730

28-
protected function tearDown()
31+
private function doTearDown()
2932
{
3033
$fs = new Filesystem();
3134
$fs->remove($this->cacheDir);

Tests/CacheWarmer/TemplatePathsCacheWarmerTest.php

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

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
1516
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer;
1617
use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator;
@@ -21,6 +22,8 @@
2122

2223
class TemplatePathsCacheWarmerTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
/** @var Filesystem */
2528
private $filesystem;
2629

@@ -35,7 +38,7 @@ class TemplatePathsCacheWarmerTest extends TestCase
3538

3639
private $tmpDir;
3740

38-
protected function setUp()
41+
private function doSetUp()
3942
{
4043
$this->templateFinder = $this
4144
->getMockBuilder(TemplateFinderInterface::class)
@@ -56,7 +59,7 @@ protected function setUp()
5659
$this->filesystem->mkdir($this->tmpDir);
5760
}
5861

59-
protected function tearDown()
62+
private function doTearDown()
6063
{
6164
$this->filesystem->remove($this->tmpDir);
6265
}

Tests/Command/CacheClearCommand/CacheClearCommandTest.php

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

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Bundle\FrameworkBundle\Console\Application;
1516
use Symfony\Bundle\FrameworkBundle\Tests\Command\CacheClearCommand\Fixture\TestAppKernel;
1617
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@@ -23,13 +24,15 @@
2324

2425
class CacheClearCommandTest extends TestCase
2526
{
27+
use ForwardCompatTestTrait;
28+
2629
/** @var TestAppKernel */
2730
private $kernel;
2831
/** @var Filesystem */
2932
private $fs;
3033
private $rootDir;
3134

32-
protected function setUp()
35+
private function doSetUp()
3336
{
3437
$this->fs = new Filesystem();
3538
$this->kernel = new TestAppKernel('test', true);
@@ -38,7 +41,7 @@ protected function setUp()
3841
$this->fs->mkdir($this->rootDir);
3942
}
4043

41-
protected function tearDown()
44+
private function doTearDown()
4245
{
4346
$this->fs->remove($this->rootDir);
4447
}

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
1617
use Symfony\Bundle\FrameworkBundle\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
@@ -20,6 +21,8 @@
2021

2122
class TranslationDebugCommandTest extends TestCase
2223
{
24+
use ForwardCompatTestTrait;
25+
2326
private $fs;
2427
private $translationDir;
2528

@@ -109,7 +112,7 @@ public function testDebugInvalidDirectory()
109112
$tester->execute(['locale' => 'en', 'bundle' => 'dir']);
110113
}
111114

112-
protected function setUp()
115+
private function doSetUp()
113116
{
114117
$this->fs = new Filesystem();
115118
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
@@ -119,7 +122,7 @@ protected function setUp()
119122
$this->fs->mkdir($this->translationDir.'/templates');
120123
}
121124

122-
protected function tearDown()
125+
private function doTearDown()
123126
{
124127
$this->fs->remove($this->translationDir);
125128
}

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\Command\TranslationUpdateCommand;
1617
use Symfony\Bundle\FrameworkBundle\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
@@ -20,6 +21,8 @@
2021

2122
class TranslationUpdateCommandTest extends TestCase
2223
{
24+
use ForwardCompatTestTrait;
25+
2326
private $fs;
2427
private $translationDir;
2528

@@ -87,7 +90,7 @@ public function testWriteMessagesForSpecificDomain()
8790
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
8891
}
8992

90-
protected function setUp()
93+
private function doSetUp()
9194
{
9295
$this->fs = new Filesystem();
9396
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
@@ -97,7 +100,7 @@ protected function setUp()
97100
$this->fs->mkdir($this->translationDir.'/templates');
98101
}
99102

100-
protected function tearDown()
103+
private function doTearDown()
101104
{
102105
$this->fs->remove($this->translationDir);
103106
}

Tests/Command/YamlLintCommandTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\Command\YamlLintCommand;
1617
use Symfony\Bundle\FrameworkBundle\Console\Application;
1718
use Symfony\Component\Console\Application as BaseApplication;
@@ -28,6 +29,8 @@
2829
*/
2930
class YamlLintCommandTest extends TestCase
3031
{
32+
use ForwardCompatTestTrait;
33+
3134
private $files;
3235

3336
public function testLintCorrectFile()
@@ -183,13 +186,13 @@ private function getKernelAwareApplicationMock()
183186
return $application;
184187
}
185188

186-
protected function setUp()
189+
private function doSetUp()
187190
{
188191
@mkdir(sys_get_temp_dir().'/yml-lint-test');
189192
$this->files = [];
190193
}
191194

192-
protected function tearDown()
195+
private function doTearDown()
193196
{
194197
foreach ($this->files as $file) {
195198
if (file_exists($file)) {

Tests/Console/Descriptor/TextDescriptorTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\TextDescriptor;
1516

1617
class TextDescriptorTest extends AbstractDescriptorTest
1718
{
18-
protected function setUp()
19+
use ForwardCompatTestTrait;
20+
21+
private function doSetUp()
1922
{
2023
putenv('COLUMNS=121');
2124
}
2225

23-
protected function tearDown()
26+
private function doTearDown()
2427
{
2528
putenv('COLUMNS');
2629
}

Tests/Controller/ControllerNameParserTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
1313

1414
use Composer\Autoload\ClassLoader;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
1617
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1718
use Symfony\Component\HttpKernel\Kernel;
1819

1920
class ControllerNameParserTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
protected $loader;
2225

23-
protected function setUp()
26+
private function doSetUp()
2427
{
2528
$this->loader = new ClassLoader();
2629
$this->loader->add('TestBundle', __DIR__.'/../Fixtures');
2730
$this->loader->add('TestApplication', __DIR__.'/../Fixtures');
2831
$this->loader->register();
2932
}
3033

31-
protected function tearDown()
34+
private function doTearDown()
3235
{
3336
$this->loader->unregister();
3437
$this->loader = null;

0 commit comments

Comments
 (0)