minor #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
This commit is contained in:
Fabien Potencier 2015-12-21 19:31:12 +01:00
commit bbc53dd83f
9 changed files with 37 additions and 67 deletions

View File

@ -16,7 +16,6 @@ class AuthenticationCommencingTest extends WebTestCase
public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'config.yml'));
$client->insulate();
$client->request('GET', '/secure-but-not-covered-by-access-control');
$this->assertRedirect($client->getResponse(), '/login');

View File

@ -19,7 +19,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginAndLogoutWithCsrfTokens($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['user_login[username]'] = 'johannes';
@ -50,7 +49,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginWithInvalidCsrfToken($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['user_login[_token]'] = '';
@ -68,7 +66,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginWithCustomTargetPath($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['user_login[username]'] = 'johannes';
@ -89,7 +86,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/protected-resource');
$this->assertRedirect($client->getResponse(), '/login');
@ -113,17 +109,13 @@ class CsrfFormLoginTest extends WebTestCase
);
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('CsrfFormLogin');
parent::deleteTmpDir('CsrfFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('CsrfFormLogin');
parent::deleteTmpDir('CsrfFormLogin');
}
}

View File

@ -18,7 +18,6 @@ class FirewallEntryPointTest extends WebTestCase
public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials()
{
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint'));
$client->insulate();
$client->request('GET', '/secure/resource', array(), array(), array(
'PHP_AUTH_USER' => 'unknown',
@ -35,7 +34,6 @@ class FirewallEntryPointTest extends WebTestCase
public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFormLoginAndNoCredentials()
{
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint', 'root_config' => 'config_form_login.yml'));
$client->insulate();
$client->request('GET', '/secure/resource');
@ -46,17 +44,13 @@ class FirewallEntryPointTest extends WebTestCase
);
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('FirewallEntryPoint');
parent::deleteTmpDir('FirewallEntryPoint');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('FirewallEntryPoint');
parent::deleteTmpDir('FirewallEntryPoint');
}
}

View File

@ -19,7 +19,6 @@ class FormLoginTest extends WebTestCase
public function testFormLogin($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -39,7 +38,6 @@ class FormLoginTest extends WebTestCase
public function testFormLoginWithCustomTargetPath($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -60,7 +58,6 @@ class FormLoginTest extends WebTestCase
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/protected_resource');
$this->assertRedirect($client->getResponse(), '/login');
@ -84,17 +81,13 @@ class FormLoginTest extends WebTestCase
);
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -19,7 +19,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testLoginLogoutProcedure($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
$client->insulate();
$crawler = $client->request('GET', '/'.$locale.'/login');
$form = $crawler->selectButton('login')->form();
@ -41,7 +40,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testLoginFailureWithLocalizedFailurePath($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_form_failure_handler.yml'));
$client->insulate();
$crawler = $client->request('GET', '/'.$locale.'/login');
$form = $crawler->selectButton('login')->form();
@ -58,7 +56,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testAccessRestrictedResource($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
$client->insulate();
$client->request('GET', '/'.$locale.'/secure/');
$this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
@ -70,7 +67,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testAccessRestrictedResourceWithForward($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes_with_forward.yml'));
$client->insulate();
$crawler = $client->request('GET', '/'.$locale.'/secure/');
$this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse());
@ -81,17 +77,13 @@ class LocalizedRoutesAsPathTest extends WebTestCase
return array(array('en'), array('de'));
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -19,7 +19,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/protected_resource');
$this->assertRedirect($client->getResponse(), '/login');
@ -35,7 +34,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
}
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/unprotected_resource');
$this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse());
@ -51,7 +49,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
}
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -106,17 +103,13 @@ class SecurityRoutingIntegrationTest extends WebTestCase
return array(array('config.yml'), array('routes_as_path.yml'));
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -62,7 +62,6 @@ class SwitchUserTest extends WebTestCase
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'switchuser.yml'));
$client->followRedirects(true);
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = $username;
@ -72,17 +71,13 @@ class SwitchUserTest extends WebTestCase
return $client;
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -23,7 +23,7 @@ class WebTestCase extends BaseWebTestCase
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
}
protected function deleteTmpDir($testCase)
protected static function deleteTmpDir($testCase)
{
if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) {
return;

View File

@ -65,6 +65,18 @@ class AppKernel extends Kernel
parent::__construct($environment, $debug);
}
/**
* {@inheritdoc}
*/
public function getName()
{
if (null === $this->name) {
$this->name = parent::getName().md5($this->rootConfig);
}
return $this->name;
}
public function registerBundles()
{
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {