66use DMT \CommandBus \Validator \ValidationMiddleware ;
77use DMT \Test \CommandBus \Fixtures \AnnotationReaderCommand ;
88use DMT \Test \CommandBus \Fixtures \ClassMetadataCommand ;
9- use Doctrine \ Common \ Annotations \ AnnotationException ;
9+ use PHPUnit \ Framework \ Attributes \ DataProvider ;
1010use PHPUnit \Framework \TestCase ;
11+ use stdClass ;
1112use Symfony \Component \Validator \ConstraintViolation ;
1213use Symfony \Component \Validator \ConstraintViolationList ;
1314use Symfony \Component \Validator \Validator \ValidatorInterface ;
1920 */
2021class ValidationMiddlewareTest extends TestCase
2122{
22- /**
23- * @throws \ReflectionException
24- * @throws AnnotationException
25- */
26- public function testValidCommand ()
23+ public function testValidCommand (): void
2724 {
28- $ validator = static ::getMockForAbstractClass (ValidatorInterface::class);
25+ /** @var ValidatorInterface $validator */
26+ $ validator = static ::getMockBuilder (ValidatorInterface::class)->getMock ();
2927 $ validator ->expects (static ::once ())
3028 ->method ('validate ' )
3129 ->willReturn (new ConstraintViolationList ());
@@ -43,10 +41,7 @@ function ($command) {
4341 static ::assertSame ($ expected , $ result );
4442 }
4543
46- /**
47- * @throws AnnotationException
48- */
49- public function testLoadClassMetadataValidator ()
44+ public function testLoadClassMetadataValidator (): void
5045 {
5146 $ this ->expectException (ValidationException::class);
5247 $ this ->expectExceptionMessageMatches ("~Invalid command .* given~ " );
@@ -55,10 +50,7 @@ public function testLoadClassMetadataValidator()
5550 $ middleware ->execute (new ClassMetadataCommand (), 'gettype ' );
5651 }
5752
58- /**
59- * @throws AnnotationException
60- */
61- public function testAnnotationReaderValidator ()
53+ public function testAnnotationReaderValidator (): void
6254 {
6355 $ this ->expectException (ValidationException::class);
6456 $ this ->expectExceptionMessageMatches ("~Invalid command .* given~ " );
@@ -67,25 +59,19 @@ public function testAnnotationReaderValidator()
6759 $ middleware ->execute (new AnnotationReaderCommand (), 'gettype ' );
6860 }
6961
70- /**
71- * @dataProvider provideConstraintViolations
72- *
73- * @param ConstraintViolationList $violations
74- *
75- * @throws \ReflectionException
76- * @throws AnnotationException
77- */
78- public function testInvalidCommand (ConstraintViolationList $ violations )
62+ #[DataProvider(methodName: "provideConstraintViolations " )]
63+ public function testInvalidCommand (ConstraintViolationList $ violations ): void
7964 {
80- $ validator = static ::getMockForAbstractClass (ValidatorInterface::class);
65+ /** @var ValidatorInterface $validator */
66+ $ validator = static ::getMockBuilder (ValidatorInterface::class)->getMock ();
8167 $ validator ->expects (static ::once ())
8268 ->method ('validate ' )
8369 ->willReturn ($ violations );
8470
8571 try {
8672 $ middleware = new ValidationMiddleware ($ validator );
8773 $ middleware ->execute (
88- new \ stdClass (),
74+ new stdClass (),
8975 function ($ command ) {
9076 return $ command ;
9177 }
@@ -95,20 +81,20 @@ function ($command) {
9581 }
9682 }
9783
98- public function provideConstraintViolations (): array
84+ public static function provideConstraintViolations (): array
9985 {
10086 return [
10187 [
10288 new ConstraintViolationList (
103- [new ConstraintViolation ('missing property $foo ' , null , ['foo ' ], new \ StdClass (), 'foo ' , null )]
89+ [new ConstraintViolation ('missing property $foo ' , null , ['foo ' ], new stdClass (), 'foo ' , null )]
10490 )
10591 ],
10692 [
10793 new ConstraintViolationList (
10894 [
109- new ConstraintViolation ('missing property $foo ' , null , ['foo ' ], new \ StdClass (), 'foo ' , null ),
110- new ConstraintViolation ('missing property $bar ' , null , ['bar ' ], new \ StdClass (), 'bar ' , null ),
111- new ConstraintViolation ('missing property $baz ' , null , ['baz ' ], new \ StdClass (), 'baz ' , null ),
95+ new ConstraintViolation ('missing property $foo ' , null , ['foo ' ], new stdClass (), 'foo ' , null ),
96+ new ConstraintViolation ('missing property $bar ' , null , ['bar ' ], new stdClass (), 'bar ' , null ),
97+ new ConstraintViolation ('missing property $baz ' , null , ['baz ' ], new stdClass (), 'baz ' , null ),
11298 ]
11399 )
114100 ],
0 commit comments