1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use function addslashes;
use function basename;
use function dirname;
use function sprintf;
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\CodeCoverage;
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Filter\Directory;
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Filter\DirectoryCollection;
use PHPUnit\TextUI\XmlConfiguration\File;
use PHPUnit\TextUI\XmlConfiguration\FileCollection;
/**
* @small
* @covers \PHPUnit\Util\XdebugFilterScriptGenerator
*/
final class XDebugFilterScriptGeneratorTest extends TestCase
{
public function testReturnsExpectedScript(): void
{
$expectedDirectory = sprintf(addslashes('%s' . DIRECTORY_SEPARATOR), __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->assertDirectoryDoesNotExist($directoryPathThatDoesNotExist);
$filterConfiguration = new CodeCoverage(
null,
DirectoryCollection::fromArray(
[
new Directory(
__DIR__,
'',
'.php',
'DEFAULT'
),
new Directory(
sprintf('%s/', __DIR__),
'',
'.php',
'DEFAULT'
),
new Directory(
sprintf('%s/./%s', dirname(__DIR__), basename(__DIR__)),
'',
'.php',
'DEFAULT'
),
new Directory(
$directoryPathThatDoesNotExist,
'',
'.php',
'DEFAULT'
),
]
),
FileCollection::fromArray(
[
new File('src/foo.php'),
new File('src/bar.php'),
]
),
DirectoryCollection::fromArray([]),
FileCollection::fromArray([]),
false,
true,
true,
false,
false,
null,
null,
null,
null,
null,
null,
null
);
$writer = new XdebugFilterScriptGenerator;
$actual = $writer->generate($filterConfiguration);
$this->assertSame($expected, $actual);
}
}
|