Skip to content

Commit b550d7e

Browse files
minor symfony#20587 [SecurityBundle] Fix complete config tests (julienfalque)
This PR was merged into the 2.7 branch. Discussion ---------- [SecurityBundle] Fix complete config tests | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Fixes a little bug in `*CompleteConfigurationTest`: if a test fails for one format, subsequent tests for other formats will also fail. This is because subsequent tests actually use the container built from the very first tested config, which is PHP if all tests are ran. This can be reproduced by changing a value in the PHP config fixtures. `PhpCompleteConfigurationTest` will fail as expected but `XmlCompleteConfigurationTest` and `YamlCompleteConfigurationTest` will fail too, which is not expected. Commits ------- b25c1d3 Fix complete config tests
2 parents b0fd453 + b25c1d3 commit b550d7e

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
2121
{
2222
private static $containerCache = array();
2323

24-
abstract protected function loadFromFile(ContainerBuilder $container, $file);
24+
abstract protected function getLoader(ContainerBuilder $container);
25+
26+
abstract protected function getFileExtension();
2527

2628
public function testRolesHierarchy()
2729
{
@@ -237,6 +239,8 @@ public function testRememberMeThrowExceptions()
237239

238240
protected function getContainer($file)
239241
{
242+
$file = $file.'.'.$this->getFileExtension();
243+
240244
if (isset(self::$containerCache[$file])) {
241245
return self::$containerCache[$file];
242246
}
@@ -246,7 +250,7 @@ protected function getContainer($file)
246250

247251
$bundle = new SecurityBundle();
248252
$bundle->build($container); // Attach all default factories
249-
$this->loadFromFile($container, $file);
253+
$this->getLoader($container)->load($file);
250254

251255
$container->getCompilerPassConfig()->setOptimizationPasses(array());
252256
$container->getCompilerPassConfig()->setRemovingPasses(array());

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpCompleteConfigurationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
class PhpCompleteConfigurationTest extends CompleteConfigurationTest
1919
{
20-
protected function loadFromFile(ContainerBuilder $container, $file)
20+
protected function getLoader(ContainerBuilder $container)
2121
{
22-
$loadXml = new PhpFileLoader($container, new FileLocator(__DIR__.'/Fixtures/php'));
23-
$loadXml->load($file.'.php');
22+
return new PhpFileLoader($container, new FileLocator(__DIR__.'/Fixtures/php'));
23+
}
24+
25+
protected function getFileExtension()
26+
{
27+
return 'php';
2428
}
2529
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
class XmlCompleteConfigurationTest extends CompleteConfigurationTest
1919
{
20-
protected function loadFromFile(ContainerBuilder $container, $file)
20+
protected function getLoader(ContainerBuilder $container)
2121
{
22-
$loadXml = new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml'));
23-
$loadXml->load($file.'.xml');
22+
return new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml'));
23+
}
24+
25+
protected function getFileExtension()
26+
{
27+
return 'xml';
2428
}
2529
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlCompleteConfigurationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
class YamlCompleteConfigurationTest extends CompleteConfigurationTest
1919
{
20-
protected function loadFromFile(ContainerBuilder $container, $file)
20+
protected function getLoader(ContainerBuilder $container)
2121
{
22-
$loadXml = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/yml'));
23-
$loadXml->load($file.'.yml');
22+
return new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/yml'));
23+
}
24+
25+
protected function getFileExtension()
26+
{
27+
return 'yml';
2428
}
2529
}

0 commit comments

Comments
 (0)