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(); 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();