mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
snapshots code cleanup
This commit is contained in:
@ -805,6 +805,11 @@ final class Expectation
|
||||
*/
|
||||
public function toMatchSnapshot(string $message = ''): self
|
||||
{
|
||||
$snapshots = TestSuite::getInstance()->snapshots;
|
||||
|
||||
$testCase = TestSuite::getInstance()->test;
|
||||
assert($testCase instanceof TestCase);
|
||||
|
||||
$string = match (true) {
|
||||
is_string($this->value) => $this->value,
|
||||
is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(),
|
||||
@ -817,12 +822,8 @@ final class Expectation
|
||||
default => InvalidExpectationValue::expected('array|object|string'),
|
||||
};
|
||||
|
||||
$testCase = TestSuite::getInstance()->test;
|
||||
assert($testCase instanceof TestCase);
|
||||
$snapshots = TestSuite::getInstance()->snapshots;
|
||||
|
||||
if ($snapshots->has($testCase, $string)) {
|
||||
[$filename, $content] = $snapshots->get($testCase, $string);
|
||||
if ($snapshots->has()) {
|
||||
[$filename, $content] = $snapshots->get();
|
||||
|
||||
Assert::assertSame(
|
||||
$content,
|
||||
@ -830,7 +831,7 @@ final class Expectation
|
||||
$message === '' ? "Failed asserting that the string value matches its snapshot ($filename)." : $message
|
||||
);
|
||||
} else {
|
||||
$filename = $snapshots->save($testCase, $string);
|
||||
$filename = $snapshots->save($string);
|
||||
|
||||
$testCase::markTestIncomplete('Snapshot created at ['.$filename.'].');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user