diff --git a/src/EventListener/StateChangeRequestListener.php b/src/EventListener/StateChangeRequestListener.php index aeb365e..ec5cc56 100644 --- a/src/EventListener/StateChangeRequestListener.php +++ b/src/EventListener/StateChangeRequestListener.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpKernel\Event\RequestEvent; use Tienvx\Bundle\PactProviderBundle\Exception\BadMethodCallException; use Tienvx\Bundle\PactProviderBundle\Exception\BadRequestException; +use Tienvx\Bundle\PactProviderBundle\Exception\NoHandlerForStateException; class StateChangeRequestListener { @@ -35,6 +36,9 @@ public function __invoke(RequestEvent $event): void if (!in_array($action, [self::SETUP_ACTION, self::TEARDOWN_ACTION])) { throw new BadRequestException(sprintf("Action '%s' is not supported in state change request.", $action)); } + if (!$this->locator->has($state)) { + throw new NoHandlerForStateException(sprintf("No handler for state '%s'.", $state)); + } $handler = $this->locator->get($state); $method = [$handler, self::METHODS[$action]]; if (!is_callable($method)) { diff --git a/src/Exception/NoHandlerForStateException.php b/src/Exception/NoHandlerForStateException.php new file mode 100644 index 0000000..8e709c3 --- /dev/null +++ b/src/Exception/NoHandlerForStateException.php @@ -0,0 +1,7 @@ +