Skip to content

Commit

Permalink
Clone the snapshot in the collection mutator
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Mar 24, 2017
1 parent 9d50450 commit e90a67a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@
}
}
}

6 changes: 3 additions & 3 deletions src/Snapshot/CollectionSnapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public function mutate(RecursiveSnapshotter $recursiveSnapshotter): Snapshot

$clone = clone $this;

foreach ($clone->data as &$snapshot) {
$snapshot = $snapshot->mutate($recursiveSnapshotter);
foreach ($clone->data as $key => $snapshot) {
$snapshot = clone $snapshot;
$clone->data[$key] = $snapshot->mutate($recursiveSnapshotter);
}

return $clone;
}
}

7 changes: 4 additions & 3 deletions test/Snapshot/CollectionSnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public function testMutate()

$recursive->addSnapshotter($snapshotter);

$snapshot = new CollectionSnapshot(['foo'], [$snapshot->reveal()], [], true);
$snapshot = $snapshot->mutate($recursive);
$collectionSnapshot = new CollectionSnapshot(['foo'], [$snapshot->reveal()], [], true);
$mutatedSnapshot = $collectionSnapshot->mutate($recursive);

$this->assertInstanceOf(CollectionSnapshot::class, $snapshot);
$this->assertInstanceOf(CollectionSnapshot::class, $mutatedSnapshot);
$this->assertNotSame($mutatedSnapshot, $collectionSnapshot);
}

public function testItIsComparableToOtherCollectionSnapshots()
Expand Down

0 comments on commit e90a67a

Please sign in to comment.