Skip to content

Commit bbc53dd

Browse files
committed
minor symfony#16999 [SecurityBundle] Removing test insulations for a huge perf win (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [SecurityBundle] Removing test insulations for a huge perf win | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- b8fa471 [SecurityBundle] Removing test insulations for a huge perf win
2 parents 36a5141 + b8fa471 commit bbc53dd

File tree

9 files changed

+37
-67
lines changed

9 files changed

+37
-67
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class AuthenticationCommencingTest extends WebTestCase
1616
public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
1717
{
1818
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'config.yml'));
19-
$client->insulate();
2019

2120
$client->request('GET', '/secure-but-not-covered-by-access-control');
2221
$this->assertRedirect($client->getResponse(), '/login');

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class CsrfFormLoginTest extends WebTestCase
1919
public function testFormLoginAndLogoutWithCsrfTokens($config)
2020
{
2121
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
22-
$client->insulate();
2322

2423
$form = $client->request('GET', '/login')->selectButton('login')->form();
2524
$form['user_login[username]'] = 'johannes';
@@ -50,7 +49,6 @@ public function testFormLoginAndLogoutWithCsrfTokens($config)
5049
public function testFormLoginWithInvalidCsrfToken($config)
5150
{
5251
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
53-
$client->insulate();
5452

5553
$form = $client->request('GET', '/login')->selectButton('login')->form();
5654
$form['user_login[_token]'] = '';
@@ -68,7 +66,6 @@ public function testFormLoginWithInvalidCsrfToken($config)
6866
public function testFormLoginWithCustomTargetPath($config)
6967
{
7068
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
71-
$client->insulate();
7269

7370
$form = $client->request('GET', '/login')->selectButton('login')->form();
7471
$form['user_login[username]'] = 'johannes';
@@ -89,7 +86,6 @@ public function testFormLoginWithCustomTargetPath($config)
8986
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
9087
{
9188
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
92-
$client->insulate();
9389

9490
$client->request('GET', '/protected-resource');
9591
$this->assertRedirect($client->getResponse(), '/login');
@@ -113,17 +109,13 @@ public function getConfigs()
113109
);
114110
}
115111

116-
protected function setUp()
112+
public static function setUpBeforeClass()
117113
{
118-
parent::setUp();
119-
120-
$this->deleteTmpDir('CsrfFormLogin');
114+
parent::deleteTmpDir('CsrfFormLogin');
121115
}
122116

123-
protected function tearDown()
117+
public static function tearDownAfterClass()
124118
{
125-
parent::tearDown();
126-
127-
$this->deleteTmpDir('CsrfFormLogin');
119+
parent::deleteTmpDir('CsrfFormLogin');
128120
}
129121
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class FirewallEntryPointTest extends WebTestCase
1818
public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials()
1919
{
2020
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint'));
21-
$client->insulate();
2221

2322
$client->request('GET', '/secure/resource', array(), array(), array(
2423
'PHP_AUTH_USER' => 'unknown',
@@ -35,7 +34,6 @@ public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials()
3534
public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFormLoginAndNoCredentials()
3635
{
3736
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint', 'root_config' => 'config_form_login.yml'));
38-
$client->insulate();
3937

4038
$client->request('GET', '/secure/resource');
4139

@@ -46,17 +44,13 @@ public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFor
4644
);
4745
}
4846

49-
protected function setUp()
47+
public static function setUpBeforeClass()
5048
{
51-
parent::setUp();
52-
53-
$this->deleteTmpDir('FirewallEntryPoint');
49+
parent::deleteTmpDir('FirewallEntryPoint');
5450
}
5551

56-
protected function tearDown()
52+
public static function tearDownAfterClass()
5753
{
58-
parent::tearDown();
59-
60-
$this->deleteTmpDir('FirewallEntryPoint');
54+
parent::deleteTmpDir('FirewallEntryPoint');
6155
}
6256
}

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class FormLoginTest extends WebTestCase
1919
public function testFormLogin($config)
2020
{
2121
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
22-
$client->insulate();
2322

2423
$form = $client->request('GET', '/login')->selectButton('login')->form();
2524
$form['_username'] = 'johannes';
@@ -39,7 +38,6 @@ public function testFormLogin($config)
3938
public function testFormLoginWithCustomTargetPath($config)
4039
{
4140
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
42-
$client->insulate();
4341

4442
$form = $client->request('GET', '/login')->selectButton('login')->form();
4543
$form['_username'] = 'johannes';
@@ -60,7 +58,6 @@ public function testFormLoginWithCustomTargetPath($config)
6058
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
6159
{
6260
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
63-
$client->insulate();
6461

6562
$client->request('GET', '/protected_resource');
6663
$this->assertRedirect($client->getResponse(), '/login');
@@ -84,17 +81,13 @@ public function getConfigs()
8481
);
8582
}
8683

87-
protected function setUp()
84+
public static function setUpBeforeClass()
8885
{
89-
parent::setUp();
90-
91-
$this->deleteTmpDir('StandardFormLogin');
86+
parent::deleteTmpDir('StandardFormLogin');
9287
}
9388

94-
protected function tearDown()
89+
public static function tearDownAfterClass()
9590
{
96-
parent::tearDown();
97-
98-
$this->deleteTmpDir('StandardFormLogin');
91+
parent::deleteTmpDir('StandardFormLogin');
9992
}
10093
}

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
1919
public function testLoginLogoutProcedure($locale)
2020
{
2121
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
22-
$client->insulate();
2322

2423
$crawler = $client->request('GET', '/'.$locale.'/login');
2524
$form = $crawler->selectButton('login')->form();
@@ -41,7 +40,6 @@ public function testLoginLogoutProcedure($locale)
4140
public function testLoginFailureWithLocalizedFailurePath($locale)
4241
{
4342
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_form_failure_handler.yml'));
44-
$client->insulate();
4543

4644
$crawler = $client->request('GET', '/'.$locale.'/login');
4745
$form = $crawler->selectButton('login')->form();
@@ -58,7 +56,6 @@ public function testLoginFailureWithLocalizedFailurePath($locale)
5856
public function testAccessRestrictedResource($locale)
5957
{
6058
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
61-
$client->insulate();
6259

6360
$client->request('GET', '/'.$locale.'/secure/');
6461
$this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
@@ -70,7 +67,6 @@ public function testAccessRestrictedResource($locale)
7067
public function testAccessRestrictedResourceWithForward($locale)
7168
{
7269
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes_with_forward.yml'));
73-
$client->insulate();
7470

7571
$crawler = $client->request('GET', '/'.$locale.'/secure/');
7672
$this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse());
@@ -81,17 +77,13 @@ public function getLocales()
8177
return array(array('en'), array('de'));
8278
}
8379

84-
protected function setUp()
80+
public static function setUpBeforeClass()
8581
{
86-
parent::setUp();
87-
88-
$this->deleteTmpDir('StandardFormLogin');
82+
parent::deleteTmpDir('StandardFormLogin');
8983
}
9084

91-
protected function tearDown()
85+
public static function tearDownAfterClass()
9286
{
93-
parent::tearDown();
94-
95-
$this->deleteTmpDir('StandardFormLogin');
87+
parent::deleteTmpDir('StandardFormLogin');
9688
}
9789
}

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
1919
public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($config)
2020
{
2121
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
22-
$client->insulate();
2322
$client->request('GET', '/protected_resource');
2423

2524
$this->assertRedirect($client->getResponse(), '/login');
@@ -35,7 +34,6 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
3534
}
3635

3736
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
38-
$client->insulate();
3937
$client->request('GET', '/unprotected_resource');
4038

4139
$this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse());
@@ -51,7 +49,6 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWith
5149
}
5250

5351
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
54-
$client->insulate();
5552

5653
$form = $client->request('GET', '/login')->selectButton('login')->form();
5754
$form['_username'] = 'johannes';
@@ -106,17 +103,13 @@ public function getConfigs()
106103
return array(array('config.yml'), array('routes_as_path.yml'));
107104
}
108105

109-
protected function setUp()
106+
public static function setUpBeforeClass()
110107
{
111-
parent::setUp();
112-
113-
$this->deleteTmpDir('StandardFormLogin');
108+
parent::deleteTmpDir('StandardFormLogin');
114109
}
115110

116-
protected function tearDown()
111+
public static function tearDownAfterClass()
117112
{
118-
parent::tearDown();
119-
120-
$this->deleteTmpDir('StandardFormLogin');
113+
parent::deleteTmpDir('StandardFormLogin');
121114
}
122115
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ protected function createAuthenticatedClient($username)
6262
{
6363
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'switchuser.yml'));
6464
$client->followRedirects(true);
65-
$client->insulate();
6665

6766
$form = $client->request('GET', '/login')->selectButton('login')->form();
6867
$form['_username'] = $username;
@@ -72,17 +71,13 @@ protected function createAuthenticatedClient($username)
7271
return $client;
7372
}
7473

75-
protected function setUp()
74+
public static function setUpBeforeClass()
7675
{
77-
parent::setUp();
78-
79-
$this->deleteTmpDir('StandardFormLogin');
76+
parent::deleteTmpDir('StandardFormLogin');
8077
}
8178

82-
protected function tearDown()
79+
public static function tearDownAfterClass()
8380
{
84-
parent::tearDown();
85-
86-
$this->deleteTmpDir('StandardFormLogin');
81+
parent::deleteTmpDir('StandardFormLogin');
8782
}
8883
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function assertRedirect($response, $location)
2323
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
2424
}
2525

26-
protected function deleteTmpDir($testCase)
26+
protected static function deleteTmpDir($testCase)
2727
{
2828
if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) {
2929
return;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public function __construct($testCase, $rootConfig, $environment, $debug)
6565
parent::__construct($environment, $debug);
6666
}
6767

68+
/**
69+
* {@inheritdoc}
70+
*/
71+
public function getName()
72+
{
73+
if (null === $this->name) {
74+
$this->name = parent::getName().md5($this->rootConfig);
75+
}
76+
77+
return $this->name;
78+
}
79+
6880
public function registerBundles()
6981
{
7082
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {

0 commit comments

Comments
 (0)