Skip to content

Commit a73f2eb

Browse files
committed
Switching from @Assert to @assertion
1 parent f9f5b6c commit a73f2eb

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

src/Annotations/Assert.php renamed to src/Annotations/Assertion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @Attribute("constraint", type = "Symfony\Component\Validator\Constraint[]|Symfony\Component\Validator\Constraint")
2121
* })
2222
*/
23-
class Assert implements ParameterAnnotationInterface
23+
class Assertion implements ParameterAnnotationInterface
2424
{
2525
/** @var string */
2626
private $for;

src/Mappers/Parameters/AssertParameterMiddleware.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use TheCodingMachine\GraphQLite\Parameters\InputTypeParameterInterface;
1717
use TheCodingMachine\GraphQLite\Parameters\ParameterInterface;
1818
use TheCodingMachine\Graphqlite\Validator\Annotations\Assert;
19+
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
1920
use function array_map;
2021
use function array_merge;
2122

@@ -40,12 +41,12 @@ public function __construct(ConstraintValidatorFactoryInterface $constraintValid
4041

4142
public function mapParameter(ReflectionParameter $refParameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface
4243
{
43-
/** @var Assert[] $assertAnnotations */
44-
$assertAnnotations = $parameterAnnotations->getAnnotationsByType(Assert::class);
44+
/** @var Assertion[] $assertionAnnotations */
45+
$assertionAnnotations = $parameterAnnotations->getAnnotationsByType(Assertion::class);
4546

4647
$parameter = $next->mapParameter($refParameter, $docBlock, $paramTagType, $parameterAnnotations);
4748

48-
if (empty($assertAnnotations)) {
49+
if (empty($assertionAnnotations)) {
4950
return $parameter;
5051
}
5152

@@ -54,9 +55,9 @@ public function mapParameter(ReflectionParameter $refParameter, DocBlock $docBlo
5455
}
5556

5657
// Let's wrap the ParameterInterface into a ParameterValidator.
57-
$recursiveConstraints = array_map(static function (Assert $assertAnnotation) {
58+
$recursiveConstraints = array_map(static function (Assertion $assertAnnotation) {
5859
return $assertAnnotation->getConstraint();
59-
}, $assertAnnotations);
60+
}, $assertionAnnotations);
6061
$constraints = array_merge(...$recursiveConstraints);
6162

6263
return new ParameterValidator($parameter, $refParameter->getName(), $constraints, $this->constraintValidatorFactory, $this->validator, $this->translator);

tests/Annotations/AssertTest.php renamed to tests/Annotations/AssertionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
use BadMethodCallException;
66
use PHPUnit\Framework\TestCase;
77

8-
class AssertTest extends TestCase
8+
class AssertionTest extends TestCase
99
{
1010

1111
public function testException1()
1212
{
1313
$this->expectException(BadMethodCallException::class);
1414
$this->expectExceptionMessage('The @Assert annotation must be passed a target. For instance: "@Assert(for="$email", constraint=@Email)"');
15-
new Assert([]);
15+
new Assertion([]);
1616
}
1717

1818
public function testException2()
1919
{
2020
$this->expectException(BadMethodCallException::class);
2121
$this->expectExceptionMessage('The @Assert annotation must be passed one or many constraints. For instance: "@Assert(for="$email", constraint=@Email)"');
22-
new Assert(['for'=>'foo']);
22+
new Assertion(['for'=>'foo']);
2323
}
2424
}

tests/Fixtures/Controllers/UserController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
namespace TheCodingMachine\Graphqlite\Validator\Fixtures\Controllers;
55

66

7-
use Symfony\Component\Validator\Constraints as Assertion;
7+
use Symfony\Component\Validator\Constraints as Assert;
88
use Symfony\Component\Validator\Validator\ValidatorInterface;
99
use TheCodingMachine\GraphQLite\Annotations\Mutation;
1010
use TheCodingMachine\GraphQLite\Annotations\Query;
1111
use TheCodingMachine\Graphqlite\Validator\Fixtures\Types\User;
12-
use TheCodingMachine\Graphqlite\Validator\Annotations\Assert;
12+
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
1313
use TheCodingMachine\Graphqlite\Validator\ValidationFailedException;
1414

1515
class UserController
@@ -40,7 +40,7 @@ public function createUser(string $email, string $password): User
4040

4141
/**
4242
* @Query
43-
* @Assert(for="email", constraint=@Assertion\Email())
43+
* @Assertion(for="email", constraint=@Assert\Email())
4444
*/
4545
public function findByMail(string $email = '[email protected]'): User
4646
{

tests/Fixtures/InvalidControllers/InvalidController.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55

66

77
use GraphQL\Type\Definition\ResolveInfo;
8-
use Symfony\Component\Validator\Constraints as Assertion;
9-
use Symfony\Component\Validator\Validator\ValidatorInterface;
10-
use TheCodingMachine\GraphQLite\Annotations\Mutation;
8+
use Symfony\Component\Validator\Constraints as Assert;
119
use TheCodingMachine\GraphQLite\Annotations\Query;
12-
use TheCodingMachine\Graphqlite\Validator\Annotations\Assert;
13-
use TheCodingMachine\Graphqlite\Validator\ValidationFailedException;
10+
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
1411

1512
class InvalidController
1613
{
1714
/**
1815
* @Query
19-
* @Assert(for="$resolveInfo", constraint=@Assertion\Email())
16+
* @Assertion(for="$resolveInfo", constraint=@Assert\Email())
2017
*/
2118
public function invalid(ResolveInfo $resolveInfo): string
2219
{

0 commit comments

Comments
 (0)