mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 16:27:23 +01:00
multiple snapshots
This commit is contained in:
@ -806,6 +806,7 @@ final class Expectation
|
||||
public function toMatchSnapshot(string $message = ''): self
|
||||
{
|
||||
$snapshots = TestSuite::getInstance()->snapshots;
|
||||
$snapshots->startNewExpectation();
|
||||
|
||||
$testCase = TestSuite::getInstance()->test;
|
||||
assert($testCase instanceof TestCase);
|
||||
@ -833,7 +834,7 @@ final class Expectation
|
||||
} else {
|
||||
$filename = $snapshots->save($string);
|
||||
|
||||
$testCase::markTestIncomplete('Snapshot created at ['.$filename.'].');
|
||||
//$testCase::markTestIncomplete('Snapshot created at ['.$filename.'].');
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@ -12,6 +12,8 @@ use Pest\TestSuite;
|
||||
*/
|
||||
final class SnapshotRepository
|
||||
{
|
||||
private static array $expectationsCounter = [];
|
||||
|
||||
/**
|
||||
* Creates a snapshot repository instance.
|
||||
*/
|
||||
@ -106,6 +108,33 @@ final class SnapshotRepository
|
||||
// remove extension from filename
|
||||
$relativePath = substr($relativePath, 0, (int) strrpos($relativePath, '.'));
|
||||
|
||||
return sprintf('%s/%s.snap', $this->testsPath.'/'.$this->snapshotsPath.$relativePath, TestSuite::getInstance()->getDescription());
|
||||
$description = TestSuite::getInstance()->getDescription();
|
||||
|
||||
if($this->getCurrentSnapshotCounter() > 1){
|
||||
$description .= '__' . $this->getCurrentSnapshotCounter();
|
||||
}
|
||||
|
||||
return sprintf('%s/%s.snap', $this->testsPath.'/'.$this->snapshotsPath.$relativePath, $description);
|
||||
}
|
||||
|
||||
private function getCurrentSnapshotKey(): string
|
||||
{
|
||||
return TestSuite::getInstance()->getFilename().'###'.TestSuite::getInstance()->getDescription();
|
||||
}
|
||||
|
||||
private function getCurrentSnapshotCounter(): int
|
||||
{
|
||||
return self::$expectationsCounter[$this->getCurrentSnapshotKey()] ?? 0;
|
||||
}
|
||||
|
||||
public function startNewExpectation(): void
|
||||
{
|
||||
$key = $this->getCurrentSnapshotKey();
|
||||
|
||||
if(!isset(self::$expectationsCounter[$key])){
|
||||
self::$expectationsCounter[$key] = 0;
|
||||
}
|
||||
|
||||
self::$expectationsCounter[$key]++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user