Skip to content

Commit

Permalink
Merge pull request #65 from aeviiq/63-submit-events-are-not-triggered…
Browse files Browse the repository at this point in the history
…-when-going-backwards

Ensure only the form that is inside the request is being handled.
  • Loading branch information
aeviiq authored Jul 5, 2021
2 parents 7c2de71 + 0d07c7d commit 15b0a25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Transitioner.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ private function createGroupListenerId(string $eventName, string $group): string

private function submitForm(FormInterface $form): void
{
if (!$form->isSubmitted()) {
$form->handleRequest($this->getHttpRequest());
$httpRequest = $this->getHttpRequest();
if ($httpRequest->request->has($form->getName()) && !$form->isSubmitted()) {
$form->handleRequest($httpRequest);
}
}

Expand Down
13 changes: 9 additions & 4 deletions tests/TransitionerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -211,7 +212,7 @@ public function testTransitionForwardWithInvalidForm(): void
$this->transitioner->forwards($this->flow);
}

public function testTransitionFormwardWithBlockedTransition(): void
public function testTransitionForwardWithBlockedTransition(): void
{
$this->setCurrentRequest($this->createHttpRequest('forwards'));
$this->setCurrentStepNumber(1);
Expand Down Expand Up @@ -472,6 +473,7 @@ private function setCurrentStepForm(bool $valid, bool $submitted): void
$form = $this->createStub(FormInterface::class);
$form->method('isValid')->willReturn($valid);
$form->method('isSubmitted')->willReturn($submitted);
$form->method('getName')->willReturn('form_name');

$this->flow->method('getCurrentStepForm')->willReturn($form);
}
Expand All @@ -483,10 +485,13 @@ private function setCurrentStepNumber(int $currentStep): void

private function createHttpRequest(string $action): HttpRequest
{
$request = $this->createMock(HttpRequest::class);
$request->method('get')->with('some-trans-key')->willReturn($action);
$httpRequest = $this->createMock(HttpRequest::class);
$httpRequest->method('get')->with('some-trans-key')->willReturn($action);
$request = $this->createMock(ParameterBag::class);
$request->method('has')->willReturn(true);
$httpRequest->request = $request;

return $request;
return $httpRequest;
}

private function assertFlowEvent(string $expectedInstance): Constraint
Expand Down

0 comments on commit 15b0a25

Please sign in to comment.