mirror of
https://github.com/pestphp/pest.git
synced 2026-12-05 07:15:33 +01:00
cd5bae7e91
* fix(tia): restrict Xdebug coverage to the source scope before tracing * fix(tia): set the Xdebug exclude filter before the bootstrap and keep case twins traced --------- Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
139 lines
5.7 KiB
PHP
139 lines
5.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Pest\Plugins\Tia\SourceScope;
|
|
|
|
describe('contains()', function (): void {
|
|
it('excludes only the files matching the suffix of an excluded directory', function (): void {
|
|
$scope = new SourceScope(
|
|
['/project/src'],
|
|
[['path' => '/project/src', 'prefix' => '', 'suffix' => 'Test.php']],
|
|
);
|
|
|
|
expect($scope->contains('/project/src/Calculator.php'))->toBeTrue()
|
|
->and($scope->contains('/project/src/CalculatorTest.php'))->toBeFalse();
|
|
});
|
|
|
|
it('excludes only the files matching the prefix of an excluded directory', function (): void {
|
|
$scope = new SourceScope(
|
|
['/project/src'],
|
|
[['path' => '/project/src', 'prefix' => 'Legacy', 'suffix' => '.php']],
|
|
);
|
|
|
|
expect($scope->contains('/project/src/Calculator.php'))->toBeTrue()
|
|
->and($scope->contains('/project/src/LegacyCalculator.php'))->toBeFalse();
|
|
});
|
|
|
|
it('excludes every file of an excluded directory without a prefix or suffix', function (): void {
|
|
$scope = new SourceScope(
|
|
['/project'],
|
|
[['path' => '/project/storage/framework', 'prefix' => '', 'suffix' => '']],
|
|
);
|
|
|
|
expect($scope->contains('/project/app/Calculator.php'))->toBeTrue()
|
|
->and($scope->contains('/project/storage/framework/views/compiled.php'))->toBeFalse();
|
|
});
|
|
});
|
|
|
|
describe('coverageExcludePaths()', function (): void {
|
|
beforeEach(function (): void {
|
|
$this->projectRoot = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-tia-scope-'.bin2hex(random_bytes(4));
|
|
mkdir($this->projectRoot.'/vendor/acme', 0755, true);
|
|
mkdir($this->projectRoot.'/storage/framework', 0755, true);
|
|
$this->realRoot = (string) realpath($this->projectRoot);
|
|
});
|
|
|
|
afterEach(function (): void {
|
|
if (is_link($this->projectRoot.'/storage/framework')) {
|
|
unlink($this->projectRoot.'/storage/framework');
|
|
}
|
|
|
|
foreach (['vendor/acme', 'vendor', 'storage/framework', 'storage/Framework', 'storage/generated', 'storage/Generated', 'storage'] as $directory) {
|
|
if (is_dir($this->projectRoot.'/'.$directory)) {
|
|
rmdir($this->projectRoot.'/'.$directory);
|
|
}
|
|
}
|
|
|
|
rmdir($this->projectRoot);
|
|
});
|
|
|
|
it('excludes each noise directory of the project that the scope rejects', function (): void {
|
|
$scope = new SourceScope(
|
|
[$this->realRoot.'/app'],
|
|
[['path' => $this->realRoot.'/storage/framework', 'prefix' => '', 'suffix' => '']],
|
|
);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))->toBe([
|
|
$this->realRoot.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR,
|
|
$this->realRoot.DIRECTORY_SEPARATOR.'storage/framework'.DIRECTORY_SEPARATOR,
|
|
]);
|
|
});
|
|
|
|
it('keeps a noise directory that holds an included directory', function (): void {
|
|
$scope = new SourceScope([$this->realRoot.'/vendor/acme'], []);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))
|
|
->toBe([$this->realRoot.DIRECTORY_SEPARATOR.'storage/framework'.DIRECTORY_SEPARATOR]);
|
|
});
|
|
|
|
it('keeps a noise directory below an included directory', function (): void {
|
|
$scope = new SourceScope([$this->realRoot], []);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))->toBeEmpty();
|
|
});
|
|
|
|
it('keeps a noise directory whose name an included directory shares in another case', function (): void {
|
|
$scope = new SourceScope([$this->realRoot.'/Vendor'], []);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))
|
|
->toBe([$this->realRoot.DIRECTORY_SEPARATOR.'storage/framework'.DIRECTORY_SEPARATOR]);
|
|
});
|
|
|
|
it('keeps a noise directory that has a sibling with the same name in another case', function (): void {
|
|
rmdir($this->projectRoot.'/storage/framework');
|
|
mkdir($this->projectRoot.'/storage/Framework');
|
|
|
|
if (! is_dir($this->projectRoot.'/storage/framework')) {
|
|
mkdir($this->projectRoot.'/storage/framework');
|
|
}
|
|
|
|
$scope = new SourceScope(
|
|
[$this->realRoot.'/storage'],
|
|
[['path' => $this->realRoot.'/storage/framework', 'prefix' => '', 'suffix' => '']],
|
|
);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))
|
|
->toBe([$this->realRoot.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR]);
|
|
});
|
|
|
|
it('keeps each noise directory when an included directory is the project root in another case', function (): void {
|
|
$twinRoot = dirname($this->realRoot).DIRECTORY_SEPARATOR.strtoupper(basename($this->realRoot));
|
|
$scope = new SourceScope(
|
|
[$this->realRoot.'/app', $twinRoot],
|
|
[['path' => $this->realRoot.'/storage/framework', 'prefix' => '', 'suffix' => '']],
|
|
);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))->toBeEmpty();
|
|
});
|
|
|
|
it('keeps a linked noise directory whose target has a sibling with the same name in another case', function (): void {
|
|
rmdir($this->projectRoot.'/storage/framework');
|
|
mkdir($this->projectRoot.'/storage/Generated');
|
|
|
|
if (! is_dir($this->projectRoot.'/storage/generated')) {
|
|
mkdir($this->projectRoot.'/storage/generated');
|
|
}
|
|
|
|
symlink('generated', $this->projectRoot.'/storage/framework');
|
|
|
|
$scope = new SourceScope(
|
|
[$this->realRoot.'/storage'],
|
|
[['path' => $this->realRoot.'/storage/generated', 'prefix' => '', 'suffix' => '']],
|
|
);
|
|
|
|
expect($scope->coverageExcludePaths($this->projectRoot))
|
|
->toBe([$this->realRoot.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR]);
|
|
})->skipOnWindows();
|
|
});
|