|
14 | 14 | namespace Chevere\Tests; |
15 | 15 |
|
16 | 16 | use BadMethodCallException; |
| 17 | +use Chevere\Parameter\Attributes\_int; |
17 | 18 | use Chevere\Parameter\Exceptions\ParameterException; |
18 | 19 | use Chevere\Parameter\Exceptions\ReturnException; |
19 | 20 | use Chevere\Parameter\Interfaces\ParametersAccessInterface; |
20 | 21 | use Chevere\Parameter\Interfaces\ParametersInterface; |
| 22 | +use Chevere\Tests\src\CallableClassMethod; |
21 | 23 | use InvalidArgumentException; |
22 | 24 | use LogicException; |
23 | 25 | use OutOfBoundsException; |
@@ -480,6 +482,41 @@ public function testValidatedFunction(): void |
480 | 482 | validated($function, 100, 1, 'Test'); // base, times, name |
481 | 483 | } |
482 | 484 |
|
| 485 | + public static function dataProviderValidatedCallables(): array |
| 486 | + { |
| 487 | + $object = new class() { |
| 488 | + public function main(#[_int(min: 10)] int $base): void |
| 489 | + { |
| 490 | + } |
| 491 | + }; |
| 492 | + |
| 493 | + return [ |
| 494 | + [ |
| 495 | + fn (#[_int(min: 10)] int $base) => null, |
| 496 | + ], |
| 497 | + ['Chevere\Tests\src\intMin10'], |
| 498 | + [[CallableClassMethod::class, 'main']], |
| 499 | + [[$object, 'main']], |
| 500 | + [new class() { |
| 501 | + public function __invoke(#[_int(min: 10)] int $base): void |
| 502 | + { |
| 503 | + } |
| 504 | + }], |
| 505 | + ]; |
| 506 | + } |
| 507 | + |
| 508 | + #[DataProvider('dataProviderValidatedCallables')] |
| 509 | + public function testValidatedCallables(callable $callable): void |
| 510 | + { |
| 511 | + $this->expectException(ParameterException::class); |
| 512 | + $this->expectExceptionMessage( |
| 513 | + <<<PLAIN |
| 514 | + InvalidArgumentException → [base]: Argument value provided `9` is less than `10` |
| 515 | + PLAIN |
| 516 | + ); |
| 517 | + validated($callable, 9); |
| 518 | + } |
| 519 | + |
483 | 520 | #[DataProvider('dataProviderValMd')] |
484 | 521 | public function testValMd(mixed $value, string $expects): void |
485 | 522 | { |
|
0 commit comments