Skip to content

Updating Validator to be usable with Symfony 5 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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