Skip to content

Commit 631b39d

Browse files
authored
Merge pull request #2 from moufmouf/symfony5
Updating Validator to be usable with Symfony 5
2 parents 05a41fc + 4284f85 commit 631b39d

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"require" : {
2020
"php" : ">=7.2",
2121
"thecodingmachine/graphqlite" : "~4.0.0",
22-
"symfony/validator": "^4.0",
22+
"symfony/validator": "^4 | ^5",
2323
"doctrine/annotations": "^1.6"
2424
},
2525
"require-dev": {

src/ConstraintViolationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ConstraintViolationException extends Exception implements GraphQLException
1515

1616
public function __construct(ConstraintViolationInterface $violation)
1717
{
18-
parent::__construct($violation->getMessage(), 400);
18+
parent::__construct((string) $violation->getMessage(), 400);
1919
$this->violation = $violation;
2020
}
2121

src/Mappers/Parameters/AssertParameterMiddleware.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use TheCodingMachine\GraphQLite\Mappers\Parameters\ParameterMiddlewareInterface;
1616
use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface;
1717
use TheCodingMachine\GraphQLite\Parameters\ParameterInterface;
18-
use TheCodingMachine\Graphqlite\Validator\Annotations\Assert;
1918
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
2019
use function array_map;
2120
use function array_merge;

tests/Fixtures/Types/User.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class User
1313
{
1414
/**
1515
* @Assert\Email(
16-
* message = "The email '{{ value }}' is not a valid email.",
17-
* checkMX = true
16+
* message = "The email '{{ value }}' is not a valid email."
1817
* )
1918
*/
2019
private $email;

tests/IntegrationTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Mouf\Picotainer\Picotainer;
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerInterface;
14+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
15+
use Symfony\Component\Cache\Adapter\Psr16Adapter;
16+
use Symfony\Component\Cache\Psr16Cache;
1417
use Symfony\Component\Cache\Simple\ArrayCache;
1518
use Symfony\Component\Translation\Translator;
1619
use Symfony\Component\Validator\ContainerConstraintValidatorFactory;
@@ -47,7 +50,7 @@ private function getSchemaFactory(): SchemaFactory
4750
}
4851
]);
4952

50-
$schemaFactory = new SchemaFactory(new ArrayCache(), new BasicAutoWiringContainer($container));
53+
$schemaFactory = new SchemaFactory(new Psr16Cache(new ArrayAdapter()), new BasicAutoWiringContainer($container));
5154
$schemaFactory->addControllerNamespace('TheCodingMachine\Graphqlite\Validator\Fixtures\Controllers');
5255
$schemaFactory->addTypeNamespace('TheCodingMachine\Graphqlite\Validator\Fixtures\Types');
5356
$schemaFactory->addParameterMiddleware(new AssertParameterMiddleware(new ContainerConstraintValidatorFactory($container), $container->get(ValidatorInterface::class), $container->get(TranslatorInterface::class)));
@@ -67,7 +70,7 @@ public function testEndToEndThrowException(): void
6770

6871
$queryString = '
6972
mutation {
70-
createUser(email: "foo@fgdjkerbrtehrthjker.com", password: "short") {
73+
createUser(email: "foofgdjkerbrtehrthjker.com", password: "short") {
7174
email
7275
}
7376
}
@@ -81,7 +84,7 @@ public function testEndToEndThrowException(): void
8184
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);
8285

8386
$errors = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['errors'];
84-
$this->assertSame('The email \'"foo@fgdjkerbrtehrthjker.com"\' is not a valid email.', $errors[0]['message']);
87+
$this->assertSame('The email \'"foofgdjkerbrtehrthjker.com"\' is not a valid email.', $errors[0]['message']);
8588
$this->assertSame('email', $errors[0]['extensions']['field']);
8689
$this->assertSame('Validate', $errors[0]['extensions']['category']);
8790
$this->assertSame('This value is too short. It should have 8 characters or more.', $errors[1]['message']);

0 commit comments

Comments
 (0)