Skip to content

Commit

Permalink
Merge pull request #64 from aeviiq/dont-initialize-upon-creation
Browse files Browse the repository at this point in the history
Dont initialize upon creation
  • Loading branch information
aeviiq authored Jul 5, 2021
2 parents 7ee5fe2 + c71610d commit 7c2de71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/FormFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ public function __construct(
$this->storageManager = $storageManager;
$this->formFactory = $formFactory;
$this->definition = $definition;
$this->initialize();
}

public function isStarted(): bool
{
if (null === $this->context) {
$this->initialize();
}

return null !== $this->context;
}

Expand All @@ -74,7 +77,7 @@ public function start(object $data): void

public function getContext(): Context
{
if (null === $this->context) {
if (!$this->isStarted()) {
throw new LogicException('The flow is missing it\'s context. Did you FormFlow#start() the flow?');
}

Expand Down
6 changes: 4 additions & 2 deletions tests/FormFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function testInitialize(): void
$this->mockedStorageManager->expects(self::once())->method('load')
->with('form_flow.storage.form_flow')->willReturn($this->createStub(Context::class));

$this->createDefaultFormFlow();
$flow = $this->createDefaultFormFlow();
self::assertTrue($flow->isStarted());
}

public function testInitializeWithCorruptedContext(): void
Expand All @@ -52,7 +53,8 @@ public function testInitializeWithCorruptedContext(): void

$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('The stored context is corrupted.');
$this->createDefaultFormFlow();
$flow = $this->createDefaultFormFlow();
self::assertTrue($flow->isStarted());
}

public function testStartWhenFlowIsAlreadyStarted(): void
Expand Down

0 comments on commit 7c2de71

Please sign in to comment.