diff --git a/src/Progressable.php b/src/Progressable.php index 4fe078d..ccf0913 100644 --- a/src/Progressable.php +++ b/src/Progressable.php @@ -439,6 +439,11 @@ public function getLocalKey(): string { */ public function setLocalKey(string $name): static { $currentKey = $this->getLocalKey(); + + if ($name === $currentKey) { + return $this; + } + $overallProgressData = $this->getOverallProgressData(); if (isset($overallProgressData[$currentKey])) { diff --git a/tests/ProgressableTest.php b/tests/ProgressableTest.php index 5d3bb30..61d355f 100644 --- a/tests/ProgressableTest.php +++ b/tests/ProgressableTest.php @@ -594,4 +594,16 @@ public function test_to_array_without_unique_name(): void { 'current_step' => 5, ], $this->toArray()); } + + public function test_set_local_key_with_same_name_preserves_data(): void { + $this->setOverallUniqueName('test_local_key_preserves_data_'.$this->testId); + $this->setLocalProgress(50); + $before = $this->getOverallProgressData(); + + $key = $this->getLocalKey(); + $this->setLocalKey($key); + + $after = $this->getOverallProgressData(); + $this->assertEquals($before, $after); + } }