Skip to content

Commit

Permalink
Merge pull request #62 from aeviiq/storage-key
Browse files Browse the repository at this point in the history
Initialize form flow when the storage key is set.
  • Loading branch information
aeviiq authored Oct 30, 2020
2 parents e766711 + 81e8ec8 commit 7ee5fe2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/FormFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ public function getFormByStepNumber(int $stepNumber): FormInterface

public function setStorageKey(?string $storageKey): void
{
if (null !== $this->context) {
throw new LogicException(\sprintf('The storage key cannot be changed after the flow has context.'));
}

$this->storageKey = $storageKey;

$this->initialize();
}

public function getStorageKey(): string
Expand Down
9 changes: 9 additions & 0 deletions tests/FormFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ public function testGetStorageKey(): void
$this->assertSame(\sprintf(FormFlow::STORAGE_KEY_PREFIX, $flow->getName()), $flow->getStorageKey());
}

public function testGetStorageKeyWithContextPresent(): void
{
$flow = $this->createDefaultFormFlow();
$flow->start(new stdClass());
$this->expectException(LogicException::class);
$this->expectExceptionMessage('The storage key cannot be changed after the flow has context.');
$flow->setStorageKey('12345');
}

protected function setUp(): void
{
$this->mockedStorageManager = $this->createMock(StorageManagerInterface::class);
Expand Down

0 comments on commit 7ee5fe2

Please sign in to comment.