Skip to content

Commit 103ce26

Browse files
committed
ISSUE-345: return 409
1 parent 253d39d commit 103ce26

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/Validator/UniqueEmailValidator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpList\RestBundle\Validator;
66

77
use PhpList\Core\Domain\Repository\Subscription\SubscriberRepository;
8+
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
89
use Symfony\Component\Validator\Constraint;
910
use Symfony\Component\Validator\ConstraintValidator;
1011
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -36,9 +37,7 @@ public function validate($value, Constraint $constraint): void
3637
$existingUser = $this->subscriberRepository->findOneBy(['email' => $value]);
3738

3839
if ($existingUser) {
39-
$this->context->buildViolation($constraint->message)
40-
->setParameter('{{ value }}', $value)
41-
->addViolation();
40+
throw new ConflictHttpException('Email already exists.');
4241
}
4342
}
4443
}

tests/Integration/Controller/AbstractTestController.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,11 @@ protected function assertHttpMethodNotAllowed(): void
240240
protected function assertHttpConflict(): void
241241
{
242242
$this->assertHttpStatusWithJsonContentType(Response::HTTP_CONFLICT);
243-
244-
self::assertSame(
245-
[
246-
'message' => 'This resource already exists.',
247-
],
248-
$this->getDecodedJsonResponseContent()
249-
);
243+
$data = $this->getDecodedJsonResponseContent();
244+
$this->assertArrayHasKey('message', $data);
245+
$this->assertIsString($data['message']);
246+
$this->assertNotEmpty($data['message']);
247+
$this->assertStringContainsString('already exists', $data['message']);
250248
}
251249

252250
/**

0 commit comments

Comments
 (0)