@@ -30,77 +30,77 @@ public function testItCanBeBuilt(): void
30
30
new ValidationExceptionMapper ()
31
31
);
32
32
33
- static ::assertInstanceOf (RequestValidatorInterface::class, $ validator );
33
+ self ::assertInstanceOf (RequestValidatorInterface::class, $ validator );
34
34
}
35
35
36
- public function testItCanValidateRequest (): void
37
- {
38
- $ requestValidator = $ this ->createMock (PSR7RequestValidator::class);
39
- $ request = $ this ->createMock (RequestInterface::class);
40
-
41
- $ requestValidator
42
- ->expects (static ::once ())
43
- ->method ('validate ' )
44
- ->with ($ request );
45
-
46
- (new RequestValidator (
47
- $ requestValidator ,
48
- new ValidationExceptionMapper ()
49
- ))->validate ($ request );
50
- }
51
-
52
- public function testItCallsExceptionMapperOnThrowable (): void
53
- {
54
- $ this ->expectException (ApiSchemaException::class);
55
-
56
- $ requestValidator = $ this ->createMock (PSR7RequestValidator::class);
57
- $ validationMapper = $ this ->createMock (ValidationExceptionMapper::class);
58
- $ request = $ this ->createMock (RequestInterface::class);
59
-
60
- $ error = new Exception ('Error ' );
61
-
62
- $ requestValidator
63
- ->expects (static ::once ())
64
- ->method ('validate ' )
65
- ->with ($ request )
66
- ->willThrowException ($ error );
67
-
68
- $ validationMapper
69
- ->expects (static ::once ())
70
- ->method ('map ' )
71
- ->with ($ error )
72
- ->willReturn (new ApiSchemaException ($ error ));
73
-
74
- (new RequestValidator ($ requestValidator , $ validationMapper ))->validate ($ request );
75
- }
76
-
77
- /**
78
- * @dataProvider giveExceptions
79
- */
80
- public function testItCanCatchExceptions (Throwable $ error , string $ exception ): void
81
- {
82
- $ this ->expectException ($ exception );
83
-
84
- $ requestValidator = $ this ->createMock (PSR7RequestValidator::class);
85
- $ request = $ this ->createMock (RequestInterface::class);
86
-
87
- $ requestValidator
88
- ->expects (static ::once ())
89
- ->method ('validate ' )
90
- ->with ($ request )
91
- ->willThrowException ($ error );
92
-
93
- (new RequestValidator (
94
- $ requestValidator ,
95
- new ValidationExceptionMapper ()
96
- ))->validate ($ request );
97
- }
98
-
99
- public function giveExceptions (): \ Generator
100
- {
101
- yield [new NoOperation ('Message ' ), OperationNotFoundException::class];
102
- yield [new NoPath ('Message ' ), OperationNotFoundException::class];
103
- yield [new MultipleOperationsMismatchForRequest ('Message ' ), OperationNotFoundException::class];
104
- yield [new RuntimeException ('Message ' ), RuntimeException::class];
105
- }
36
+ public function testItCanValidateRequest (): void
37
+ {
38
+ $ requestValidator = $ this ->createMock (PSR7RequestValidator::class);
39
+ $ request = $ this ->createMock (RequestInterface::class);
40
+
41
+ $ requestValidator
42
+ ->expects (self ::once ())
43
+ ->method ('validate ' )
44
+ ->with ($ request );
45
+
46
+ (new RequestValidator (
47
+ $ requestValidator ,
48
+ new ValidationExceptionMapper ()
49
+ ))->validate ($ request );
50
+ }
51
+
52
+ public function testItCallsExceptionMapperOnThrowable (): void
53
+ {
54
+ $ this ->expectException (ApiSchemaException::class);
55
+
56
+ $ requestValidator = $ this ->createMock (PSR7RequestValidator::class);
57
+ $ validationMapper = $ this ->createMock (ValidationExceptionMapper::class);
58
+ $ request = $ this ->createMock (RequestInterface::class);
59
+
60
+ $ error = new Exception ('Error ' );
61
+
62
+ $ requestValidator
63
+ ->expects (self ::once ())
64
+ ->method ('validate ' )
65
+ ->with ($ request )
66
+ ->willThrowException ($ error );
67
+
68
+ $ validationMapper
69
+ ->expects (self ::once ())
70
+ ->method ('map ' )
71
+ ->with ($ error )
72
+ ->willReturn (new ApiSchemaException ($ error ));
73
+
74
+ (new RequestValidator ($ requestValidator , $ validationMapper ))->validate ($ request );
75
+ }
76
+
77
+ /**
78
+ * @dataProvider provideItCanCatchExceptionsCases
79
+ */
80
+ public function testItCanCatchExceptions (Throwable $ error , string $ exception ): void
81
+ {
82
+ $ this ->expectException ($ exception );
83
+
84
+ $ requestValidator = $ this ->createMock (PSR7RequestValidator::class);
85
+ $ request = $ this ->createMock (RequestInterface::class);
86
+
87
+ $ requestValidator
88
+ ->expects (self ::once ())
89
+ ->method ('validate ' )
90
+ ->with ($ request )
91
+ ->willThrowException ($ error );
92
+
93
+ (new RequestValidator (
94
+ $ requestValidator ,
95
+ new ValidationExceptionMapper ()
96
+ ))->validate ($ request );
97
+ }
98
+
99
+ public static function provideItCanCatchExceptionsCases (): iterable
100
+ {
101
+ yield [new NoOperation ('Message ' ), OperationNotFoundException::class];
102
+ yield [new NoPath ('Message ' ), OperationNotFoundException::class];
103
+ yield [new MultipleOperationsMismatchForRequest ('Message ' ), OperationNotFoundException::class];
104
+ yield [new RuntimeException ('Message ' ), RuntimeException::class];
105
+ }
106
106
}
0 commit comments