8000 [HttpKernel] simplified some tests · symfony/symfony@ccacd8d · GitHub
[go: up one dir, main page]

Skip to content

Commit ccacd8d

Browse files
committed
[HttpKernel] simplified some tests
1 parent 9766c72 commit ccacd8d

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -824,48 +824,37 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
824824
$kernel->terminate(Request::create('/'), new Response());
825825
}
826826

827-
public function testRemoveAbsolutePathsFromContainer()
828-
{
829-
$kernel = new KernelForTest('dev', true);
830-
$kernel->setRootDir($symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app');
831-
832-
$content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php');
833-
$content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content);
834-
835-
$m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer');
836-
$m->setAccessible(true);
837-
$content = $m->invoke($kernel, $content);
838-
$this->assertEquals(file_get_contents($symfonyRootDir.'/cache/dev/withoutAbsolutePaths.php'), $content);
839-
}
840-
841-
public function testRemoveAbsolutePathsFromContainerGiveUpWhenComposerJsonPathNotGuessable()
827+
/**
828+
* @dataProvider getRemoveAbsolutePathsFromContainerData
829+
*/
830+
public function testRemoveAbsolutePathsFromContainer($symfonyRootDir, $realRootDir, $replacement, $replaced)
842831
{
843832
$kernel = new KernelForTest('dev', true);
844-
$kernel->setRootDir($symfonyRootDir = sys_get_temp_dir());
833+
$kernel->setRootDir($symfonyRootDir);
834+
if (null !== $realRootDir) {
835+
$kernel->setRealRootDir($realRootDir);
836+
}
845837

846838
$content = file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php');
847-
$content = str_replace('ROOT_DIR', __DIR__.'/Fixtures/DumpedContainers', $content);
839+
$content = str_replace('ROOT_DIR', $replacement, $content);
848840

849841
$m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer');
850842
$m->setAccessible(true);
851843
$newContent = $m->invoke($kernel, $content);
852-
$this->assertEquals($newContent, $content);
844+
if ($replaced) {
845+
$this->assertEquals(file_get_contents(__DIR__.'/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php'), $newContent);
846+
} else {
847+
$this->assertEquals($newContent, $content);
848+
}
853849
}
854850

855-
public function testRemoveAbsolutePathsFromContainerWithSpecialCase()
851+
public function getRemoveAbsolutePathsFromContainerData()
856852
{
857-
$kernel = new KernelForTest('dev', true);
858-
$kernel->setRootDir('/app/app');
859-
$kernel->setRealRootDir('/app');
860-
$symfonyRootDir = __DIR__.'/Fixtures/DumpedContainers/app';
861-
862-
$content = file_get_contents($symfonyRootDir.'/cache/dev/withAbsolutePaths.php');
863-
$content = str_replace('ROOT_DIR', '/app', $content);
864-
865-
$m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer');
866-
$m->setAccessible(true);
867-
$content = $m->invoke($kernel, $content);
868-
$this->assertEquals(file_get_contents($symfonyRootDir.'/cache/dev/withoutAbsolutePaths.php'), $content);
853+
return array(
854+
array(__DIR__.'/Fixtures/DumpedContainers/app', null, __DIR__.'/Fixtures/DumpedContainers', true),
855+
array(sys_get_temp_dir(), null, __DIR__.'/Fixtures/DumpedContainers', false),
856+
array('/app/app', '/app', '/app', true),
857+
);
869858
}
870859

871860
/**

0 commit comments

Comments
 (0)
0