Skip to content

Commit

Permalink
Merge pull request #13 from acornforth/master
Browse files Browse the repository at this point in the history
Fix Bug in SourceValidator.php
  • Loading branch information
loevgaard authored Sep 6, 2019
2 parents 8c7cd0c + efd6ad7 commit 72daacf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions spec/Validator/Constraints/SourceValidatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Constraints/SourceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 72daacf

Please sign in to comment.