Skip to content

Upgrade dependencies to prepare 5.0.0 release #60

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 10 commits into from
Oct 29, 2021
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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ matrix:
include:
# Test the latest stable release
- php: 7.2
- php: 7.4
- php: 8.0
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

# Test LTS versions.
- php: 7.4
- php: 8.0
env: DEPENDENCIES="symfony/lts:^4"

# Latest commit to master
- php: 7.4
- php: 8.0
env: STABILITY="dev"

allow_failures:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.4
- php: 8.0
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
Expand Down
21 changes: 0 additions & 21 deletions GraphqliteBundle.php

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/graphqlite-symfony-validator-bridge/badge.svg?branch=master&service=github)](https://coveralls.io/github/thecodingmachine/graphqlite-symfony-validator-bridge?branch=master)


# Graphqlite - Symfony validator bridge
# GraphQLite - Symfony validator bridge

A bridge between GraphQLite and the Symfony Validator component

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
],
"require" : {
"php" : ">=7.2",
"thecodingmachine/graphqlite" : "^4.1",
"symfony/validator": "^4 | ^5",
"thecodingmachine/graphqlite" : "^5.0",
"symfony/validator": "^4.2 | ^5",
"doctrine/annotations": "^1.6"
},
"require-dev": {
Expand All @@ -28,7 +28,7 @@
"phpstan/phpstan": "^0.12.14",
"php-coveralls/php-coveralls": "^2.1.0",
"symfony/translation": "^4",
"doctrine/coding-standard": "^7.0"
"doctrine/coding-standard": "^9.0"
},
"scripts": {
"phpstan": "phpstan analyse src/ -c phpstan.neon --level=7 --no-progress",
Expand All @@ -38,17 +38,17 @@
},
"autoload" : {
"psr-4" : {
"TheCodingMachine\\Graphqlite\\Validator\\" : "src/"
"TheCodingMachine\\GraphQLite\\Validator\\" : "src/"
}
},
"autoload-dev" : {
"psr-4" : {
"TheCodingMachine\\Graphqlite\\Validator\\" : "tests/"
"TheCodingMachine\\GraphQLite\\Validator\\" : "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "4.1.x-dev"
"dev-master": "5.0.x-dev"
}
},
"minimum-stability": "dev",
Expand Down
13 changes: 13 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@
<property name="enableNativeTypeHint" value="false"/>
</properties>
</rule>

<!-- Disable "mixed" type hints only available since PHP 8.0 -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<properties>
<property name="enableMixedTypeHint" value="false"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<property name="enableMixedTypeHint" value="false"/>
</properties>
</rule>
</ruleset>
5 changes: 3 additions & 2 deletions src/Annotations/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

declare(strict_types=1);

namespace TheCodingMachine\Graphqlite\Validator\Annotations;
namespace TheCodingMachine\GraphQLite\Validator\Annotations;

use BadMethodCallException;
use Symfony\Component\Validator\Constraint;
use TheCodingMachine\GraphQLite\Annotations\ParameterAnnotationInterface;

use function is_array;
use function ltrim;

Expand Down Expand Up @@ -41,7 +42,7 @@ public function __construct(array $values)
}

$this->for = ltrim($values['for'], '$');
$this->constraint = is_array($values['constraint']) ? $values['constraint'] : [ $values['constraint'] ];
$this->constraint = is_array($values['constraint']) ? $values['constraint'] : [$values['constraint']];
}

public function getTarget(): string
Expand Down
6 changes: 3 additions & 3 deletions src/ConstraintViolationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TheCodingMachine\Graphqlite\Validator;
namespace TheCodingMachine\GraphQLite\Validator;

use Exception;
use Symfony\Component\Validator\ConstraintViolationInterface;
Expand Down Expand Up @@ -46,12 +46,12 @@ public function getExtensions(): array
{
$extensions = [];
$code = $this->violation->getCode();
if ($code !== null) {
if (! empty($code)) {
$extensions['code'] = $code;
}

$propertyPath = $this->violation->getPropertyPath();
if ($propertyPath !== null) {
if (! empty($propertyPath)) {
Comment on lines +49 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$extensions['field'] = $propertyPath;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Mappers/Parameters/AssertParameterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TheCodingMachine\Graphqlite\Validator\Mappers\Parameters;
namespace TheCodingMachine\GraphQLite\Validator\Mappers\Parameters;

use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\Type;
Expand All @@ -15,7 +15,8 @@
use TheCodingMachine\GraphQLite\Mappers\Parameters\ParameterMiddlewareInterface;
use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface;
use TheCodingMachine\GraphQLite\Parameters\ParameterInterface;
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
use TheCodingMachine\GraphQLite\Validator\Annotations\Assertion;

use function array_map;
use function array_merge;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TheCodingMachine\Graphqlite\Validator\Mappers\Parameters;
namespace TheCodingMachine\GraphQLite\Validator\Mappers\Parameters;

use Exception;
use ReflectionParameter;
Expand Down
4 changes: 2 additions & 2 deletions src/Mappers/Parameters/ParameterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TheCodingMachine\Graphqlite\Validator\Mappers\Parameters;
namespace TheCodingMachine\GraphQLite\Validator\Mappers\Parameters;

use GraphQL\Type\Definition\InputType;
use GraphQL\Type\Definition\ResolveInfo;
Expand All @@ -12,7 +12,7 @@
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface;
use TheCodingMachine\Graphqlite\Validator\ValidationFailedException;
use TheCodingMachine\GraphQLite\Validator\ValidationFailedException;

class ParameterValidator implements InputTypeParameterInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/ValidationFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TheCodingMachine\Graphqlite\Validator;
namespace TheCodingMachine\GraphQLite\Validator;

use GraphQL\Error\ClientAware;
use InvalidArgumentException;
Expand Down
2 changes: 1 addition & 1 deletion tests/Annotations/AssertionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TheCodingMachine\Graphqlite\Validator\Annotations;
namespace TheCodingMachine\GraphQLite\Validator\Annotations;

use BadMethodCallException;
use PHPUnit\Framework\TestCase;
Expand Down
3 changes: 1 addition & 2 deletions tests/ConstraintValidationExceptionTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

namespace TheCodingMachine\Graphqlite\Validator;
namespace TheCodingMachine\GraphQLite\Validator;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

class ConstraintValidationExceptionTest extends TestCase
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Fixtures/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php


namespace TheCodingMachine\Graphqlite\Validator\Fixtures\Controllers;
namespace TheCodingMachine\GraphQLite\Validator\Fixtures\Controllers;


use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\Graphqlite\Validator\Fixtures\Types\User;
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
use TheCodingMachine\Graphqlite\Validator\ValidationFailedException;
use TheCodingMachine\GraphQLite\Validator\Fixtures\Types\User;
use TheCodingMachine\GraphQLite\Validator\Annotations\Assertion;
use TheCodingMachine\GraphQLite\Validator\ValidationFailedException;

class UserController
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/InvalidControllers/InvalidController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php


namespace TheCodingMachine\Graphqlite\Validator\Fixtures\InvalidControllers;
namespace TheCodingMachine\GraphQLite\Validator\Fixtures\InvalidControllers;


use GraphQL\Type\Definition\ResolveInfo;
use Symfony\Component\Validator\Constraints as Assert;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
use TheCodingMachine\GraphQLite\Validator\Annotations\Assertion;

class InvalidController
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Types/User.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace TheCodingMachine\Graphqlite\Validator\Fixtures\Types;
namespace TheCodingMachine\GraphQLite\Validator\Fixtures\Types;
use Symfony\Component\Validator\Constraints as Assert;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
Expand Down
32 changes: 13 additions & 19 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
<?php


namespace TheCodingMachine\Graphqlite\Validator;
namespace TheCodingMachine\GraphQLite\Validator;


use Doctrine\Common\Annotations\AnnotationReader;
use GraphQL\Error\Debug;
use GraphQL\Error\DebugFlag;
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
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;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorBuilder;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheCodingMachine\GraphQLite\Containers\BasicAutoWiringContainer;
use TheCodingMachine\GraphQLite\Containers\EmptyContainer;
use TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler;
use TheCodingMachine\GraphQLite\SchemaFactory;
use TheCodingMachine\Graphqlite\Validator\Fixtures\Controllers\UserController;
use TheCodingMachine\Graphqlite\Validator\Mappers\Parameters\AssertParameterMiddleware;
use TheCodingMachine\Graphqlite\Validator\Mappers\Parameters\InvalidAssertionAnnotationException;
use function var_dump;
use function var_export;
use const JSON_PRETTY_PRINT;
use TheCodingMachine\GraphQLite\Validator\Fixtures\Controllers\UserController;
use TheCodingMachine\GraphQLite\Validator\Mappers\Parameters\AssertParameterMiddleware;
use TheCodingMachine\GraphQLite\Validator\Mappers\Parameters\InvalidAssertionAnnotationException;

class IntegrationTest extends TestCase
{
Expand All @@ -51,8 +45,8 @@ private function getSchemaFactory(): SchemaFactory
]);

$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->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)));

return $schemaFactory;
Expand Down Expand Up @@ -83,7 +77,7 @@ public function testEndToEndThrowException(): void
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']);
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);

$errors = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['errors'];
$errors = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'];
$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']);
Expand Down Expand Up @@ -112,7 +106,7 @@ public function testEndToEndAssert(): void
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']);
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);

$errors = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['errors'];
$errors = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'];

// TODO: find why message is not in French...
$this->assertSame('This value is not a valid email address.', $errors[0]['message']);
Expand All @@ -135,7 +129,7 @@ public function testEndToEndAssert(): void
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']);
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);

$data = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['data'];
$data = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data'];
$this->assertSame('[email protected]', $data['findByMail']['email']);

// Test default parameter
Expand All @@ -154,19 +148,19 @@ public function testEndToEndAssert(): void
$result->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']);
$result->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']);

$data = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['data'];
$data = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data'];
$this->assertSame('[email protected]', $data['findByMail']['email']);

}

public function testException(): void
{
$schemaFactory = $this->getSchemaFactory();
$schemaFactory->addControllerNamespace('TheCodingMachine\Graphqlite\Validator\Fixtures\InvalidControllers');
$schemaFactory->addControllerNamespace('TheCodingMachine\GraphQLite\Validator\Fixtures\InvalidControllers');
$schema = $schemaFactory->createSchema();

$this->expectException(InvalidAssertionAnnotationException::class);
$this->expectExceptionMessage('In method TheCodingMachine\Graphqlite\Validator\Fixtures\InvalidControllers\InvalidController::invalid(), the @Assert annotation is targeting parameter "$resolveInfo". You cannot target this parameter because it is not part of the GraphQL Input type. You can only assert parameters coming from the end user.');
$this->expectExceptionMessage('In method TheCodingMachine\GraphQLite\Validator\Fixtures\InvalidControllers\InvalidController::invalid(), the @Assert annotation is targeting parameter "$resolveInfo". You cannot target this parameter because it is not part of the GraphQL Input type. You can only assert parameters coming from the end user.');
$schema->validate();
}
}
2 changes: 1 addition & 1 deletion tests/ValidationFailedExceptionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TheCodingMachine\Graphqlite\Validator;
namespace TheCodingMachine\GraphQLite\Validator;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\ConstraintViolation;
Expand Down