|
15 | 15 | use Attributes\Options as Options; |
16 | 16 | use Attributes\Options\Exceptions\InvalidOptionException; |
17 | 17 | use Attributes\Options\Ignore; |
| 18 | +use Attributes\Validation\Context; |
18 | 19 | use Attributes\Validation\Tests\Models as Models; |
19 | 20 | use Attributes\Validation\Validator; |
20 | 21 |
|
|
130 | 131 | $validator = new Validator(strict: $isStrict); |
131 | 132 | $rawData = [ |
132 | 133 | 'value' => 'my value', |
133 | | - 'ignore' => 'ignored', |
134 | | - 'ignoreValidation' => 'ignored', |
| 134 | + 'ignore' => 'both', |
| 135 | + 'ignoreValidation' => 'validation', |
| 136 | + 'ignoreSerialization' => 'serialization', |
135 | 137 | ]; |
136 | 138 | $model = $validator->validate($rawData, new class |
137 | 139 | { |
|
142 | 144 |
|
143 | 145 | #[Ignore(serialization: false)] |
144 | 146 | public string $ignoreValidation = 'original'; |
| 147 | + |
| 148 | + #[Ignore(validation: false)] |
| 149 | + public string $ignoreSerialization = 'original'; |
| 150 | + }); |
| 151 | + expect($model) |
| 152 | + ->toHaveProperty('value', 'my value') |
| 153 | + ->toHaveProperty('ignore', 'original') |
| 154 | + ->toHaveProperty('ignoreValidation', 'original') |
| 155 | + ->toHaveProperty('ignoreSerialization', 'serialization'); |
| 156 | +}) |
| 157 | + ->with([true, false]) |
| 158 | + ->group('validator', 'options', 'ignore'); |
| 159 | + |
| 160 | +test('Ignore as a serializer', function (bool $isStrict) { |
| 161 | + $context = new Context; |
| 162 | + $context->set('internal.options.ignore.useSerialization', true); |
| 163 | + $validator = new Validator(strict: $isStrict, context: $context); |
| 164 | + $rawData = [ |
| 165 | + 'value' => 'my value', |
| 166 | + 'ignore' => 'both', |
| 167 | + 'ignoreValidation' => 'validation', |
| 168 | + 'ignoreSerialization' => 'serialization', |
| 169 | + ]; |
| 170 | + $model = $validator->validate($rawData, new class |
| 171 | + { |
| 172 | + public string $value; |
| 173 | + |
| 174 | + #[Ignore] |
| 175 | + public string $ignore = 'original'; |
| 176 | + |
| 177 | + #[Ignore(serialization: false)] |
| 178 | + public string $ignoreValidation = 'original'; |
| 179 | + |
| 180 | + #[Ignore(validation: false)] |
| 181 | + public string $ignoreSerialization = 'original'; |
145 | 182 | }); |
146 | 183 | expect($model) |
147 | 184 | ->toHaveProperty('value', 'my value') |
148 | 185 | ->toHaveProperty('ignore', 'original') |
149 | | - ->toHaveProperty('ignoreValidation', 'original'); |
| 186 | + ->toHaveProperty('ignoreValidation', 'validation') |
| 187 | + ->toHaveProperty('ignoreSerialization', 'original'); |
150 | 188 | }) |
151 | 189 | ->with([true, false]) |
152 | 190 | ->group('validator', 'options', 'ignore'); |
0 commit comments