fix incomplete tests while updating snapshots

This commit is contained in:
Fabio Ivona
2023-08-01 17:13:15 +02:00
parent 2f6b99885e
commit 4e719214c6
3 changed files with 32 additions and 2 deletions

View File

@ -189,7 +189,29 @@ final class TestCaseFactory
private static \$__filename = '$filename'; private static \$__filename = '$filename';
private array \$__snapshotChanges = [];
$methodsCode $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; PHP;

View File

@ -834,7 +834,8 @@ final class Expectation
} else { } else {
$filename = $snapshots->save($string); $filename = $snapshots->save($string);
//$testCase::markTestIncomplete('Snapshot created at ['.$filename.'].'); // $testCase::markTestIncomplete('Snapshot created at ['.$filename.'].');
TestSuite::getInstance()->registerSnapshotChange("Snapshot created at [$filename]");
} }
return $this; return $this;

View File

@ -100,7 +100,7 @@ final class TestSuite
return self::$instance; return self::$instance;
} }
if (! self::$instance instanceof self) { if (!self::$instance instanceof self) {
Panic::with(new InvalidPestCommand()); Panic::with(new InvalidPestCommand());
} }
@ -114,6 +114,13 @@ final class TestSuite
return (fn () => self::$__filename)->call($this->test, $this->test::class); // @phpstan-ignore-line return (fn () => self::$__filename)->call($this->test, $this->test::class); // @phpstan-ignore-line
} }
public function registerSnapshotChange(string $message): void
{
assert($this->test instanceof TestCase);
(fn () => $this->__snapshotChanges[] = $message)->call($this->test, $this->test::class); // @phpstan-ignore-line
}
public function getDescription(): string public function getDescription(): string
{ {
assert($this->test instanceof TestCase); assert($this->test instanceof TestCase);