Skip to content

Commit a598c8c

Browse files
committed
Check dirtyState and correct bsonUnserialize dirtystate
1 parent 2ee40a0 commit a598c8c

File tree

5 files changed

+6
-8
lines changed

5 files changed

+6
-8
lines changed

src/Mvc/Collection.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,8 @@ public function bsonUnserialize(array $data): void
945945

946946
$this->collectionsManager = $collectionsManager;
947947

948+
$this->dirtyState = self::DIRTY_STATE_PERSISTENT;
949+
948950
foreach ($data as $key => $value) {
949951
$this->writeAttribute($key, $value);
950952
}
@@ -1406,10 +1408,6 @@ protected static function getResultset(
14061408
return null;
14071409
}
14081410

1409-
if (method_exists($base, 'afterFetch')) {
1410-
$base->afterFetch();
1411-
}
1412-
14131411
return $document;
14141412
}
14151413

@@ -1418,10 +1416,6 @@ protected static function getResultset(
14181416
*/
14191417
$documentsCursor = $mongoCollection->find($conditions, $parameters);
14201418

1421-
if (method_exists($base, 'afterFetch')) {
1422-
$base->afterFetch();
1423-
}
1424-
14251419
return $documentsCursor->toArray();
14261420
}
14271421

tests/integration/Collection/ConstructCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ public function mvcCollectionConstruct(IntegrationTester $I)
4444

4545
$robot = new Robots();
4646
$I->assertInstanceOf(Robots::class, $robot);
47+
$I->assertEquals(Robots::DIRTY_STATE_TRANSIENT, $robot->getDirtyState());
4748
}
4849
}

tests/integration/Collection/CreateCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function mvcCollectionCreate(IntegrationTester $I)
5454
$robot = new Robots();
5555
$robot->first_name = null;
5656
$I->assertTrue($robot->create());
57+
$I->assertEquals(Robots::DIRTY_STATE_PERSISTENT, $robot->getDirtyState());
5758

5859
$search = $this->mongo->selectCollection($this->source)->findOne(['_id' => $robot->getId()]);
5960
$I->assertNotNull($search);

tests/integration/Collection/FindFirstCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function mvcCollectionFindFirst(IntegrationTester $I)
6767

6868
/** @var Robots|bool $firstRobot */
6969
$firstRobot = Robots::findFirst();
70+
$I->assertEquals(Robots::DIRTY_STATE_PERSISTENT, $firstRobot->getDirtyState());
7071

7172
/** @var Robots|bool $robot */
7273
$robot = Robots::findFirst([['last_name' => 'Nobody']]);

tests/integration/Collection/UpdateCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function mvcCollectionUpdate(IntegrationTester $I)
6565

6666
$robot->last_name = 'X';
6767
$I->assertTrue($robot->update());
68+
$I->assertEquals(Robots::DIRTY_STATE_PERSISTENT, $robot->getDirtyState());
6869

6970
$updated = $this->mongo->selectCollection($this->source)->findOne(['_id' => $robot->getId()]);
7071
$I->assertEquals($updated['last_name'], 'X');

0 commit comments

Comments
 (0)