Skip to content

Commit

Permalink
feat(xdebug-filter-generator): improve directories paths
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyweb authored and sebastianbergmann committed Jan 9, 2019
1 parent be5f758 commit afa7f01
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/Util/XdebugFilterScriptGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
43 changes: 41 additions & 2 deletions tests/unit/Util/XDebugFilterScriptGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,50 @@ class XDebugFilterScriptGeneratorTest extends TestCase
*/
public function testReturnsExpectedScript(): void
{
$expectedDirectory = \sprintf('%s/', __DIR__);
$expected = <<<EOF
<?php declare(strict_types=1);
if (!\\function_exists('xdebug_set_filter')) {
return;
}
\\xdebug_set_filter(
\\XDEBUG_FILTER_CODE_COVERAGE,
\\XDEBUG_PATH_WHITELIST,
[
'$expectedDirectory',
'$expectedDirectory',
'$expectedDirectory',
'src/foo.php',
'src/bar.php'
]
);
EOF;

$directoryPathThatDoesNotExist = \sprintf('%s/path/that/does/not/exist', __DIR__);
$this->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' => '',
],
Expand All @@ -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);
}
}
14 changes: 0 additions & 14 deletions tests/unit/Util/_files/expectedXDebugFilterScript.txt

This file was deleted.

0 comments on commit afa7f01

Please sign in to comment.