mirror of
https://github.com/pestphp/pest.git
synced 2026-09-05 22:33:35 +02:00
fix: fail missing snapshots in CI (#1842)
Prevent snapshot assertions from silently creating missing snapshots during CI runs unless --update-snapshots is enabled.
This commit is contained in:
@@ -16,6 +16,36 @@ final class Snapshot implements HandlesArguments
|
||||
|
||||
public static bool $updateSnapshots = false;
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private const array CI_ENVIRONMENT_VARIABLES = [
|
||||
'CI',
|
||||
'GITHUB_ACTIONS',
|
||||
'GITLAB_CI',
|
||||
'CIRCLECI',
|
||||
'TRAVIS',
|
||||
'APPVEYOR',
|
||||
'BITBUCKET_BUILD_NUMBER',
|
||||
'BUILDKITE',
|
||||
'TEAMCITY_VERSION',
|
||||
'JENKINS_URL',
|
||||
'SYSTEM_COLLECTIONURI',
|
||||
'CI_NAME',
|
||||
'TASKCLUSTER_ROOT_URL',
|
||||
'DRONE',
|
||||
'WERCKER',
|
||||
'NEVERCODE',
|
||||
'SEMAPHORE',
|
||||
'NETLIFY',
|
||||
'NOW_BUILDER',
|
||||
];
|
||||
|
||||
public static function shouldCreateMissingSnapshots(): bool
|
||||
{
|
||||
return self::$updateSnapshots || ! self::runningOnCI();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -119,4 +149,19 @@ final class Snapshot implements HandlesArguments
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function runningOnCI(): bool
|
||||
{
|
||||
if (Environment::name() === Environment::CI) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (self::CI_ENVIRONMENT_VARIABLES as $environmentVariable) {
|
||||
if (getenv($environmentVariable) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user