mirror of
https://github.com/pestphp/pest.git
synced 2026-12-04 15:05:09 +01:00
8eb2892f69
* fix(tia): skip locally() when the process is on CI locally() only looked at --ci, so a CI job that followed the docs and ran plain pest replayed cached results. Fixes #1970 * test(tia): clear CI variables so the local assertion passes on CI * test: update snapshots for TIA CI detection --------- Co-authored-by: Tiago Santos <tsantos@lynixt.pt> Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
use Pest\Plugins\Tia;
|
|
use Pest\Plugins\Tia\WatchPatterns;
|
|
use Pest\Support\Ci;
|
|
use Pest\Support\Container;
|
|
|
|
test('does not throw when an integer --random-order-seed is passed as a separate argv element', function (): void {
|
|
$arguments = ['--order-by=random', '--random-order-seed', 1782350398];
|
|
|
|
expect(Tia::isEnabledForRun($arguments))->toBeFalse();
|
|
});
|
|
|
|
test('still detects --tia when an integer argument is present', function (): void {
|
|
$arguments = ['--tia', '--random-order-seed', 1782350398];
|
|
|
|
expect(Tia::isEnabledForRun($arguments))->toBeTrue();
|
|
});
|
|
|
|
test('locally configured tia runs outside CI', function (): void {
|
|
$previous = [];
|
|
|
|
foreach (Ci::ENVIRONMENT_VARIABLES as $variable) {
|
|
$previous[$variable] = getenv($variable);
|
|
putenv($variable);
|
|
}
|
|
|
|
try {
|
|
withLocalTia(function (): void {
|
|
expect(Tia::isEnabledForRun([]))->toBeTrue();
|
|
});
|
|
} finally {
|
|
foreach ($previous as $variable => $value) {
|
|
putenv($value === false ? $variable : $variable.'='.$value);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('locally configured tia stays off when CI is detected', function (string $variable): void {
|
|
withLocalTia(function () use ($variable): void {
|
|
$previous = getenv($variable);
|
|
putenv($variable.'=true');
|
|
|
|
try {
|
|
expect(Tia::isEnabledForRun([]))->toBeFalse()
|
|
->and(Tia::isEnabledForRun(['--ci']))->toBeFalse();
|
|
} finally {
|
|
putenv($previous === false ? $variable : $variable.'='.$previous);
|
|
}
|
|
});
|
|
})->with(['CI', 'GITHUB_ACTIONS']);
|
|
|
|
function withLocalTia(Closure $callback): void
|
|
{
|
|
$patterns = Container::getInstance()->get(WatchPatterns::class);
|
|
$reflection = new ReflectionClass($patterns);
|
|
$enabled = $reflection->getProperty('enabled');
|
|
$locally = $reflection->getProperty('locally');
|
|
$wasEnabled = $enabled->getValue($patterns);
|
|
$wasLocally = $locally->getValue($patterns);
|
|
|
|
$patterns->markEnabled();
|
|
$patterns->markLocally();
|
|
|
|
try {
|
|
$callback();
|
|
} finally {
|
|
$enabled->setValue($patterns, $wasEnabled);
|
|
$locally->setValue($patterns, $wasLocally);
|
|
}
|
|
}
|