bug #17183 [FrameworkBundle] Set the kernel.name properly after a cache warmup (jakzal)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #17183).

Discussion
----------

[FrameworkBundle] Set the kernel.name properly after a cache warmup

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16180
| License       | MIT
| Doc PR        | -

Commits
-------

1438b9a [FrameworkBundle] Set the kernel.name properly after a cache warmup
This commit is contained in:
Fabien Potencier 2016-01-04 18:15:55 +01:00
commit 19a63356ef
2 changed files with 13 additions and 3 deletions

View File

@ -144,9 +144,18 @@ EOF
}
// fix references to kernel/container related classes
$search = $tempKernel->getName().ucfirst($tempKernel->getEnvironment());
$replace = $realKernel->getName().ucfirst($realKernel->getEnvironment());
foreach (Finder::create()->files()->name($search.'*')->in($warmupDir) as $file) {
$fileSearch = $tempKernel->getName().ucfirst($tempKernel->getEnvironment()).'*';
$search = array(
$tempKernel->getName().ucfirst($tempKernel->getEnvironment()),
sprintf('\'kernel.name\' => \'%s\'', $tempKernel->getName()),
sprintf('key="kernel.name">%s<', $tempKernel->getName()),
);
$replace = array(
$realKernel->getName().ucfirst($realKernel->getEnvironment()),
sprintf('\'kernel.name\' => \'%s\'', $realKernel->getName()),
sprintf('key="kernel.name">%s<', $realKernel->getName()),
);
foreach (Finder::create()->files()->name($fileSearch)->in($warmupDir) as $file) {
$content = str_replace($search, $replace, file_get_contents($file));
file_put_contents(str_replace($search, $replace, $file), $content);
unlink($file);

View File

@ -83,5 +83,6 @@ class CacheClearCommandTest extends TestCase
}
}
$this->assertTrue($found, 'Kernel file should present as resource');
$this->assertRegExp(sprintf('/\'kernel.name\'\s*=>\s*\'%s\'/', $this->kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container');
}
}