setTimeout(10.0); $process->mustRun(); } function fingerprintRepository(): string { $root = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest_fingerprint_'.uniqid(); mkdir($root, 0777, true); fingerprintGit($root, 'init', '-q'); fingerprintGit($root, 'config', 'user.email', 'pest@example.com'); fingerprintGit($root, 'config', 'user.name', 'Pest'); return $root; } function fingerprintRemoveDirectory(string $path): void { if (! is_dir($path)) { return; } $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST, ); foreach ($iterator as $file) { @chmod($file->getPathname(), 0777); $file->isDir() ? @rmdir($file->getPathname()) : @unlink($file->getPathname()); } @rmdir($path); } describe('compute()', function (): void { it('fingerprints tracked structural files in a regular clone', function (): void { $clone = fingerprintRepository(); try { file_put_contents($clone.'/composer.lock', '{"packages": []}'); file_put_contents($clone.'/phpunit.xml', ''); fingerprintGit($clone, 'add', '-A'); fingerprintGit($clone, 'commit', '-q', '-m', 'init'); $fingerprint = Fingerprint::compute($clone); expect($fingerprint['structural']['composer_lock'])->not->toBeNull() ->and($fingerprint['structural']['phpunit_configuration'])->not->toBeNull(); } finally { fingerprintRemoveDirectory($clone); } }); it('fingerprints tracked structural files inside a linked git worktree', function (): void { $clone = fingerprintRepository(); try { file_put_contents($clone.'/composer.lock', '{"packages": []}'); file_put_contents($clone.'/phpunit.xml', ''); file_put_contents($clone.'/.gitignore', ".worktrees/\n"); fingerprintGit($clone, 'add', '-A'); fingerprintGit($clone, 'commit', '-q', '-m', 'init'); fingerprintGit($clone, 'worktree', 'add', '-q', '.worktrees/feature'); $worktree = $clone.'/.worktrees/feature'; $cloneFingerprint = Fingerprint::compute($clone); $worktreeFingerprint = Fingerprint::compute($worktree); expect($worktreeFingerprint['structural']['composer_lock'])->not->toBeNull() ->and($worktreeFingerprint['structural']['phpunit_configuration'])->not->toBeNull() ->and($worktreeFingerprint['structural']['composer_lock'])->toBe($cloneFingerprint['structural']['composer_lock']) ->and($worktreeFingerprint['structural']['phpunit_configuration'])->toBe($cloneFingerprint['structural']['phpunit_configuration']); } finally { fingerprintRemoveDirectory($clone); } }); it('excludes gitignored untracked files from the fingerprint', function (): void { $clone = fingerprintRepository(); try { file_put_contents($clone.'/phpunit.xml', ''); file_put_contents($clone.'/.gitignore', "composer.lock\n"); fingerprintGit($clone, 'add', '-A'); fingerprintGit($clone, 'commit', '-q', '-m', 'init'); file_put_contents($clone.'/composer.lock', '{"packages": []}'); $fingerprint = Fingerprint::compute($clone); expect($fingerprint['structural']['composer_lock'])->toBeNull() ->and($fingerprint['structural']['phpunit_configuration'])->not->toBeNull(); } finally { fingerprintRemoveDirectory($clone); } }); it('keeps the command line bootstrap and include path out of a run that sets neither', function (): void { $root = fingerprintRepository(); try { $structural = Fingerprint::compute($root, ConfigurationFile::fromArguments(['--tia']))['structural']; expect($structural)->not->toHaveKey('phpunit_bootstrap') ->and($structural)->not->toHaveKey('phpunit_include_path'); } finally { fingerprintRemoveDirectory($root); } }); it('tells a bootstrap whose name looks like an include path apart from a bootstrap and an include path', function (): void { $root = fingerprintRepository(); try { $bootstrapOnly = Fingerprint::compute($root, ConfigurationFile::fromArguments(['--bootstrap', 'bootstrap.php;include-path=app'])); $bootstrapAndIncludePath = Fingerprint::compute($root, ConfigurationFile::fromArguments(['--bootstrap', 'bootstrap.php', '--include-path', 'app'])); expect(Fingerprint::structuralMatches($bootstrapOnly, $bootstrapAndIncludePath))->toBeFalse() ->and(Fingerprint::structuralDrift($bootstrapOnly, $bootstrapAndIncludePath))->toBe(['phpunit_bootstrap', 'phpunit_include_path']); } finally { fingerprintRemoveDirectory($root); } }); });