diff --git a/spec/Validator/Constraints/SourceValidatorSpec.php b/spec/Validator/Constraints/SourceValidatorSpec.php index c2e4022..0cd9306 100644 --- a/spec/Validator/Constraints/SourceValidatorSpec.php +++ b/spec/Validator/Constraints/SourceValidatorSpec.php @@ -72,10 +72,14 @@ function it_does_not_add_violation_if_there_is_no_other_redirect( RedirectInterface $redirect, RedirectRepositoryInterface $redirectRepository ): void { + $source = '/dumb-source'; $redirect->isEnabled()->willReturn(true); - $redirect->getId()->willReturn(1); + $redirect->getSource()->willReturn($source); + $redirect->isEnabled()->shouldBeCalled(); + $redirect->getSource()->shouldBeCalled(); + $redirect->getId()->shouldBeCalled(); - $redirectRepository->findBy(['source' => $redirect, 'enabled' => true]) + $redirectRepository->findBy(['source' => $source, 'enabled' => true]) ->willReturn([$redirect]); $context->buildViolation(Argument::any())->shouldNotBeCalled(); @@ -90,11 +94,12 @@ function it_adds_a_violation_if_there_is_another_route_with_the_same_source( RedirectRepositoryInterface $redirectRepository, ConstraintViolationBuilderInterface $violationBuilder ): void { + $source = '/some-route'; $redirect->isEnabled()->willReturn(true); $redirect->getId()->willReturn(null); - $redirect->getSource()->willReturn('/some-route'); + $redirect->getSource()->willReturn($source); - $redirectRepository->findBy(['source' => $redirect, 'enabled' => true]) + $redirectRepository->findBy(['source' => $source, 'enabled' => true]) ->willReturn([$redirect, $conflictingRedirects]); $conflictingRedirects->getId()->willReturn(1); diff --git a/src/Validator/Constraints/SourceValidator.php b/src/Validator/Constraints/SourceValidator.php index 6dc08a9..2b3c683 100644 --- a/src/Validator/Constraints/SourceValidator.php +++ b/src/Validator/Constraints/SourceValidator.php @@ -44,7 +44,7 @@ public function validate($value, Constraint $constraint): void } /** @var RedirectInterface[] $conflictingRedirects */ - $conflictingRedirects = $this->redirectRepository->findBy(['source' => $value, 'enabled' => true]); + $conflictingRedirects = $this->redirectRepository->findBy(['source' => $value->getSource(), 'enabled' => true]); $conflictingRedirects = array_filter($conflictingRedirects, function (RedirectInterface $conflictingRedirect) use ($value): bool { return $conflictingRedirect->getId() !== $value->getId(); });