Skip to content

Commit 47d1e4e

Browse files
Merge branch '3.2'
* 3.2: [FrameworkBundle] Fix cleaning of test dirs
2 parents e9a61a0 + 888aa4f commit 47d1e4e

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
@@ -22,14 +22,16 @@
2222
*/
2323
class AppKernel extends Kernel
2424
{
25+
private $varDir;
2526
private $testCase;
2627
private $rootConfig;
2728

28-
public function __construct($testCase, $rootConfig, $environment, $debug)
29+
public function __construct($varDir, $testCase, $rootConfig, $environment, $debug)
2930
{
3031
if (!is_dir(__DIR__.'/'.$testCase)) {
3132
throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
3233
}
34+
$this->varDir = $varDir;
3335
$this->testCase = $testCase;
3436

3537
$fs = new Filesystem();
@@ -57,12 +59,12 @@ public function getRootDir()
5759

5860
public function getCacheDir()
5961
{
60-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
62+
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
6163
}
6264

6365
public function getLogDir()
6466
{
65-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
67+
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs';
6668
}
6769

6870
public function registerContainerConfiguration(LoaderInterface $loader)
@@ -72,13 +74,13 @@ public function registerContainerConfiguration(LoaderInterface $loader)
7274

7375
public function serialize()
7476
{
75-
return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
77+
return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
7678
}
7779

7880
public function unserialize($str)
7981
{
8082
$a = unserialize($str);
81-
$this->__construct($a[0], $a[1], $a[2], $a[3]);
83+
$this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]);
8284
}
8385

8486
protected function getKernelParameters()

0 commit comments

Comments
 (0)