From ccacd8d2af428de1cf3df3e25757d4e4a20ab5e1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 26 May 2014 18:12:56 +0200 Subject: [PATCH] [HttpKernel] simplified some tests --- .../Component/HttpKernel/Tests/KernelTest.php | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index d2a22c6ae4..82a7561377 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -824,48 +824,37 @@ EOF; $kernel->terminate(Request::create('/'), new Response()); } - public function testRemoveAbsolutePathsFromContainer() + /** + * @dataProvider getRemoveAbsolutePathsFromContainerData + */ + public function testRemoveAbsolutePathsFromContainer($symfonyRootDir, $realRootDir, $replacement, $replaced) { $kernel = new KernelForTest('dev', true); - $kernel->setRootDir($symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app'); - - $content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php'); - $content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content); - - $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); - $m->setAccessible(true); - $content = $m->invoke($kernel, $content); - $this->assertEquals(file_get_contents($symfonyRootDir.'/cache/dev/withoutAbsolutePaths.php'), $content); - } - - public function testRemoveAbsolutePathsFromContainerGiveUpWhenComposerJsonPathNotGuessable() - { - $kernel = new KernelForTest('dev', true); - $kernel->setRootDir($symfonyRootDir = sys_get_temp_dir()); + $kernel->setRootDir($symfonyRootDir); + if (null !== $realRootDir) { + $kernel->setRealRootDir($realRootDir); + } $content = file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php'); - $content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content); + $content = str_replace('ROOT_DIR', $replacement, $content); $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); $m->setAccessible(true); $newContent = $m->invoke($kernel, $content); - $this->assertEquals($newContent, $content); + if ($replaced) { + $this->assertEquals(file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php'), $newContent); + } else { + $this->assertEquals($newContent, $content); + } } - public function testRemoveAbsolutePathsFromContainerWithSpecialCase() + public function getRemoveAbsolutePathsFromContainerData() { - $kernel = new KernelForTest('dev', true); - $kernel->setRootDir('/app/app'); - $kernel->setRealRootDir('/app'); - $symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app'; - - $content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php'); - $content = str_replace('ROOT_DIR', '/app', $content); - - $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); - $m->setAccessible(true); - $content = $m->invoke($kernel, $content); - $this->assertEquals(file_get_contents($symfonyRootDir.'/cache/dev/withoutAbsolutePaths.php'), $content); + return array( + array(__DIR__.'/Fixtures/DumpedContainers/app', null, __DIR__.'/Fixtures/DumpedContainers', true), + array(sys_get_temp_dir(), null, __DIR__.'/Fixtures/DumpedContainers', false), + array('/app/app', '/app', '/app', true), + ); } /**