Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b4cfd6

Browse files
Merge branch '2.7' into 2.8
* 2.7: [FrameworkBundle] Fix cleaning of test dirs
2 parents 9fb17b4 + ac89b1c commit 6b4cfd6

12 files changed

+53
-107
lines changed

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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()

src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,4 @@ public function getConfigs()
108108
array('routes_as_path.yml'),
109109
);
110110
}
111-
112-
public static function setUpBeforeClass()
113-
{
114-
parent::deleteTmpDir('CsrfFormLogin');
115-
}
116-
117-
public static function tearDownAfterClass()
118-
{
119-
parent::deleteTmpDir('CsrfFormLogin');
120-
}
121111
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,4 @@ public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFor
4343
"Custom entry point wasn't started"
4444
);
4545
}
46-
47-
public static function setUpBeforeClass()
48-
{
49-
parent::deleteTmpDir('FirewallEntryPoint');
50-
}
51-
52-
public static function tearDownAfterClass()
53-
{
54-
parent::deleteTmpDir('FirewallEntryPoint');
55-
}
5646
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,4 @@ public function getConfigs()
113113
array('routes_as_path.yml'),
114114
);
115115
}
116-
117-
public static function setUpBeforeClass()
118-
{
119-
parent::deleteTmpDir('StandardFormLogin');
120-
}
121-
122-
public static function tearDownAfterClass()
123-
{
124-
parent::deleteTmpDir('StandardFormLogin');
125-
}
126116
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,4 @@ public function getLocales()
7676
{
7777
return array(array('en'), array('de'));
7878
}
79-
80-
public static function setUpBeforeClass()
81-
{
82-
parent::deleteTmpDir('StandardFormLogin');
83-
}
84-
85-
public static function tearDownAfterClass()
86-
{
87-
parent::deleteTmpDir('StandardFormLogin');
88-
}
8979
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,4 @@ public function getConfigs()
116116
{
117117
return array(array('config.yml'), array('routes_as_path.yml'));
118118
}
119-
120-
public static function setUpBeforeClass()
121-
{
122-
parent::deleteTmpDir('StandardFormLogin');
123-
}
124-
125-
public static function tearDownAfterClass()
126-
{
127-
parent::deleteTmpDir('StandardFormLogin');
128-
}
129119
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ class SetAclCommandTest extends WebTestCase
4040
const OBJECT_CLASS = 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AclBundle\Entity\Car';
4141
const SECURITY_CLASS = 'Symfony\Component\Security\Core\User\User';
4242

43-
protected function setUp()
44-
{
45-
parent::setUp();
46-
47-
$this->deleteTmpDir('Acl');
48-
}
49-
50-
protected function tearDown()
51-
{
52-
parent::tearDown();
53-
54-
$this->deleteTmpDir('Acl');
55-
}
56-
5743
public function testSetAclUser()
5844
{
5945
$objectId = 1;

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,4 @@ protected function createAuthenticatedClient($username)
7070

7171
return $client;
7272
}
73-
74-
public static function setUpBeforeClass()
75-
{
76-
parent::deleteTmpDir('StandardFormLogin');
77-
}
78-
79-
public static function tearDownAfterClass()
80-
{
81-
parent::deleteTmpDir('StandardFormLogin');
82-
}
8373
}

src/Symfony/Bundle/SecurityBundle/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 static function deleteTmpDir($testCase)
25+
public static function setUpBeforeClass()
2726
{
28-
if (defined('HHVM_VERSION_ID') || !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'] : 'securitybundletest'.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
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php

Lines changed: 8 additions & 6 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();
@@ -71,7 +73,7 @@ public function __construct($testCase, $rootConfig, $environment, $debug)
7173
public function getName()
7274
{
7375
if (null === $this->name) {
74-
$this->name = parent::getName().md5($this->rootConfig);
76+
$this->name = parent::getName().substr(md5($this->rootConfig), -16);
7577
}
7678

7779
return $this->name;
@@ -93,12 +95,12 @@ public function getRootDir()
9395

9496
public function getCacheDir()
9597
{
96-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
98+
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
9799
}
98100

99101
public function getLogDir()
100102
{
101-
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
103+
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs';
102104
}
103105

104106
public function registerContainerConfiguration(LoaderInterface $loader)
@@ -108,13 +110,13 @@ public function registerContainerConfiguration(LoaderInterface $loader)
108110

109111
public function serialize()
110112
{
111-
return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
113+
return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
112114
}
113115

114116
public function unserialize($str)
115117
{
116118
$a = unserialize($str);
117-
$this->__construct($a[0], $a[1], $a[2], $a[3]);
119+
$this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]);
118120
}
119121

120122
protected function getKernelParameters()

0 commit comments

Comments
 (0)