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

Skip to content

Commit 80086ad

Browse files
committed
minor #17399 [FrameworkBundle] Optimize framework extension tests (paradajozsef)
This PR was squashed before being merged into the 2.3 branch (closes #17399). Discussion ---------- [FrameworkBundle] Optimize framework extension tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17366 | License | MIT | Doc PR | - ```XmlFrameworkExtensionTest```, ```YamlFrameworkExtensionTest``` and ```PhpFrameworkExtensionTest``` are slow tests. The reason is that the [parent test](https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php#L308) creates the container in every test case. With different parameters, but the same is created several times. (actually with 'full' parameter it is created 12 times in 2.3) If we cache the different containers during test, we avoid to creating the same container multiple times. As I experienced it can be merged without a conflict into 2.3 and 2.7, but 2.8 and 3.0 conflicts. I have these result on my local setup. Not that big optimalization, but a few second can matter too imo. :) **2.3 before** ```go Time: 8.79 seconds, Memory: 55.75Mb OK (449 tests, 586 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` **2.3 after** ```go Time: 5.85 seconds, Memory: 58.25Mb OK (449 tests, 586 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` ---- **2.7 before** ```go Time: 17.17 seconds, Memory: 81.50Mb OK, but incomplete, skipped, or risky tests! Tests: 753, Assertions: 1098, Skipped: 3. Legacy deprecation notices (45) OK src/Symfony/Bundle/FrameworkBundle ``` **2.7 after** ```go Time: 12.65 seconds, Memory: 88.00Mb OK, but incomplete, skipped, or risky tests! Tests: 753, Assertions: 1098, Skipped: 3. Legacy deprecation notices (41) OK src/Symfony/Bundle/FrameworkBundle ``` ---- **2.8 before** ```go Time: 18.94 seconds, Memory: 88.00Mb OK, but incomplete, skipped, or risky tests! Tests: 787, Assertions: 1159, Skipped: 3. Legacy deprecation notices (89) OK src/Symfony/Bundle/FrameworkBundle ``` **2.8 after** ```go Time: 12.69 seconds, Memory: 94.50Mb OK, but incomplete, skipped, or risky tests! Tests: 787, Assertions: 1159, Skipped: 3. Legacy deprecation notices (85) OK src/Symfony/Bundle/FrameworkBundle ``` ---- **3.0 before** ```go Time: 16.48 seconds, Memory: 73.75Mb OK (741 tests, 1043 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` **3.0 after** ```go Time: 11.49 seconds, Memory: 76.75Mb OK (741 tests, 1043 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` Commits ------- f6a078b [FrameworkBundle] Optimize framework extension tests
2 parents 5c034ad + f6a078b commit 80086ad

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
abstract class FrameworkExtensionTest extends TestCase
2020
{
21+
private static $containerCache = array();
22+
2123
abstract protected function loadFromFile(ContainerBuilder $container, $file);
2224

2325
public function testCsrfProtection()
@@ -307,6 +309,10 @@ protected function createContainer(array $data = array())
307309

308310
protected function createContainerFromFile($file, $data = array())
309311
{
312+
$cacheKey = md5($file.serialize($data));
313+
if (isset(self::$containerCache[$cacheKey])) {
314+
return self::$containerCache[$cacheKey];
315+
}
310316
$container = $this->createContainer($data);
311317
$container->registerExtension(new FrameworkExtension());
312318
$this->loadFromFile($container, $file);
@@ -315,6 +321,6 @@ protected function createContainerFromFile($file, $data = array())
315321
$container->getCompilerPassConfig()->setRemovingPasses(array());
316322
$container->compile();
317323

318-
return $container;
324+
return self::$containerCache[$cacheKey] = $container;
319325
}
320326
}

0 commit comments

Comments
 (0)