Skip to content

Commit

Permalink
Merge pull request #2 from moufmouf/symfony5
Browse files Browse the repository at this point in the history
Updating Validator to be usable with Symfony 5
  • Loading branch information
moufmouf authored Dec 2, 2019
2 parents 05a41fc + 4284f85 commit 631b39d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require" : {
"php" : ">=7.2",
"thecodingmachine/graphqlite" : "~4.0.0",
"symfony/validator": "^4.0",
"symfony/validator": "^4 | ^5",
"doctrine/annotations": "^1.6"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/ConstraintViolationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConstraintViolationException extends Exception implements GraphQLException

public function __construct(ConstraintViolationInterface $violation)
{
parent::__construct($violation->getMessage(), 400);
parent::__construct((string) $violation->getMessage(), 400);
$this->violation = $violation;
}

Expand Down
1 change: 0 additions & 1 deletion src/Mappers/Parameters/AssertParameterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use TheCodingMachine\GraphQLite\Mappers\Parameters\ParameterMiddlewareInterface;
use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface;
use TheCodingMachine\GraphQLite\Parameters\ParameterInterface;
use TheCodingMachine\Graphqlite\Validator\Annotations\Assert;
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
use function array_map;
use function array_merge;
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/Types/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class User
{
/**
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* message = "The email '{{ value }}' is not a valid email."
* )
*/
private $email;
Expand Down
9 changes: 6 additions & 3 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Mouf\Picotainer\Picotainer;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\Psr16Adapter;
use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\Cache\Simple\ArrayCache;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Validator\ContainerConstraintValidatorFactory;
Expand Down Expand Up @@ -47,7 +50,7 @@ private function getSchemaFactory(): SchemaFactory
}
]);

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

$queryString = '
mutation {
createUser(email: "foo@fgdjkerbrtehrthjker.com", password: "short") {
createUser(email: "foofgdjkerbrtehrthjker.com", password: "short") {
email
}
}
Expand All @@ -81,7 +84,7 @@ public function testEndToEndThrowException(): void
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);

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

0 comments on commit 631b39d

Please sign in to comment.