1
1
<?php
2
2
3
3
4
- namespace TheCodingMachine \Graphqlite \Validator ;
4
+ namespace TheCodingMachine \GraphQLite \Validator ;
5
5
6
6
7
7
use Doctrine \Common \Annotations \AnnotationReader ;
8
- use GraphQL \Error \Debug ;
8
+ use GraphQL \Error \DebugFlag ;
9
9
use GraphQL \GraphQL ;
10
10
use GraphQL \Type \Schema ;
11
11
use Mouf \Picotainer \Picotainer ;
12
12
use PHPUnit \Framework \TestCase ;
13
13
use Psr \Container \ContainerInterface ;
14
14
use Symfony \Component \Cache \Adapter \ArrayAdapter ;
15
- use Symfony \Component \Cache \Adapter \Psr16Adapter ;
16
15
use Symfony \Component \Cache \Psr16Cache ;
17
- use Symfony \Component \Cache \Simple \ArrayCache ;
18
16
use Symfony \Component \Translation \Translator ;
19
17
use Symfony \Component \Validator \ContainerConstraintValidatorFactory ;
20
18
use Symfony \Component \Validator \Validator \ValidatorInterface ;
21
19
use Symfony \Component \Validator \ValidatorBuilder ;
22
20
use Symfony \Contracts \Translation \TranslatorInterface ;
23
21
use TheCodingMachine \GraphQLite \Containers \BasicAutoWiringContainer ;
24
- use TheCodingMachine \GraphQLite \Containers \EmptyContainer ;
25
22
use TheCodingMachine \GraphQLite \Exceptions \WebonyxErrorHandler ;
26
23
use TheCodingMachine \GraphQLite \SchemaFactory ;
27
- use TheCodingMachine \Graphqlite \Validator \Fixtures \Controllers \UserController ;
28
- use TheCodingMachine \Graphqlite \Validator \Mappers \Parameters \AssertParameterMiddleware ;
29
- use TheCodingMachine \Graphqlite \Validator \Mappers \Parameters \InvalidAssertionAnnotationException ;
30
- use function var_dump ;
31
- use function var_export ;
32
- use const JSON_PRETTY_PRINT ;
24
+ use TheCodingMachine \GraphQLite \Validator \Fixtures \Controllers \UserController ;
25
+ use TheCodingMachine \GraphQLite \Validator \Mappers \Parameters \AssertParameterMiddleware ;
26
+ use TheCodingMachine \GraphQLite \Validator \Mappers \Parameters \InvalidAssertionAnnotationException ;
33
27
34
28
class IntegrationTest extends TestCase
35
29
{
@@ -51,8 +45,8 @@ private function getSchemaFactory(): SchemaFactory
51
45
]);
52
46
53
47
$ schemaFactory = new SchemaFactory (new Psr16Cache (new ArrayAdapter ()), new BasicAutoWiringContainer ($ container ));
54
- $ schemaFactory ->addControllerNamespace ('TheCodingMachine\Graphqlite \Validator\Fixtures\Controllers ' );
55
- $ schemaFactory ->addTypeNamespace ('TheCodingMachine\Graphqlite \Validator\Fixtures\Types ' );
48
+ $ schemaFactory ->addControllerNamespace ('TheCodingMachine\GraphQLite \Validator\Fixtures\Controllers ' );
49
+ $ schemaFactory ->addTypeNamespace ('TheCodingMachine\GraphQLite \Validator\Fixtures\Types ' );
56
50
$ schemaFactory ->addParameterMiddleware (new AssertParameterMiddleware (new ContainerConstraintValidatorFactory ($ container ), $ container ->get (ValidatorInterface::class), $ container ->get (TranslatorInterface::class)));
57
51
58
52
return $ schemaFactory ;
@@ -83,7 +77,7 @@ public function testEndToEndThrowException(): void
83
77
$ result ->setErrorsHandler ([WebonyxErrorHandler::class, 'errorHandler ' ]);
84
78
$ result ->setErrorFormatter ([WebonyxErrorHandler::class, 'errorFormatter ' ]);
85
79
86
- $ errors = $ result ->toArray (Debug ::RETHROW_UNSAFE_EXCEPTIONS )['errors ' ];
80
+ $ errors = $ result ->toArray (DebugFlag ::RETHROW_UNSAFE_EXCEPTIONS )['errors ' ];
87
81
$ this ->assertSame ('The email \'"foofgdjkerbrtehrthjker.com" \' is not a valid email. ' , $ errors [0 ]['message ' ]);
88
82
$ this ->assertSame ('email ' , $ errors [0 ]['extensions ' ]['field ' ]);
89
83
$ this ->assertSame ('Validate ' , $ errors [0 ]['extensions ' ]['category ' ]);
@@ -112,7 +106,7 @@ public function testEndToEndAssert(): void
112
106
$ result ->setErrorsHandler ([WebonyxErrorHandler::class, 'errorHandler ' ]);
113
107
$ result ->setErrorFormatter ([WebonyxErrorHandler::class, 'errorFormatter ' ]);
114
108
115
- $ errors = $ result ->toArray (Debug ::RETHROW_UNSAFE_EXCEPTIONS )['errors ' ];
109
+ $ errors = $ result ->toArray (DebugFlag ::RETHROW_UNSAFE_EXCEPTIONS )['errors ' ];
116
110
117
111
// TODO: find why message is not in French...
118
112
$ this ->assertSame ('This value is not a valid email address. ' , $ errors [0 ]['message ' ]);
@@ -135,7 +129,7 @@ public function testEndToEndAssert(): void
135
129
$ result ->setErrorsHandler ([WebonyxErrorHandler::class, 'errorHandler ' ]);
136
130
$ result ->setErrorFormatter ([WebonyxErrorHandler::class, 'errorFormatter ' ]);
137
131
138
- $ data = $ result ->toArray (Debug ::RETHROW_UNSAFE_EXCEPTIONS )['data ' ];
132
+ $ data = $ result ->toArray (DebugFlag ::RETHROW_UNSAFE_EXCEPTIONS )['data ' ];
139
133
$ this ->
assertSame (
'[email protected] ' ,
$ data[
'findByMail ' ][
'email ' ]);
140
134
141
135
// Test default parameter
@@ -154,19 +148,19 @@ public function testEndToEndAssert(): void
154
148
$ result ->setErrorsHandler ([WebonyxErrorHandler::class, 'errorHandler ' ]);
155
149
$ result ->setErrorFormatter ([WebonyxErrorHandler::class, 'errorFormatter ' ]);
156
150
157
- $ data = $ result ->toArray (Debug ::RETHROW_UNSAFE_EXCEPTIONS )['data ' ];
151
+ $ data = $ result ->toArray (DebugFlag ::RETHROW_UNSAFE_EXCEPTIONS )['data ' ];
158
152
$ this ->
assertSame (
'[email protected] ' ,
$ data[
'findByMail ' ][
'email ' ]);
159
153
160
154
}
161
155
162
156
public function testException (): void
163
157
{
164
158
$ schemaFactory = $ this ->getSchemaFactory ();
165
- $ schemaFactory ->addControllerNamespace ('TheCodingMachine\Graphqlite \Validator\Fixtures\InvalidControllers ' );
159
+ $ schemaFactory ->addControllerNamespace ('TheCodingMachine\GraphQLite \Validator\Fixtures\InvalidControllers ' );
166
160
$ schema = $ schemaFactory ->createSchema ();
167
161
168
162
$ this ->expectException (InvalidAssertionAnnotationException::class);
169
- $ 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. ' );
163
+ $ 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. ' );
170
164
$ schema ->validate ();
171
165
}
172
166
}
0 commit comments