From 3ff7a12a472afad534055ccd9363f64598edb50c Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 2 May 2026 07:50:03 +0200 Subject: [PATCH 1/2] fix(database): hydrate deferred writes before staging values --- src/Handlers/DatabaseHandler.php | 3 +++ tests/DatabaseHandlerTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Handlers/DatabaseHandler.php b/src/Handlers/DatabaseHandler.php index c0ec985..3ae38dd 100644 --- a/src/Handlers/DatabaseHandler.php +++ b/src/Handlers/DatabaseHandler.php @@ -81,6 +81,7 @@ public function get(string $class, string $property, ?string $context = null) public function set(string $class, string $property, $value = null, ?string $context = null): void { if ($this->deferWrites) { + $this->hydrate($context); $this->markPending($class, $property, $value, $context); } else { $this->persist($class, $property, $value, $context); @@ -104,6 +105,8 @@ public function setMany(array $settings, ?string $context = null): void } if ($this->deferWrites) { + $this->hydrate($context); + foreach ($settings as $setting) { $this->markPending($setting['class'], $setting['property'], $setting['value'], $context); $this->setStored($setting['class'], $setting['property'], $setting['value'], $context); diff --git a/tests/DatabaseHandlerTest.php b/tests/DatabaseHandlerTest.php index 7a9f3ec..adcca75 100644 --- a/tests/DatabaseHandlerTest.php +++ b/tests/DatabaseHandlerTest.php @@ -490,6 +490,30 @@ public function testDeferredSetManyPersistsAfterPersist(): void ]); } + public function testDeferredSetReturnsPendingValueBeforePersist(): void + { + $this->settings->set('Example.siteName', 'StoredSingle'); + + $deferredSettings = $this->createDeferredSettings(); + + $deferredSettings->set('Example.siteName', 'PendingSingle'); + + $this->assertSame('PendingSingle', $deferredSettings->get('Example.siteName')); + } + + public function testDeferredSetManyReturnsPendingValueBeforePersist(): void + { + $this->settings->set('Example.siteName', 'StoredBatch'); + + $deferredSettings = $this->createDeferredSettings(); + + $deferredSettings->setMany([ + 'Example.siteName' => 'PendingBatch', + ]); + + $this->assertSame('PendingBatch', $deferredSettings->get('Example.siteName')); + } + public function testDeferredSetManyPersistsDifferentClassesAfterPersist(): void { $deferredSettings = $this->createDeferredSettings(); From eb91cc6763904452dee8d7423bb6c91785fb887b Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 2 May 2026 07:52:52 +0200 Subject: [PATCH 2/2] add similar tests for the file handler to prove it is working correctly --- tests/FileHandlerTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/FileHandlerTest.php b/tests/FileHandlerTest.php index e966859..9cb1f4d 100644 --- a/tests/FileHandlerTest.php +++ b/tests/FileHandlerTest.php @@ -682,6 +682,30 @@ public function testDeferredSetManyPersistsAfterPersist(): void $this->assertSame('deferred@example.com', $data['siteEmail']['value']); } + public function testDeferredSetReturnsPendingValueBeforePersist(): void + { + $this->settings->set('Example.siteName', 'FileStoredSingle'); + + $deferredSettings = $this->createDeferredSettings(); + + $deferredSettings->set('Example.siteName', 'FilePendingSingle'); + + $this->assertSame('FilePendingSingle', $deferredSettings->get('Example.siteName')); + } + + public function testDeferredSetManyReturnsPendingValueBeforePersist(): void + { + $this->settings->set('Example.siteName', 'FileStoredBatch'); + + $deferredSettings = $this->createDeferredSettings(); + + $deferredSettings->setMany([ + 'Example.siteName' => 'FilePendingBatch', + ]); + + $this->assertSame('FilePendingBatch', $deferredSettings->get('Example.siteName')); + } + public function testDeferredSetManyPersistsDifferentClassesAfterPersist(): void { $deferredSettings = $this->createDeferredSettings();