diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index cbe50985..7b9da1f9 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -189,7 +189,29 @@ 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; diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 6eed299a..fe49cb0f 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -834,7 +834,8 @@ final class Expectation } else { $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; diff --git a/src/TestSuite.php b/src/TestSuite.php index 51c1084d..e27ec155 100644 --- a/src/TestSuite.php +++ b/src/TestSuite.php @@ -100,7 +100,7 @@ final class TestSuite return self::$instance; } - if (! self::$instance instanceof self) { + if (!self::$instance instanceof self) { Panic::with(new InvalidPestCommand()); } @@ -114,6 +114,13 @@ final class TestSuite 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 { assert($this->test instanceof TestCase);