diff --git a/composer.json b/composer.json index 872b8b6..8efec18 100644 --- a/composer.json +++ b/composer.json @@ -30,9 +30,9 @@ "aeviiq/collection": "^3.2", "aeviiq/storage-manager": "^3.0", "aeviiq/enum": "^2.0", - "symfony/form": "^4.3", - "symfony/event-dispatcher": "^4.3", - "symfony/http-foundation": "^4.3" + "symfony/form": "^4.3|^5.0", + "symfony/http-foundation": "^4.3|^5.0", + "symfony/event-dispatcher-contracts": "^1.0|^2.0" }, "require-dev": { "phpunit/phpunit": "^8.2" diff --git a/src/Transitioner.php b/src/Transitioner.php index 61a266b..360aa3c 100644 --- a/src/Transitioner.php +++ b/src/Transitioner.php @@ -12,10 +12,10 @@ use Aeviiq\FormFlow\Event\TransitionEvent; use Aeviiq\FormFlow\Exception\LogicException; use Aeviiq\FormFlow\Exception\TransitionException; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request as HttpRequest; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; final class Transitioner implements TransitionerInterface, RequestStackAwareInterface { diff --git a/tests/TransitionerTest.php b/tests/TransitionerTest.php index 1ca6044..931cef4 100644 --- a/tests/TransitionerTest.php +++ b/tests/TransitionerTest.php @@ -20,13 +20,12 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\Constraint; -use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request as HttpRequest; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; final class TransitionerTest extends TestCase { @@ -123,10 +122,12 @@ public function testTransitionForwardsWithHardSkip(): void [$this->assertFlowEvent(TransitionedEvent::class), 'form_flow.post_forwards.group-1'], [$this->assertFlowEvent(TransitionedEvent::class), 'form_flow.post_forwards.some-name'], [$this->assertFlowEvent(TransitionedEvent::class), 'form_flow.post_forwards'] - )->willReturnCallback(static function (Event $event, string $eventName): void { + )->willReturnCallback(static function (Event $event, string $eventName): object { if ($event instanceof SkipEvent && 'form_flow.skip.some-name.step_1' === $eventName) { $event->hardSkip(); } + + return $event; }); $status = $this->transitioner->transition($this->flow); @@ -152,10 +153,12 @@ public function testTransitionForwardsWithSoftSkip(): void [$this->assertFlowEvent(TransitionedEvent::class), 'form_flow.post_forwards.group-1'], [$this->assertFlowEvent(TransitionedEvent::class), 'form_flow.post_forwards.some-name'], [$this->assertFlowEvent(TransitionedEvent::class), 'form_flow.post_forwards'] - )->willReturnCallback(static function (Event $event, string $eventName): void { + )->willReturnCallback(static function (Event $event, string $eventName): object { if ($event instanceof SkipEvent && 'form_flow.skip.some-name.step_1' === $eventName) { $event->softSkip(); } + + return $event; }); $status = $this->transitioner->transition($this->flow); @@ -174,11 +177,13 @@ public function testTransitionForwardWithHardAndSoftSkip(): void [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_forwards.some-name'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_forwards'], [$this->assertFlowEvent(SkipEvent::class), 'form_flow.skip.some-name.step_1'] - )->willReturnCallback(static function (Event $event, string $eventName): void { + )->willReturnCallback(static function (Event $event, string $eventName): object { if ($event instanceof SkipEvent && 'form_flow.skip.some-name.step_1' === $eventName) { $event->hardSkip(); $event->softSkip(); } + + return $event; }); $this->expectException(LogicException::class); @@ -217,8 +222,10 @@ public function testTransitionFormwardWithBlockedTransition(): void [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_forwards.group-1'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_forwards.some-name'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_forwards'] - )->willReturnCallback(static function (TransitionEvent $event): void { + )->willReturnCallback(static function (TransitionEvent $event): object { $event->blockTransition(); + + return $event; }); $status = $this->transitioner->transition($this->flow); @@ -271,8 +278,10 @@ public function testTransitionBackwardsWithBlockedTransition(): void [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_backwards.group-1'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_backwards.some-name'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_backwards'] - )->willReturnCallback(static function (TransitionEvent $event): void { + )->willReturnCallback(static function (TransitionEvent $event): object { $event->blockTransition(); + + return $event; }); $status = $this->transitioner->transition($this->flow); @@ -326,8 +335,10 @@ public function testTransitionCompleteWithBlockedTransition(): void [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_complete.group-1'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_complete.some-name'], [$this->assertFlowEvent(TransitionEvent::class), 'form_flow.pre_complete'] - )->willReturnCallback(static function (TransitionEvent $event): void { + )->willReturnCallback(static function (TransitionEvent $event): object { $event->blockTransition(); + + return $event; }); $status = $this->transitioner->transition($this->flow);