diff --git a/src/Theme/Infrastructure/ThemeSettingRepository.php b/src/Theme/Infrastructure/ThemeSettingRepository.php index 75b3658..fb81b39 100644 --- a/src/Theme/Infrastructure/ThemeSettingRepository.php +++ b/src/Theme/Infrastructure/ThemeSettingRepository.php @@ -228,15 +228,17 @@ protected function saveSettingValue(string $name, string $themeId, string $value 'value' => $value ]); - $queryBuilder->execute(); - - $this->eventDispatcher->dispatch( - new ThemeSettingChangedEvent( - $name, - $shopId, - $themeId - ) - ); + $result = $queryBuilder->execute(); + + if ($result !== 0) { + $this->eventDispatcher->dispatch( + new ThemeSettingChangedEvent( + $name, + $shopId, + $themeId + ) + ); + } } protected function saveSettingAsType(string $settingType, string $name, string $themeId, mixed $value): void diff --git a/tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php b/tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php index 887273d..d39e5b5 100644 --- a/tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php +++ b/tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php @@ -40,8 +40,10 @@ public function testSaveAndGetIntegerSetting(): void $sut->saveIntegerSetting($name, 124, 'awesomeTheme'); $integerResult = $sut->getInteger($name, 'awesomeTheme'); - $this->assertSame(124, $integerResult); + + // Check if dispatcher isn't executed again if value is the same + $sut->saveIntegerSetting($name, 124, 'awesomeTheme'); } public function testSaveAndGetFloatSetting(): void @@ -61,8 +63,10 @@ public function testSaveAndGetFloatSetting(): void $sut->saveFloatSetting($name, 1.24, 'awesomeTheme'); $floatResult = $sut->getFloat($name, 'awesomeTheme'); - $this->assertSame(1.24, $floatResult); + + // Check if dispatcher isn't executed again if value is the same + $sut->saveFloatSetting($name, 1.24, 'awesomeTheme'); } public function testSaveAndGetBooleanSetting(): void @@ -81,9 +85,11 @@ public function testSaveAndGetBooleanSetting(): void ); $sut->saveBooleanSetting($name, true, 'awesomeTheme'); - $floatResult = $sut->getBoolean($name, 'awesomeTheme'); + $booleanResult = $sut->getBoolean($name, 'awesomeTheme'); + $this->assertSame(true, $booleanResult); - $this->assertSame(true, $floatResult); + // Check if dispatcher isn't executed again if value is the same + $sut->saveBooleanSetting($name, true, 'awesomeTheme'); } public function testSaveAndGetStringSetting(): void @@ -103,8 +109,10 @@ public function testSaveAndGetStringSetting(): void $sut->saveStringSetting($name, 'new value', 'awesomeTheme'); $stringResult = $sut->getString($name, 'awesomeTheme'); - $this->assertSame('new value', $stringResult); + + // Check if dispatcher isn't executed again if value is the same + $sut->saveStringSetting($name, 'new value', 'awesomeTheme'); } public function testSaveAndGetSelectSetting(): void @@ -124,8 +132,10 @@ public function testSaveAndGetSelectSetting(): void $sut->saveSelectSetting($name, 'new select value', 'awesomeTheme'); $stringResult = $sut->getSelect($name, 'awesomeTheme'); - $this->assertSame('new select value', $stringResult); + + // Check if dispatcher isn't executed again if value is the same + $sut->saveSelectSetting($name, 'new select value', 'awesomeTheme'); } public function testSaveAndGetCollectionSetting(): void @@ -145,8 +155,10 @@ public function testSaveAndGetCollectionSetting(): void $sut->saveCollectionSetting($name, ['nice', 'cool', 'values'], 'awesomeTheme'); $collectionResult = $sut->getCollection($name, 'awesomeTheme'); - $this->assertSame(['nice', 'cool', 'values'], $collectionResult); + + // Check if dispatcher isn't executed again if value is the same + $sut->saveCollectionSetting($name, ['nice', 'cool', 'values'], 'awesomeTheme'); } public function testSaveAndGetAssocCollectionSetting(): void @@ -170,8 +182,14 @@ public function testSaveAndGetAssocCollectionSetting(): void 'awesomeTheme' ); $assocCollectionResult = $sut->getAssocCollection($name, 'awesomeTheme'); - $this->assertSame(['first' => '10', 'second' => '20', 'third' => '60'], $assocCollectionResult); + + // Check if dispatcher isn't executed again if value is the same + $sut->saveAssocCollectionSetting( + $name, + ['first' => '10', 'second' => '20', 'third' => '60'], + 'awesomeTheme' + ); } public function testGetSettingsList(): void