Skip to content

Commit 354e016

Browse files
committed
Update tests and correct dirtyState cloneResult
1 parent a598c8c commit 354e016

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Mvc/Collection.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,16 @@ public static function aggregate(?array $parameters = [], ?array $options = []):
198198
*/
199199
public static function cloneResult(CollectionInterface $base, array $data, int $dirtyState = 0): CollectionInterface
200200
{
201+
/**
202+
* Clone the base record
203+
*/
201204
$collection = clone $base;
202205

206+
/**
207+
* Mark the object as persistent
208+
*/
209+
$collection->setDirtyState($dirtyState);
210+
203211
foreach ($data as $key => $value) {
204212
$collection->writeAttribute($key, $value);
205213
}
@@ -1360,10 +1368,6 @@ protected static function getResultset(
13601368
$base = $collection;
13611369
}
13621370

1363-
if ($base instanceof self) {
1364-
$base->setDirtyState(self::DIRTY_STATE_PERSISTENT);
1365-
}
1366-
13671371
$source = $collection->getSource();
13681372
if (empty($source)) {
13691373
throw new Exception("Method getSource() returns empty string");

tests/integration/Collection/CloneResultCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function mvcCollectionCloneResult(IntegrationTester $I)
6262
$robot = Robots::findFirst();
6363
$clonedRobot = Robots::cloneResult($robot, []);
6464

65+
$I->assertEquals(Robots::DIRTY_STATE_PERSISTENT, $clonedRobot->getDirtyState());
6566
$I->assertEquals($robot, $clonedRobot);
6667
}
6768

0 commit comments

Comments
 (0)