Skip to content

Instantly share code, notes, and snippets.

@x86demon
Last active April 22, 2024 11:59
Show Gist options
  • Save x86demon/0d4bea7c3dc685aeba2bba98d0dbb370 to your computer and use it in GitHub Desktop.
Save x86demon/0d4bea7c3dc685aeba2bba98d0dbb370 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
$jenkinsFile = $argv[1];
$mode = $argv[2] ?? 'short';
$lines = explode(PHP_EOL, file_get_contents($jenkinsFile, 'r'));
$failedTests = [];
function removeRuntimeInfo(string $str): string
{
$str = preg_replace('/\s+\d+\.\d+\s+sec\s+\d+/', '', $str);
$str = preg_replace('/\s+\d+\s+sec\s+\d+/', '', $str);
return preg_replace('/\s+\d+\s+min/', '', $str);
}
foreach ($lines as $line) {
$parts = explode('/', $line);
$parts = array_map('trim', $parts);
if (count($parts) < 3) {
continue;
}
$parts[2] = removeRuntimeInfo($parts[2]);
if (str_starts_with($parts[2], 'behat')) {
$parts[2] = trim($parts[2], '.');
$testData = strrev($parts[2]);
$behatInfoParts = explode('.', $testData, 3);
$behatInfoParts = array_map('strrev', $behatInfoParts);
$metadata = array_merge([$parts[1]], explode('_', $behatInfoParts[2]));
$behatFeature = $behatInfoParts[1];
$behatScenario = $behatInfoParts[0];
$failedTests['behat'][$behatFeature] = ['env' => $parts[1], 'vars' => $metadata, 'scenario' => $behatScenario];
} else {
$testParts = explode('.', $parts[2]);
$function = array_pop($testParts);
$test = implode('\\', $testParts) . '::' . $function;
if (str_contains($test, 'Unit')) {
$failedTests['unit'][$test] = ['env' => $parts[1]];
} else {
$failedTests['functional'][$test] = ['env' => $parts[1]];
}
}
}
if ($mode === 'short') {
foreach ($failedTests as $type => $tests) {
echo $type . PHP_EOL;
echo '-----------------------' . PHP_EOL;
echo implode(PHP_EOL, array_keys($tests)) . PHP_EOL . PHP_EOL;
}
} else {
var_dump($failedTests);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment