@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | class Utils |
15 | 15 | { |
16 | - public static function nowdoc(string $str) : string |
|
16 | + public static function nowdoc (string $str) : string |
|
17 | 17 | { |
18 | 18 | $lines = preg_split('/\\n/', $str); |
19 | 19 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | // Toss out the first and last lines. |
29 | - $lines = array_slice($lines, 1, count($lines) - 2); |
|
29 | + $lines = array_slice($lines, 1, count($lines)-2); |
|
30 | 30 | |
31 | 31 | // take the tabs from the first line, and subtract them from all lines |
32 | 32 | $matches = []; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** @var Schema */ |
37 | 37 | protected $schema; |
38 | 38 | |
39 | - protected function setUp() |
|
39 | + protected function setUp () |
|
40 | 40 | { |
41 | 41 | $this->personType = new ObjectType([ |
42 | 42 | 'name' => 'Person', |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | 'fields' => [ |
56 | 56 | 'title' => [ |
57 | 57 | 'type' => Type::string(), |
58 | - 'resolve' => static function ($book) { |
|
58 | + 'resolve' => static function($book) { |
|
59 | 59 | return $book['title']; |
60 | 60 | }, |
61 | 61 | ], |
62 | 62 | 'author' => [ |
63 | 63 | 'type' => $this->personType, |
64 | - 'resolve' => static function ($book) { |
|
64 | + 'resolve' => static function($book) { |
|
65 | 65 | return $book['author']; |
66 | 66 | }, |
67 | 67 | ], |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $this->schema = new Schema([ |
72 | 72 | 'mutation' => new ObjectType([ |
73 | 73 | 'name' => 'Mutation', |
74 | - 'fields' => function () { |
|
74 | + 'fields' => function() { |
|
75 | 75 | return [ |
76 | 76 | 'updateBook' => new ValidatedFieldDefinition([ |
77 | 77 | 'name' => 'updateBook', |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | 'bookId' => [ |
81 | 81 | 'type' => Type::nonNull(Type::id()), |
82 | 82 | 'errorCodes' => ['bookNotFound'], |
83 | - 'validate' => function ($bookId) { |
|
83 | + 'validate' => function($bookId) { |
|
84 | 84 | if (isset($this->data['books'][$bookId])) { |
85 | 85 | return 0; |
86 | 86 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | }, |
90 | 90 | ], |
91 | 91 | ], |
92 | - 'resolve' => function ($value, $args) : array { |
|
92 | + 'resolve' => function($value, $args) : array { |
|
93 | 93 | return $this->data['books'][$args['bookId']]; |
94 | 94 | }, |
95 | 95 | ]), |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | ]); |
100 | 100 | } |
101 | 101 | |
102 | - public function testNonNullScalarValidationSuccess() |
|
102 | + public function testNonNullScalarValidationSuccess () |
|
103 | 103 | { |
104 | 104 | $res = GraphQL::executeQuery( |
105 | 105 | $this->schema, |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | static::assertTrue($res->data['updateBook']['valid']); |
130 | 130 | } |
131 | 131 | |
132 | - public function testNonNullScalarValidationFail() |
|
132 | + public function testNonNullScalarValidationFail () |
|
133 | 133 | { |
134 | 134 | $res = GraphQL::executeQuery( |
135 | 135 | $this->schema, |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | /** @var Schema */ |
25 | 25 | protected $schema; |
26 | 26 | |
27 | - protected function setUp() |
|
27 | + protected function setUp () |
|
28 | 28 | { |
29 | 29 | $this->query = new ObjectType(['name' => 'Query']); |
30 | 30 | $this->schema = new Schema([ |
31 | 31 | 'query' => $this->query, |
32 | 32 | 'mutation' => new ObjectType([ |
33 | 33 | 'name' => 'Mutation', |
34 | - 'fields' => static function () { |
|
34 | + 'fields' => static function() { |
|
35 | 35 | return [ |
36 | 36 | 'setPhoneNumbers' => new ValidatedFieldDefinition([ |
37 | 37 | 'name' => 'setPhoneNumbers', |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | 'phoneNumbers' => [ |
41 | 41 | 'type' => Type::listOf(Type::listOf(Type::string())), |
42 | 42 | 'errorCodes' => ['atLeastOneList'], |
43 | - 'validate' => static function (array $phoneNumberLists) { |
|
43 | + 'validate' => static function(array $phoneNumberLists) { |
|
44 | 44 | if (count($phoneNumberLists) < 1) { |
45 | 45 | return ['atLeastOneList', 'You must submit at least one list of numbers']; |
46 | 46 | } |
47 | 47 | return 0; |
48 | 48 | }, |
49 | 49 | 'suberrorCodes' => ['invalidPhoneNumber'], |
50 | - 'validateItem' => static function ($phoneNumber) { |
|
50 | + 'validateItem' => static function($phoneNumber) { |
|
51 | 51 | $res = preg_match('/^[0-9\-]+$/', $phoneNumber) === 1; |
52 | - return ! $res ? ['invalidPhoneNumber', 'That does not seem to be a valid phone number'] : 0; |
|
52 | + return !$res ? ['invalidPhoneNumber', 'That does not seem to be a valid phone number'] : 0; |
|
53 | 53 | }, |
54 | 54 | ], |
55 | 55 | ], |
56 | - 'resolve' => static function (array $phoneNumbers) : bool { |
|
57 | - return ! empty($phoneNumbers); |
|
56 | + 'resolve' => static function(array $phoneNumbers) : bool { |
|
57 | + return !empty($phoneNumbers); |
|
58 | 58 | }, |
59 | 59 | ]), |
60 | 60 | ]; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ]); |
64 | 64 | } |
65 | 65 | |
66 | - public function testItemsValidationOnWrappedTypeFail() |
|
66 | + public function testItemsValidationOnWrappedTypeFail () |
|
67 | 67 | { |
68 | 68 | $res = GraphQL::executeQuery( |
69 | 69 | $this->schema, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | [ |
107 | 107 | 'suberrors' => |
108 | 108 | [ |
109 | - 'path' => [0,1], |
|
109 | + 'path' => [0, 1], |
|
110 | 110 | 'code' => 'invalidPhoneNumber', |
111 | 111 | ], |
112 | 112 | ], |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | static::assertFalse($res->data['setPhoneNumbers']['valid']); |
121 | 121 | } |
122 | 122 | |
123 | - public function testItemsValidationOnSelfFail() |
|
123 | + public function testItemsValidationOnSelfFail () |
|
124 | 124 | { |
125 | 125 | $res = GraphQL::executeQuery( |
126 | 126 | $this->schema, |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | static::assertFalse($res->data['setPhoneNumbers']['valid']); |
173 | 173 | } |
174 | 174 | |
175 | - public function testListOfValidationFail() |
|
175 | + public function testListOfValidationFail () |
|
176 | 176 | { |
177 | 177 | $res = GraphQL::executeQuery( |
178 | 178 | $this->schema, |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** @var Schema */ |
42 | 42 | protected $schema; |
43 | 43 | |
44 | - protected function setUp() |
|
44 | + protected function setUp () |
|
45 | 45 | { |
46 | 46 | $this->personType = new ObjectType([ |
47 | 47 | 'name' => 'Person', |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'title' => [ |
62 | 62 | 'type' => Type::string(), |
63 | 63 | 'description' => 'Enter a book title, no more than 10 characters in length', |
64 | - 'validate' => static function (string $title) { |
|
64 | + 'validate' => static function(string $title) { |
|
65 | 65 | if (strlen($title) > 10) { |
66 | 66 | return [1, 'book title must be less than 10 chaacters']; |
67 | 67 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | 'unknownAuthor', |
76 | 76 | 'authorDeceased', |
77 | 77 | ], |
78 | - 'validate' => function (string $authorId) { |
|
79 | - if (! isset($this->data['people'][$authorId])) { |
|
78 | + 'validate' => function(string $authorId) { |
|
79 | + if (!isset($this->data['people'][$authorId])) { |
|
80 | 80 | return ['unknownAuthor', 'We have no record of that author']; |
81 | 81 | } |
82 | 82 | return 0; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | 'query' => $this->query, |
92 | 92 | 'mutation' => new ObjectType([ |
93 | 93 | 'name' => 'Mutation', |
94 | - 'fields' => function () { |
|
94 | + 'fields' => function() { |
|
95 | 95 | return [ |
96 | 96 | 'updateBook' => new ValidatedFieldDefinition([ |
97 | 97 | 'name' => 'updateBook', |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | 'bookAttributes' => [ |
101 | 101 | 'type' => $this->bookAttributesInputType, |
102 | 102 | 'errorCodes' => ['titleOrIdRequired'], |
103 | - 'validate' => static function (?array $bookAttributes) { |
|
103 | + 'validate' => static function(?array $bookAttributes) { |
|
104 | 104 | if (empty($bookAttributes)) { |
105 | 105 | return 0; |
106 | 106 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | }, |
113 | 113 | ], |
114 | 114 | ], |
115 | - 'resolve' => static function ($value) : bool { |
|
115 | + 'resolve' => static function($value) : bool { |
|
116 | 116 | // ... |
117 | 117 | // do update |
118 | 118 | // ... |
119 | 119 | |
120 | - return ! $value; |
|
120 | + return !$value; |
|
121 | 121 | }, |
122 | 122 | ]), |
123 | 123 | ]; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ]); |
127 | 127 | } |
128 | 128 | |
129 | - public function testValidationInputObjectFieldFail() |
|
129 | + public function testValidationInputObjectFieldFail () |
|
130 | 130 | { |
131 | 131 | $res = GraphQL::executeQuery( |
132 | 132 | $this->schema, |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | static::assertFalse($res->data['updateBook']['valid']); |
197 | 197 | } |
198 | 198 | |
199 | - public function testValidationInputObjectSelfFail() |
|
199 | + public function testValidationInputObjectSelfFail () |
|
200 | 200 | { |
201 | 201 | $res = GraphQL::executeQuery( |
202 | 202 | $this->schema, |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | static::assertFalse($res->data['updateBook']['valid']); |
259 | 259 | } |
260 | 260 | |
261 | - public function testValidationSuccess() |
|
261 | + public function testValidationSuccess () |
|
262 | 262 | { |
263 | 263 | $res = GraphQL::executeQuery( |
264 | 264 | $this->schema, |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | static::assertTrue($res->data['updateBook']['valid']); |
312 | 312 | } |
313 | 313 | |
314 | - public function testValidationEmptyInput() |
|
314 | + public function testValidationEmptyInput () |
|
315 | 315 | { |
316 | 316 | $res = GraphQL::executeQuery( |
317 | 317 | $this->schema, |
@@ -9,7 +9,6 @@ |
||
9 | 9 | use GraphQL\Type\Definition\InputObjectType; |
10 | 10 | use GraphQL\Type\Definition\ObjectType; |
11 | 11 | use GraphQL\Type\Definition\Type; |
12 | -use GraphQL\Type\Definition\UserErrorsType; |
|
13 | 12 | use GraphQL\Type\Definition\ValidatedFieldDefinition; |
14 | 13 | use GraphQL\Type\Schema; |
15 | 14 | use PHPUnit\Framework\TestCase; |
@@ -15,18 +15,18 @@ discard block |
||
15 | 15 | |
16 | 16 | final class ErrorCodeTypeGenerationTest extends TestCase |
17 | 17 | { |
18 | - public function testMultipleErrorCodesOnSelf() |
|
18 | + public function testMultipleErrorCodesOnSelf () |
|
19 | 19 | { |
20 | 20 | $types = []; |
21 | 21 | new UserErrorsType([ |
22 | - 'validate' => static function ($val) { |
|
22 | + 'validate' => static function($val) { |
|
23 | 23 | return $val ? 0 : 1; |
24 | 24 | }, |
25 | 25 | 'errorCodes' => [ |
26 | 26 | 'unknownUser', |
27 | 27 | 'userIsMinor', |
28 | 28 | ], |
29 | - 'typeSetter' => static function ($type) use (&$types) { |
|
29 | + 'typeSetter' => static function($type) use (&$types) { |
|
30 | 30 | $types[$type->name] = $type; |
31 | 31 | }, |
32 | 32 | 'type' => new IDType(['name' => 'User']), |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ); |
47 | 47 | } |
48 | 48 | |
49 | - public function testFieldsWithNoErrorCodes() |
|
49 | + public function testFieldsWithNoErrorCodes () |
|
50 | 50 | { |
51 | 51 | $types = []; |
52 | 52 | $type = new UserErrorsType([ |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ], |
60 | 60 | ], |
61 | 61 | ]), |
62 | - 'typeSetter' => static function ($type) use (&$types) { |
|
62 | + 'typeSetter' => static function($type) use (&$types) { |
|
63 | 63 | $types[$type->name] = $type; |
64 | 64 | }, |
65 | 65 | ], ['updateBook']); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ')); |
74 | 74 | } |
75 | 75 | |
76 | - public function testFieldsWithErrorCodes() |
|
76 | + public function testFieldsWithErrorCodes () |
|
77 | 77 | { |
78 | 78 | $types = []; |
79 | 79 | new UserErrorsType([ |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'name' => 'bookInput', |
82 | 82 | 'fields' => [ |
83 | 83 | 'authorId' => [ |
84 | - 'validate' => static function ($authorId) { |
|
84 | + 'validate' => static function($authorId) { |
|
85 | 85 | return $authorId ? 0 : 1; |
86 | 86 | }, |
87 | 87 | 'errorCodes' => ['unknownAuthor'], |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | ], |
91 | 91 | ], |
92 | 92 | ]), |
93 | - 'typeSetter' => static function ($type) use (&$types) { |
|
93 | + 'typeSetter' => static function($type) use (&$types) { |
|
94 | 94 | $types[$type->name] = $type; |
95 | 95 | }, |
96 | 96 | ], ['updateBook']); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | final class ScalarTest extends TestCase |
16 | 16 | { |
17 | - public function testNoValidation() |
|
17 | + public function testNoValidation () |
|
18 | 18 | { |
19 | 19 | $type = new UserErrorsType([ |
20 | 20 | 'type' => Type::id(), |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
34 | 34 | } |
35 | 35 | |
36 | - public function testWithValidation() |
|
36 | + public function testWithValidation () |
|
37 | 37 | { |
38 | 38 | $type = new UserErrorsType([ |
39 | 39 | 'errorCodes' => ['invalidColor'], |
40 | - 'validate' => static function ($value) { |
|
40 | + 'validate' => static function($value) { |
|
41 | 41 | return $value ? 0 : 1; |
42 | 42 | }, |
43 | 43 | 'type' => new IDType(['name' => 'Color']), |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | final class InputObjectTest extends TestCase |
17 | 17 | { |
18 | - public function testFieldsWithNoErrorCodes() |
|
18 | + public function testFieldsWithNoErrorCodes () |
|
19 | 19 | { |
20 | 20 | $type = new UserErrorsType([ |
21 | 21 | 'type' => new InputObjectType([ |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - public function testFieldsWithErrorCodesButNoValidate() |
|
48 | + public function testFieldsWithErrorCodesButNoValidate () |
|
49 | 49 | { |
50 | 50 | $this->expectExceptionMessage('If you specify errorCodes, you must also provide a validate callback'); |
51 | 51 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ], ['updateBook']); |
64 | 64 | } |
65 | 65 | |
66 | - public function testFieldsWithValidate() |
|
66 | + public function testFieldsWithValidate () |
|
67 | 67 | { |
68 | 68 | $type = new UserErrorsType([ |
69 | 69 | 'type' => new InputObjectType([ |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | 'fields' => [ |
72 | 72 | 'authorId' => [ |
73 | 73 | 'errorCodes' => ['unknownAuthor'], |
74 | - 'validate' => static function (int $authorId) { |
|
74 | + 'validate' => static function(int $authorId) { |
|
75 | 75 | return $authorId ? 0 : 1; |
76 | 76 | }, |
77 | 77 | 'type' => Type::id(), |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | final class ListOfTest extends TestCase |
17 | 17 | { |
18 | - public function testScalarTypeWithNoValidation() |
|
18 | + public function testScalarTypeWithNoValidation () |
|
19 | 19 | { |
20 | 20 | $type = new UserErrorsType([ |
21 | 21 | 'type' => Type::listOf(Type::id()), |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
35 | 35 | } |
36 | 36 | |
37 | - public function testListOfScalarWithValidationOnSelf() |
|
37 | + public function testListOfScalarWithValidationOnSelf () |
|
38 | 38 | { |
39 | 39 | $type = new UserErrorsType([ |
40 | 40 | 'type' => Type::listOf(Type::id()), |
41 | 41 | 'errorCodes'=> ['atLeastOneRequired'], |
42 | - 'validate' => static function ($value) { |
|
42 | + 'validate' => static function($value) { |
|
43 | 43 | return $value ? 0 : 1; |
44 | 44 | }, |
45 | 45 | ], ['users']); |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
67 | 67 | } |
68 | 68 | |
69 | - public function testListOfListOfListOfScalarWithValidationOnSelfAndWrappedType() |
|
69 | + public function testListOfListOfListOfScalarWithValidationOnSelfAndWrappedType () |
|
70 | 70 | { |
71 | 71 | $type = new UserErrorsType([ |
72 | 72 | 'type' => Type::listOf(Type::listOf(Type::listOf(Type::id()))), |
73 | 73 | 'errorCodes'=> ['atLeastOneRequired'], |
74 | - 'validate' => static function ($value) { |
|
74 | + 'validate' => static function($value) { |
|
75 | 75 | return $value ? 0 : 1; |
76 | 76 | }, |
77 | - 'validateItem' => static function ($value) { |
|
77 | + 'validateItem' => static function($value) { |
|
78 | 78 | return $value ? 0 : 1; |
79 | 79 | }, |
80 | 80 | ], ['users']); |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
117 | 117 | } |
118 | 118 | |
119 | - public function testListOfInputObjectWithValidationOnSelf() |
|
119 | + public function testListOfInputObjectWithValidationOnSelf () |
|
120 | 120 | { |
121 | 121 | $type = new UserErrorsType([ |
122 | - 'validate' => static function (array $authors) { |
|
122 | + 'validate' => static function(array $authors) { |
|
123 | 123 | if (count($authors) < 1) { |
124 | 124 | return ['atLeastOneAuthorRequired', 'You must submit at least one author']; |
125 | 125 | } |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
161 | 161 | } |
162 | 162 | |
163 | - public function testListOfInputObjectWithValidationOnWrappedSelf() |
|
163 | + public function testListOfInputObjectWithValidationOnWrappedSelf () |
|
164 | 164 | { |
165 | 165 | $type = new UserErrorsType([ |
166 | 166 | 'suberrorCodes' => ['firstNameOrLastNameRequired'], |
167 | - 'validateItem' => static function (array $author) { |
|
168 | - if (! isset($author['firstName']) && ! isset($author['lastName'])) { |
|
167 | + 'validateItem' => static function(array $author) { |
|
168 | + if (!isset($author['firstName']) && !isset($author['lastName'])) { |
|
169 | 169 | return ['atLeastOneAuthorRequired', 'You must submit a first name or a last name']; |
170 | 170 | } |
171 | 171 | }, |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | 'fields' => [ |
175 | 175 | 'firstName' => [ |
176 | 176 | 'type' => Type::string(), |
177 | - 'validate' => static function (string $name) { |
|
177 | + 'validate' => static function(string $name) { |
|
178 | 178 | return $name ? 0 : 1; |
179 | 179 | }, |
180 | 180 | ], |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | final class BasicTest extends TestCase |
15 | 15 | { |
16 | - public function testNoValidationOnSelf() |
|
16 | + public function testNoValidationOnSelf () |
|
17 | 17 | { |
18 | 18 | $type = new UserErrorsType([ |
19 | 19 | 'type' => Type::id(), |
@@ -32,20 +32,20 @@ discard block |
||
32 | 32 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
33 | 33 | } |
34 | 34 | |
35 | - public function testNoType() |
|
35 | + public function testNoType () |
|
36 | 36 | { |
37 | 37 | $this->expectExceptionMessage('You must specify a type for your field'); |
38 | 38 | UserErrorsType::create([ |
39 | - 'validate' => static function ($value) { |
|
39 | + 'validate' => static function($value) { |
|
40 | 40 | return $value ? 0 : 1; |
41 | 41 | }, |
42 | 42 | ], ['upsertSku']); |
43 | 43 | } |
44 | 44 | |
45 | - public function testValidationWithNoErrorCodes() |
|
45 | + public function testValidationWithNoErrorCodes () |
|
46 | 46 | { |
47 | 47 | $type = UserErrorsType::create([ |
48 | - 'validate' => static function ($value) { |
|
48 | + 'validate' => static function($value) { |
|
49 | 49 | return $value ? 0 : 1; |
50 | 50 | }, |
51 | 51 | 'type' => Type::id(), |