tests: adds more tests regarding snapshots multiple

This commit is contained in:
Nuno Maduro
2023-08-02 23:02:00 +01:00
parent 43107c1743
commit 00109e9976
29 changed files with 79 additions and 26 deletions

View File

@ -62,6 +62,11 @@ trait Testable
*/
private static ?Closure $__afterAll = null;
/**
* The list of snapshot changes, if any.
*/
private array $__snapshotChanges = [];
/**
* Resets the test case static properties.
*/
@ -331,6 +336,24 @@ trait Testable
return ExceptionTrace::ensure(fn (): mixed => call_user_func_array(Closure::bind($closure, $this, $this::class), $arguments));
}
/** @postCondition */
protected function __MarkTestIncompleteIfSnapshotHaveChanged(): void
{
if (count($this->__snapshotChanges) === 0) {
return;
}
if (count($this->__snapshotChanges) === 1) {
$this->markTestIncomplete($this->__snapshotChanges[0]);
return;
}
$messages = implode(PHP_EOL, array_map(static fn (string $message): string => '- $message', $this->__snapshotChanges));
$this->markTestIncomplete($messages);
}
/**
* The printable test case name.
*/

View File

@ -189,29 +189,7 @@ final class TestCaseFactory
private static \$__filename = '$filename';
private array \$__snapshotChanges = [];
$methodsCode
/** @postCondition */
protected function __MarkTestIncompleteIfSnapshotHaveChanged(): void
{
if (empty(\$this->__snapshotChanges)) {
return;
}
if (count(\$this->__snapshotChanges) === 1) {
\$this->markTestIncomplete(\$this->__snapshotChanges[0]);
return;
}
\$formattedMessages = implode(PHP_EOL, array_map(function (string \$message) {
return "- \$message";
}, \$this->__snapshotChanges));
\$this->markTestIncomplete(\$formattedMessages);
}
}
PHP;