Skip to content

Commit 0519351

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Cache] fix cs Make tests support phpunit 8 Allow Travis CI to build on PHP 7.4
2 parents 61c1bdc + 29ac3ad commit 0519351

27 files changed

+196
-41
lines changed

Test/ForwardCompatTestTrait.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\Bundle\FrameworkBundle\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\Bundle\FrameworkBundle\Test;
21+
22+
/**
23+
* @internal
24+
*/
25+
trait ForwardCompatTestTrait
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 ForwardCompatTestTrait
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+
}

Test/KernelTestCase.php

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

2828
protected static $class;
2929

@@ -39,7 +39,7 @@ abstract class KernelTestCase extends TestCase
3939

4040
protected static $booted;
4141

42-
protected function doTearDown(): void
42+
private function doTearDown()
4343
{
4444
static::ensureKernelShutdown();
4545
}

Test/WebTestCase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
*/
2222
abstract class WebTestCase extends KernelTestCase
2323
{
24+
use ForwardCompatTestTrait;
2425
use WebTestAssertionsTrait;
2526

26-
protected function doTearDown(): void
27+
private function doTearDown()
2728
{
28-
parent::doTearDown();
29+
parent::tearDown();
2930
self::getClient(null);
3031
}
3132

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\NullAdapter;
@@ -14,17 +15,19 @@
1415

1516
class AnnotationsCacheWarmerTest extends TestCase
1617
{
18+
use ForwardCompatTestTrait;
19+
1720
private $cacheDir;
1821

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

27-
protected function tearDown()
30+
private function doTearDown()
2831
{
2932
$fs = new Filesystem();
3033
$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;
@@ -24,6 +25,8 @@
2425
*/
2526
class TemplatePathsCacheWarmerTest extends TestCase
2627
{
28+
use ForwardCompatTestTrait;
29+
2730
/** @var Filesystem */
2831
private $filesystem;
2932

@@ -38,7 +41,7 @@ class TemplatePathsCacheWarmerTest extends TestCase
3841

3942
private $tmpDir;
4043

41-
protected function setUp()
44+
private function doSetUp()
4245
{
4346
$this->templateFinder = $this
4447
->getMockBuilder(TemplateFinderInterface::class)
@@ -59,7 +62,7 @@ protected function setUp()
5962
$this->filesystem->mkdir($this->tmpDir);
6063
}
6164

62-
protected function tearDown()
65+
private function doTearDown()
6366
{
6467
$this->filesystem->remove($this->tmpDir);
6568
}

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,19 +24,21 @@
2324

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

31-
protected function setUp()
34+
private function doSetUp()
3235
{
3336
$this->fs = new Filesystem();
3437
$this->kernel = new TestAppKernel('test', true);
3538
$this->fs->mkdir($this->kernel->getProjectDir());
3639
}
3740

38-
protected function tearDown()
41+
private function doTearDown()
3942
{
4043
$this->fs->remove($this->kernel->getProjectDir());
4144
}

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;
@@ -21,6 +22,8 @@
2122

2223
class TranslationDebugCommandTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
private $fs;
2528
private $translationDir;
2629

@@ -129,15 +132,15 @@ public function testDebugInvalidDirectory()
129132
$tester->execute(['locale' => 'en', 'bundle' => 'dir']);
130133
}
131134

132-
protected function setUp()
135+
private function doSetUp()
133136
{
134137
$this->fs = new Filesystem();
135138
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
136139
$this->fs->mkdir($this->translationDir.'/translations');
137140
$this->fs->mkdir($this->translationDir.'/templates');
138141
}
139142

140-
protected function tearDown()
143+
private function doTearDown()
141144
{
142145
$this->fs->remove($this->translationDir);
143146
}

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;
@@ -21,6 +22,8 @@
2122

2223
class TranslationUpdateCommandTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
private $fs;
2528
private $translationDir;
2629

@@ -105,15 +108,15 @@ public function testWriteMessagesForSpecificDomain()
105108
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
106109
}
107110

108-
protected function setUp()
111+
private function doSetUp()
109112
{
110113
$this->fs = new Filesystem();
111114
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
112115
$this->fs->mkdir($this->translationDir.'/translations');
113116
$this->fs->mkdir($this->translationDir.'/templates');
114117
}
115118

116-
protected function tearDown()
119+
private function doTearDown()
117120
{
118121
$this->fs->remove($this->translationDir);
119122
}

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
}

0 commit comments

Comments
 (0)