@@ -17,12 +17,39 @@ class AuthTest extends TestCase
1717 const SECRET = 'THIS_IS_A_SECRET ' ;
1818 const LOGGER_CHANNEL_NAME = 'Unit-test-logger ' ;
1919
20+ /**
21+ * @var Auth
22+ */
2023 protected $ authenticator ;
24+
25+ /**
26+ * @var GithubRequestMockFactory
27+ */
2128 protected $ mockRequestFactory ;
29+
30+ /**
31+ * @var RequestHandlerInterface&\PHPUnit\Framework\MockObject\MockObject
32+ */
2233 protected $ mockHandler ;
34+
35+ /**
36+ * @var \Psr\Http\Message\ResponseFactoryInterface
37+ */
2338 protected $ responseFactory ;
39+
40+ /**
41+ * @var \Psr\Http\Message\StreamFactoryInterface
42+ */
2443 protected $ streamFactory ;
44+
45+ /**
46+ * @var Resource
47+ */
2548 protected $ logFile ;
49+
50+ /**
51+ * @var Logger
52+ */
2653 protected $ logger ;
2754
2855 protected function setUp (): void
@@ -33,18 +60,21 @@ protected function setUp(): void
3360 $ this ->authenticator = new Auth (self ::SECRET , $ this ->responseFactory , $ this ->streamFactory );
3461 $ this ->logFile = fopen ('php://memory ' , 'rw ' );
3562 $ this ->logger = new Logger (self ::LOGGER_CHANNEL_NAME );
36-
63+
3764 $ this ->mockHandler = $ this ->createMock (RequestHandlerInterface::class);
3865 $ this ->mockRequestFactory = new GithubRequestMockFactory (self ::SECRET );
3966 }
40-
67+
4168 protected function tearDown (): void
4269 {
4370 parent ::tearDown ();
4471 fclose ($ this ->logFile );
4572 }
46-
47- public static function serverRequestProvider ()
73+
74+ /**
75+ * @return ServerRequestInterface[][]
76+ */
77+ public static function serverRequestProvider (): array
4878 {
4979 $ mockRequestFactory = new GithubRequestMockFactory (self ::SECRET );
5080 return [
@@ -53,14 +83,14 @@ public static function serverRequestProvider()
5383 ];
5484 }
5585
56- public function testExtendsPsr15Interface ()
86+ public function testExtendsPsr15Interface (): void
5787 {
5888 $ this ->assertInstanceOf (
5989 MiddlewareInterface::class,
6090 new Auth (self ::SECRET , $ this ->responseFactory , $ this ->streamFactory )
6191 );
6292 }
63- public function testResponseMissingSignature ()
93+ public function testResponseMissingSignature (): void
6494 {
6595 $ request = $ this ->mockRequestFactory ->createMissingHeaderRequest ();
6696 $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
@@ -69,7 +99,7 @@ public function testResponseMissingSignature()
6999 $ this ->assertEquals ('Bad Request ' , $ result ->getReasonPhrase ());
70100 }
71101
72- public function testResponseIncorrectSignature ()
102+ public function testResponseIncorrectSignature (): void
73103 {
74104 $ request = $ this ->mockRequestFactory ->createUnauthenticRequest ();
75105 $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
@@ -78,67 +108,67 @@ public function testResponseIncorrectSignature()
78108 $ this ->assertEquals ('Unauthorized ' , $ result ->getReasonPhrase ());
79109 }
80110
81- public function test202ResponseFromHandlerCorrectSignature ()
111+ public function test202ResponseFromHandlerCorrectSignature (): void
82112 {
83113 $ request = $ this ->mockRequestFactory ->createAuthenticRequest ();
84-
114+
85115 $ this ->mockHandler ->method ('handle ' )
86116 ->willReturn ($ this ->responseFactory ->createResponse (202 , 'Accepted ' ));
87-
117+
88118 $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
89119
90120 $ this ->assertEquals (202 , $ result ->getStatusCode ());
91121 $ this ->assertEquals ('Accepted ' , $ result ->getReasonPhrase ());
92122 }
93123
94- public function test201ResponseFromHandlerCorrectSignature ()
124+ public function test201ResponseFromHandlerCorrectSignature (): void
95125 {
96126 $ request = $ this ->mockRequestFactory ->createAuthenticRequest ();
97127
98128 $ this ->mockHandler ->method ('handle ' )
99129 ->willReturn ($ this ->responseFactory ->createResponse (201 , 'Created ' ));
100-
130+
101131 $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
102132
103133 $ this ->assertEquals (201 , $ result ->getStatusCode ());
104134 $ this ->assertEquals ('Created ' , $ result ->getReasonPhrase ());
105135 }
106136
107- public function testLoggingOfMissingHeader ()
137+ public function testLoggingOfMissingHeader (): void
108138 {
109139 $ this ->logger ->pushHandler (new StreamHandler ($ this ->logFile , Logger::DEBUG ));
110140 $ this ->authenticator ->setLogger ($ this ->logger );
111141
112142 $ request = $ this ->mockRequestFactory ->createMissingHeaderRequest ();
113- $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
143+ $ this ->authenticator ->process ($ request , $ this ->mockHandler );
114144
115145 rewind ($ this ->logFile );
116146 $ logLine = stream_get_line ($ this ->logFile , 4096 );
117147 $ expected = self ::LOGGER_CHANNEL_NAME . '.WARNING: ' . Auth::LOG_MSG_MISSING_HEADER ;
118148 $ this ->assertStringContainsString ($ expected , $ logLine );
119149 }
120150
121- public function testLoggingOfFailedAuthentication ()
151+ public function testLoggingOfFailedAuthentication (): void
122152 {
123153 $ this ->logger ->pushHandler (new StreamHandler ($ this ->logFile , Logger::DEBUG ));
124154 $ this ->authenticator ->setLogger ($ this ->logger );
125155
126156 $ request = $ this ->mockRequestFactory ->createUnauthenticRequest ();
127- $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
157+ $ this ->authenticator ->process ($ request , $ this ->mockHandler );
128158
129159 rewind ($ this ->logFile );
130160 $ logLine = stream_get_line ($ this ->logFile , 4096 );
131161 $ expected = self ::LOGGER_CHANNEL_NAME . '.WARNING: ' . Auth::LOG_MSG_SIGNATURE_NOT_MATCHING ;
132162 $ this ->assertStringContainsString ($ expected , $ logLine );
133163 }
134164
135- public function testLoggingOfSuccessfulAuthentication ()
165+ public function testLoggingOfSuccessfulAuthentication (): void
136166 {
137167 $ this ->logger ->pushHandler (new StreamHandler ($ this ->logFile , Logger::DEBUG ));
138168 $ this ->authenticator ->setLogger ($ this ->logger );
139169
140170 $ request = $ this ->mockRequestFactory ->createAuthenticRequest ();
141- $ result = $ this ->authenticator ->process ($ request , $ this ->mockHandler );
171+ $ this ->authenticator ->process ($ request , $ this ->mockHandler );
142172
143173 rewind ($ this ->logFile );
144174 $ logLine = stream_get_line ($ this ->logFile , 4096 );
@@ -149,42 +179,42 @@ public function testLoggingOfSuccessfulAuthentication()
149179 /**
150180 * @dataProvider serverRequestProvider
151181 */
152- public function testRequestBodyIsPassedToHandlerIsSeekable ($ request )
182+ public function testRequestBodyIsPassedToHandlerIsSeekable (ServerRequestInterface $ request ): void
153183 {
154184 $ this ->mockHandler ->expects ($ this ->atLeastOnce ())
155- ->method ('handle ' )
156- ->with ($ this ->callback (function ($ handlerRequest ) {
157- return $ handlerRequest ->getBody ()->isSeekable ();
158- }));
159-
185+ ->method ('handle ' )
186+ ->with ($ this ->callback (function (ServerRequestInterface $ handlerRequest ) {
187+ return $ handlerRequest ->getBody ()->isSeekable ();
188+ }));
189+
160190 $ this ->authenticator ->process ($ request , $ this ->mockHandler );
161191 }
162192
163193 /**
164194 * @dataProvider serverRequestProvider
165195 */
166- public function testRequestBodyIsNotAltered ($ request )
196+ public function testRequestBodyIsNotAltered (ServerRequestInterface $ request ): void
167197 {
168198 $ this ->mockHandler ->expects ($ this ->atLeastOnce ())
169- ->method ('handle ' )
170- ->with ($ this ->callback (function ($ handlerRequest ) use ($ request ) {
171- return (string ) $ handlerRequest ->getBody () == (string ) $ request ->getBody ();
172- }));
173-
199+ ->method ('handle ' )
200+ ->with ($ this ->callback (function (ServerRequestInterface $ handlerRequest ) use ($ request ) {
201+ return (string ) $ handlerRequest ->getBody () == (string ) $ request ->getBody ();
202+ }));
203+
174204 $ this ->authenticator ->process ($ request , $ this ->mockHandler );
175205 }
176-
206+
177207 /**
178208 * @dataProvider serverRequestProvider
179209 */
180- public function testRequestBodyIsRewound ($ request )
210+ public function testRequestBodyIsRewound (ServerRequestInterface $ request ): void
181211 {
182212 $ this ->mockHandler ->expects ($ this ->atLeastOnce ())
183- ->method ('handle ' )
184- ->with ($ this ->callback (function ($ handlerRequest ) use ( $ request ) {
185- return $ handlerRequest ->getBody ()->tell () === 0 ;
186- }));
187-
213+ ->method ('handle ' )
214+ ->with ($ this ->callback (function (ServerRequestInterface $ handlerRequest ) {
215+ return $ handlerRequest ->getBody ()->tell () === 0 ;
216+ }));
217+
188218 $ this ->authenticator ->process ($ request , $ this ->mockHandler );
189219 }
190220}
0 commit comments