From afa7f010950cf27b6a29cf8df4124f9831e10a36 Mon Sep 17 00:00:00 2001 From: fancyweb Date: Fri, 28 Dec 2018 23:22:29 +0100 Subject: [PATCH] feat(xdebug-filter-generator): improve directories paths --- src/Util/XdebugFilterScriptGenerator.php | 4 +- .../Util/XDebugFilterScriptGeneratorTest.php | 43 ++++++++++++++++++- .../_files/expectedXDebugFilterScript.txt | 14 ------ 3 files changed, 44 insertions(+), 17 deletions(-) delete mode 100644 tests/unit/Util/_files/expectedXDebugFilterScript.txt diff --git a/src/Util/XdebugFilterScriptGenerator.php b/src/Util/XdebugFilterScriptGenerator.php index d2dff2a8a18..66c74eee58e 100644 --- a/src/Util/XdebugFilterScriptGenerator.php +++ b/src/Util/XdebugFilterScriptGenerator.php @@ -50,7 +50,9 @@ private function getWhitelistItems(array $filterData): array if (isset($filterData['include']['directory'])) { foreach ($filterData['include']['directory'] as $directory) { - $files[] = $directory['path']; + if (\is_string($path = \realpath($directory['path']))) { + $files[] = \sprintf('%s/', $path); + } } } diff --git a/tests/unit/Util/XDebugFilterScriptGeneratorTest.php b/tests/unit/Util/XDebugFilterScriptGeneratorTest.php index a8e08b724a4..41ddf80d569 100644 --- a/tests/unit/Util/XDebugFilterScriptGeneratorTest.php +++ b/tests/unit/Util/XDebugFilterScriptGeneratorTest.php @@ -18,11 +18,50 @@ class XDebugFilterScriptGeneratorTest extends TestCase */ public function testReturnsExpectedScript(): void { + $expectedDirectory = \sprintf('%s/', __DIR__); + $expected = <<assertDirectoryNotExists($directoryPathThatDoesNotExist); + $filterConfiguration = [ 'include' => [ 'directory' => [ [ - 'path' => 'src/somePath', + 'path' => __DIR__, + 'suffix' => '.php', + 'prefix' => '', + ], + [ + 'path' => \sprintf('%s/', __DIR__), + 'suffix' => '.php', + 'prefix' => '', + ], + [ + 'path' => \sprintf('%s/./%s', \dirname(__DIR__), \basename(__DIR__)), + 'suffix' => '.php', + 'prefix' => '', + ], + [ + 'path' => $directoryPathThatDoesNotExist, 'suffix' => '.php', 'prefix' => '', ], @@ -41,6 +80,6 @@ public function testReturnsExpectedScript(): void $writer = new XdebugFilterScriptGenerator; $actual = $writer->generate($filterConfiguration); - $this->assertStringEqualsFile(__DIR__ . '/_files/expectedXDebugFilterScript.txt', $actual); + $this->assertSame($expected, $actual); } } diff --git a/tests/unit/Util/_files/expectedXDebugFilterScript.txt b/tests/unit/Util/_files/expectedXDebugFilterScript.txt deleted file mode 100644 index dfcf8060b1f..00000000000 --- a/tests/unit/Util/_files/expectedXDebugFilterScript.txt +++ /dev/null @@ -1,14 +0,0 @@ -