Skip to content

Commit 888aa4f

Browse files
Merge branch '2.8' into 3.2
* 2.8: [FrameworkBundle] Fix cleaning of test dirs
2 parents b5ea84b + 64c5a78 commit 888aa4f

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

Tests/Functional/SessionTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,4 @@ public function getConfigs()
134134
array('config.yml', false),
135135
);
136136
}
137-
138-
protected function setUp()
139-
{
140-
parent::setUp();
141-
142-
$this->deleteTmpDir('SessionTest');
143-
}
144-
145-
protected function tearDown()
146-
{
147-
parent::tearDown();
148-
149-
$this->deleteTmpDir('SessionTest');
150-
}
151137
}

Tests/Functional/WebTestCase.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
1515
use Symfony\Component\Filesystem\Filesystem;
16-
use Symfony\Component\HttpKernel\Kernel;
1716

1817
class WebTestCase extends BaseWebTestCase
1918
{
@@ -23,9 +22,19 @@ public static function assertRedirect($response, $location)
2322
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
2423
}
2524

26-
protected function deleteTmpDir($testCase)
25+
public static function setUpBeforeClass()
2726
{
28-
if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) {
27+
static::deleteTmpDir();
28+
}
29+
30+
public static function tearDownAfterClass()
31+
{
32+
static::deleteTmpDir();
33+
}
34+
35+
protected static function deleteTmpDir()
36+
{
37+
if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) {
2938
return;
3039
}
3140

@@ -49,10 +58,16 @@ protected static function createKernel(array $options = array())
4958
}
5059

5160
return new $class(
61+
static::getVarDir(),
5262
$options['test_case'],
5363
isset($options['root_config']) ? $options['root_config'] : 'config.yml',
54-
isset($options['environment']) ? $options['environment'] : 'frameworkbundletest'.strtolower($options['test_case']),
64+
isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']),
5565
isset($options['debug']) ? $options['debug'] : true
5666
);
5767
}
68+
69+
protected static function getVarDir()
70+
{
71+
return substr(strrchr(get_called_class(), '\\'), 1);
72+
}
5873
}

Tests/Functional/app/AppKernel.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@
4646
*/
4747
class AppKernel extends Kernel
4848
{
49+
private $varDir;
4950
private $testCase;
5051
private $rootConfig;
5152

52-
public function __construct($testCase, $rootConfig, $environment, $debug)
53+
public function __construct($varDir, $testCase, $rootConfig, $environment, $debug)
5354
{
5455
if (!is_dir(__DIR__.'/'.$testCase)) {
5556
throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
5657
}
58+
$this->varDir = $varDir;
5759
$this->testCase = $testCase;
5860

5961
$fs = new Filesystem();
@@ -81,12 +83,12 @@ public function getRootDir()
8183

8284
public function getCacheDir()
8385
{
84-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
86+
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
8587
}
8688

8789
public function getLogDir()
8890
{
89-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
91+
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs';
9092
}
9193

9294
public function registerContainerConfiguration(LoaderInterface $loader)
@@ -96,13 +98,13 @@ public function registerContainerConfiguration(LoaderInterface $loader)
9698

9799
public function serialize()
98100
{
99-
return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
101+
return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
100102
}
101103

102104
public function unserialize($str)
103105
{
104106
$a = unserialize($str);
105-
$this->__construct($a[0], $a[1], $a[2], $a[3]);
107+
$this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]);
106108
}
107109

108110
protected function getKernelParameters()

0 commit comments

Comments
 (0)