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:
Caleb White
2026-08-10 19:02:44 -05:00
committed by GitHub
parent 375b92e93b
commit 617226ca01
3 changed files with 57 additions and 1 deletions
+45
View File
@@ -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;
}
}