Skip to content

Commit

Permalink
feat: Improve the diagnosis of the finders to state the result return…
Browse files Browse the repository at this point in the history
…ed (#134)
  • Loading branch information
theofidry authored Jul 29, 2024
1 parent 6f5b78e commit ae6c2b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion infection.json5
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"Coalesce": {
"ignore": [
// Cannot test this case.
"Fidry\\CpuCoreCounter\\CpuCoreCounter::getAvailableForParallelisation"
"Fidry\\CpuCoreCounter\\CpuCoreCounter::getAvailableForParallelisation",
// Not interested in testing this case.
"Fidry\\CpuCoreCounter\\Finder\\ProcOpenBasedFinder::diagnose"
]
},
"Continue_": false,
Expand Down
6 changes: 4 additions & 2 deletions src/Finder/CpuInfoFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public function diagnose(): string
}

return sprintf(
'Found the file "%s" with the content:%s%s',
'Found the file "%s" with the content:%s%s%sWill return "%s".',
self::CPU_INFO_PATH,
PHP_EOL,
$cpuInfo
$cpuInfo,
PHP_EOL,
self::countCpuCores($cpuInfo)
);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Finder/ProcOpenBasedFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ public function diagnose(): string

return $failed
? sprintf(
'Executed the command "%s" which wrote the following output to the STDERR:%s%s',
'Executed the command "%s" which wrote the following output to the STDERR:%s%s%sWill return "null".',
$command,
PHP_EOL,
$stderr
$stderr,
PHP_EOL
)
: sprintf(
'Executed the command "%s" and got the following (STDOUT) output:%s%s',
'Executed the command "%s" and got the following (STDOUT) output:%s%s%sWill return "%s".',
$command,
PHP_EOL,
$stdout
$stdout,
PHP_EOL,
$this->countCpuCores($stdout) ?? 'null'
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Finder/ProcOpenBasedFinderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function test_it_can_do_a_diagnosis(

public static function diagnosisProvider(): iterable
{
$stdoutResultRegex = '/^Executed the command ".*" and got the following \(STDOUT\) output:\nsmth in stdout$/';
$stderrResultRegex = '/^Executed the command ".*" which wrote the following output to the STDERR:\nsmth in stderr$/';
$stdoutResultRegex = '/^Executed the command ".*" and got the following \(STDOUT\) output:\nsmth in stdout\nWill return "(null|\d)"\.$/';
$stderrResultRegex = '/^Executed the command ".*" which wrote the following output to the STDERR:\nsmth in stderr\nWill return "(null|\d)"\.$/';

yield 'could not execute command' => [
null,
Expand Down

0 comments on commit ae6c2b2

Please sign in to comment.