Files
pest/tests/Visual/TeamCity.php
T
2026-11-19 15:51:16 +05:30

63 lines
1.9 KiB
PHP

<?php
use Symfony\Component\Process\Process;
function normalize_windows_os_output(string $text): string
{
$text = str_replace('\r', '', $text);
return str_replace('\\', '/', $text);
}
test('visual snapshot of team city', function (string $testFile): void {
$testsPath = dirname(__DIR__)."/Fixtures/Suites/$testFile";
$snapshot = implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__),
'.snapshots',
"$testFile.inc",
]);
$output = function () use ($testsPath): string {
$process = (new Process(
['php', 'bin/pest', '--teamcity', $testsPath],
dirname(__DIR__, levels: 2),
[
'EXCLUDE' => 'integration',
'REBUILD_SNAPSHOTS' => false,
'PARATEST' => 0,
'COLLISION_IGNORE_DURATION' => 'true',
'FLOW_ID' => '1234',
'PAO_DISABLE' => '1',
],
));
$process->run();
return $process->getOutput();
};
if (getenv('REBUILD_SNAPSHOTS')) {
file_put_contents($snapshot, normalize_windows_os_output($output()));
} elseif (! getenv('EXCLUDE')) {
expect(normalize_windows_os_output($output()))->toEqual(file_get_contents($snapshot));
}
})->with([
'Failure.php',
'SuccessOnly.php',
])->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'));
test('preserves TeamCity text in a test filter', function (array $filterArguments): void {
$process = new Process(
[PHP_BINARY, 'bin/pest', '--colors=never', 'tests/Fixtures/Suites/SuccessOnly.php', ...$filterArguments],
dirname(__DIR__, 2),
['PARATEST' => '0', 'PAO_DISABLE' => '1'],
);
expect($process->run())->toBe(0)
->and($process->getOutput())->toContain('1 passed (1 assertions)');
})->with([
'attached value' => [['--filter=can pass with comparison|--teamcity']],
'separate value' => [['--filter', 'can pass with comparison|--teamcity']],
]);