Skip to content

Commit 1e1ff3e

Browse files
committed
rename more stuff
1 parent 5b8af60 commit 1e1ff3e

11 files changed

+125
-12
lines changed

src/Type/ErrorType/ListOfValidationErrorType.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function __construct(array $config, array $path)
9696
*/
9797
protected function _validate(array $arg, mixed $value, array &$res, array $settings): void
9898
{
99-
$this->_validateListOfType($arg, $value, $res, [0]);
99+
$this->_validateListOfType($arg, $value, $res, [0], $settings);
100100
}
101101

102102
protected function _leafName(array $config): string
@@ -109,8 +109,9 @@ protected function _leafName(array $config): string
109109
* @param mixed[] $value
110110
* @param array<mixed> $res
111111
* @param Array<string|int> $path
112+
* @param ValidationSettings $settings
112113
*/
113-
protected function _validateListOfType(array $config, array $value, array &$res, array $path): void
114+
protected function _validateListOfType(array $config, array $value, array &$res, array $path, array $settings): void
114115
{
115116
$validate = $this->config[static::ITEMS_NAME]['validate'] ?? null;
116117
$wrappedType = $config['type']->getWrappedType();
@@ -125,15 +126,15 @@ protected function _validateListOfType(array $config, array $value, array &$res,
125126
// If the wrapped type is a list, recursively validate each item
126127
if ($wrappedType instanceof ListOfType) {
127128
$newPath = [...$path, 0]; // Append 0 for list path
128-
$this->_validateListOfType(['type' => $wrappedType, 'validate' => $validate], $subValue, $res, $newPath);
129+
$this->_validateListOfType(['type' => $wrappedType, 'validate' => $validate], $subValue, $res, $newPath, $settings);
129130
continue; // Skip to the next iteration
130131
}
131132

132133
// Validate scalar or complex types
133134
if (static::isScalarType($wrappedType)) {
134135
$err = static::_formatValidationResult($validate($subValue));
135136
} else {
136-
$err = $wrappedErrorType->validate(['type' => $wrappedType], $subValue);
137+
$err = $wrappedErrorType->validate(['type' => $wrappedType], $subValue, $settings);
137138
}
138139

139140
// Check for errors and add to results if necessary

src/Type/ErrorType/ValidatedFieldDefinition.php

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function __construct($field)
5454
$this->validFieldName = $field['validName'] ?? '_valid';
5555
$this->resultFieldName = $field['resultName'] ?? '_result';
5656

57-
5857
parent::__construct(array_merge([
5958
'validationMode' => $field['validationMode'] ?? 'full'
6059
], [

src/Type/ErrorType/ValidationErrorType.php

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public function validate(array $field, $value, array $settings): array
148148
* @param mixed $value
149149
* @param array<mixed> $res
150150
* @param ValidationSettings $settings
151+
*
152+
* @codeCoverageIgnore
151153
*/
152154
protected function _validate(array $arg, mixed $value, array &$res, array $settings): void
153155
{

tests/Exception/ValidateCallbackException.php renamed to tests/Exception/ValidateCallbackExceptionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use GraphQlPhpValidationToolkit\Tests\Type\TestBase;
1010
use GraphQlPhpValidationToolkit\Type\ErrorType\ValidationErrorType;
1111

12-
final class ValidateCallbackException extends TestBase
12+
final class ValidateCallbackExceptionTest extends TestBase
1313
{
1414
public function testIdThrows(): void
1515
{

tests/Type/Schema/ListOf.php renamed to tests/Type/Schema/ListOfTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum PersonErrorCode
1515
case unknownPerson;
1616
}
1717

18-
final class ListOf extends TestBase
18+
final class ListOfTest extends TestBase
1919
{
2020
public function testScalarTypeWithNoValidation(): void
2121
{

tests/Type/Schema/NonNull.php renamed to tests/Type/Schema/NonNullTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use GraphQlPhpValidationToolkit\Tests\Type\TestBase;
88
use GraphQlPhpValidationToolkit\Type\ErrorType\ValidationErrorType;
99

10-
final class NonNull extends TestBase
10+
final class NonNullTest extends TestBase
1111
{
1212
public function testStringWrappedType(): void
1313
{
+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace GraphQlPhpValidationToolkit\Tests\Type\Validation;
4+
5+
use GraphQL\GraphQL;
6+
use GraphQL\Type\Definition\ObjectType;
7+
use GraphQL\Type\Definition\Type;
8+
use GraphQL\Type\Schema;
9+
use GraphQlPhpValidationToolkit\Tests\Type\TestBase;
10+
use GraphQlPhpValidationToolkit\Tests\Utils;
11+
use GraphQlPhpValidationToolkit\Type\ErrorType\ValidatedFieldDefinition;
12+
use PHPUnit\Framework\Attributes\TestDox;
13+
use PHPUnit\Framework\TestCase;
14+
15+
16+
class MyValidatedFieldSubclass extends ValidatedFieldDefinition
17+
{
18+
19+
}
20+
21+
final class InferNameTest extends TestBase
22+
{
23+
/** @var Type */
24+
protected $bookType;
25+
26+
/** @var Type */
27+
protected $personType;
28+
29+
/** @var mixed[] */
30+
protected $books = [
31+
1 => [
32+
'title' => 'Where the Red Fern Grows',
33+
'author' => 1,
34+
],
35+
];
36+
37+
38+
#[TestDox("It validates a nullable scalar value")]
39+
public function testNullableScalarValidationOnNullValueSuccess(): void
40+
{
41+
$this->_checkValidation(
42+
new MyValidatedFieldSubclass([
43+
'type' => new ObjectType([
44+
'name' => 'Book',
45+
'fields' => [
46+
'title' => [
47+
'type' => Type::string(),
48+
'resolve' => static function ($book) {
49+
return $book['title'];
50+
},
51+
],
52+
'author' => [
53+
'type' => new ObjectType([
54+
'name' => 'Person',
55+
'fields' => [
56+
'firstName' => [
57+
'type' => Type::string(),
58+
],
59+
],
60+
]),
61+
'resolve' => static function ($book) {
62+
return $book['author'];
63+
},
64+
],
65+
],
66+
]),
67+
'args' => [
68+
'bookId' => [
69+
'type' => Type::id(),
70+
'validate' => function ($bookId) {
71+
if (isset($this->books[$bookId])) {
72+
return 0;
73+
}
74+
75+
return [1, 'Unknown book!'];
76+
},
77+
],
78+
],
79+
'resolve' => static function ($value): bool {
80+
return (bool)$value;
81+
},
82+
]),
83+
Utils::nowdoc('
84+
mutation UpdateBook(
85+
$bookId:ID
86+
) {
87+
myValidatedFieldSubclass(bookId: $bookId) {
88+
_valid
89+
bookId {
90+
_code
91+
_msg
92+
}
93+
_result {
94+
title
95+
}
96+
}
97+
}
98+
'),
99+
['bookId' => null],
100+
[
101+
'_valid' => false,
102+
'_result' => null,
103+
'bookId' => [
104+
'_code' => 1,
105+
'_msg' => 'Unknown book!',
106+
],
107+
]
108+
);
109+
}
110+
}

tests/Type/Validation/InputObjectValidation.php renamed to tests/Type/Validation/InputObjectValidationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use GraphQlPhpValidationToolkit\Tests\Utils;
1010
use GraphQlPhpValidationToolkit\Type\ErrorType\ValidatedFieldDefinition;
1111

12-
final class InputObjectValidation extends TestBase
12+
final class InputObjectValidationTest extends TestBase
1313
{
1414
/** @var mixed[] */
1515
protected $data = [

tests/Type/Validation/ListOfInputObjectValidation.php renamed to tests/Type/Validation/ListOfInputObjectValidationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use GraphQlPhpValidationToolkit\Tests\Utils;
1111
use GraphQlPhpValidationToolkit\Type\ErrorType\ValidatedFieldDefinition;
1212

13-
final class ListOfInputObjectValidation extends TestBase
13+
final class ListOfInputObjectValidationTest extends TestBase
1414
{
1515
/** @var mixed[] */
1616
protected $data = [

tests/Type/Validation/RequiredFieldsValidation.php renamed to tests/Type/Validation/RequiredFieldsValidationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum Animal
2121
case bird;
2222
}
2323

24-
final class RequiredFieldsValidation extends TestBase
24+
final class RequiredFieldsValidationTest extends TestBase
2525
{
2626
/** @var mixed[] */
2727
protected $data = [

tests/Type/Validation/ValidationMode.php renamed to tests/Type/Validation/ValidationModeTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php declare(strict_types=1);
22

3+
namespace GraphQlPhpValidationToolkit\Tests\Type\Validation\ValidationModeTest;
34

45
use GraphQL\Tests\Type\FieldDefinition;
56
use GraphQL\Type\Definition\InputObjectType;
@@ -24,7 +25,7 @@ enum Animal
2425
/**
2526
* Test the 'validationMode' config property
2627
*/
27-
final class ValidationMode extends TestBase
28+
final class ValidationModeTest extends TestBase
2829
{
2930
/** @var mixed[] */
3031
protected $data = [

0 commit comments

Comments
 (0)