1313 */
1414namespace Staffbase \plugins \test ;
1515
16- use Exception ;
1716use ReflectionClass ;
1817use phpseclib \Crypt \RSA ;
1918use PHPUnit \Framework \TestCase ;
@@ -83,7 +82,7 @@ public function testConstructorWorksAsExpected() {
8382
8483 $ mock = $ this ->getMockBuilder ($ this ->classname )
8584 ->disableOriginalConstructor ()
86- ->setMethods (array ('openSession ' , 'closeSession ' ))
85+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
8786 ->getMock ();
8887
8988 $ mock ->expects ($ this ->exactly (2 ))
@@ -112,7 +111,7 @@ public function testConstructorRejectsSpoofedPID() {
112111
113112 $ mock = $ this ->getMockBuilder ($ this ->classname )
114113 ->disableOriginalConstructor ()
115- ->setMethods (array ('openSession ' , 'closeSession ' ))
114+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
116115 ->getMock ();
117116
118117 $ reflectedClass = new ReflectionClass ($ this ->classname );
@@ -138,7 +137,7 @@ public function testConstructorRefuseEmptyPluginId() {
138137
139138 $ mock = $ this ->getMockBuilder ($ this ->classname )
140139 ->disableOriginalConstructor ()
141- ->setMethods (array ('openSession ' , 'closeSession ' ))
140+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
142141 ->getMock ();
143142
144143 $ this ->expectException (SSOException::class);
@@ -162,7 +161,7 @@ public function testConstructorRefuseEmptySecret() {
162161
163162 $ mock = $ this ->getMockBuilder ($ this ->classname )
164163 ->disableOriginalConstructor ()
165- ->setMethods (array ('openSession ' , 'closeSession ' ))
164+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
166165 ->getMock ();
167166
168167 $ this ->expectException (SSOException::class);
@@ -186,7 +185,7 @@ public function testConstructorRefuseEmptyEnv() {
186185
187186 $ mock = $ this ->getMockBuilder ($ this ->classname )
188187 ->disableOriginalConstructor ()
189- ->setMethods (array ('openSession ' , 'closeSession ' ))
188+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
190189 ->getMock ();
191190
192191 $ this ->expectException (SSOAuthenticationException::class);
@@ -210,7 +209,7 @@ public function testConstructorRefuseHavingBothJwtAndPid() {
210209
211210 $ mock = $ this ->getMockBuilder ($ this ->classname )
212211 ->disableOriginalConstructor ()
213- ->setMethods (array ('openSession ' , 'closeSession ' ))
212+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
214213 ->getMock ();
215214
216215 $ this ->expectException (SSOAuthenticationException::class);
@@ -234,10 +233,11 @@ public function testConstructorUpdatesInfoOnJwt() {
234233
235234 $ mock = $ this ->getMockBuilder ($ this ->classname )
236235 ->disableOriginalConstructor ()
237- ->setMethods (array ('openSession ' , 'closeSession ' ))
236+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
238237 ->getMock ();
239238
240- $ session = new $ mock ($ this ->pluginId , $ this ->publicKey );
239+ /** @var PluginSession $session */
240+ $ session = new $ mock ($ this ->pluginId , $ this ->publicKey );
241241
242242 $ this ->assertEquals ($ session ->getRole (), $ this ->tokenData [PluginSession::CLAIM_USER_ROLE ]);
243243
@@ -248,6 +248,7 @@ public function testConstructorUpdatesInfoOnJwt() {
248248 $ this ->setupEnvironment (null , $ newToken , false );
249249 $ newSession = new $ mock ($ this ->pluginId , $ this ->publicKey );
250250
251+ /** @var PluginSession $newSession */
251252 $ this ->assertEquals ($ newSession ->getRole (), $ tokenData [PluginSession::CLAIM_USER_ROLE ]);
252253 $ this ->assertEquals ($ session ->getRole (), $ newSession ->getRole ());
253254 }
@@ -267,9 +268,10 @@ public function testConstructorSupportMultipleInstances() {
267268
268269 $ mock = $ this ->getMockBuilder ($ this ->classname )
269270 ->disableOriginalConstructor ()
270- ->setMethods (array ('openSession ' , 'closeSession ' ))
271+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
271272 ->getMock ();
272273
274+ /** @var PluginSession $session */
273275 $ session = new $ mock ($ this ->pluginId , $ this ->publicKey );
274276
275277
@@ -280,7 +282,8 @@ public function testConstructorSupportMultipleInstances() {
280282
281283 $ this ->setupEnvironment (null , $ newToken , false );
282284
283- $ newSession = new $ mock ($ this ->pluginId , $ this ->publicKey );
285+ /** @var PluginSession $newSession */
286+ $ newSession = new $ mock ($ this ->pluginId , $ this ->publicKey );
284287
285288 $ this ->assertEquals ($ newSession ->getRole (), $ tokenData [PluginSession::CLAIM_USER_ROLE ]);
286289 $ this ->assertNotEquals ($ session ->getRole (), $ newSession ->getRole ());
@@ -311,10 +314,11 @@ public function testGetSessionData() {
311314
312315 $ mock = $ this ->getMockBuilder ($ this ->classname )
313316 ->disableOriginalConstructor ()
314- ->setMethods (array ('openSession ' , 'closeSession ' ))
317+ ->onlyMethods (array ('openSession ' , 'closeSession ' ))
315318 ->getMock ();
316319
317- $ session = new $ mock ($ this ->pluginId , $ this ->publicKey );
320+ /** @var PluginSession $session */
321+ $ session = new $ mock ($ this ->pluginId , $ this ->publicKey );
318322
319323 $ sessionData = [
320324 'test1 ' => 'val1 ' ,
@@ -346,7 +350,7 @@ public function testDeleteSuccessfulCallInterface() {
346350
347351 // successfull remote call handler mock
348352 $ handler = $ this ->getMockBuilder (DeleteInstanceCallHandlerInterface::class)
349- ->setMethods (array ('deleteInstance ' , 'exitSuccess ' , 'exitFailure ' ))
353+ ->onlyMethods (array ('deleteInstance ' , 'exitSuccess ' , 'exitFailure ' ))
350354 ->getMock ();
351355
352356 $ handler ->method ('deleteInstance ' )
@@ -364,7 +368,7 @@ public function testDeleteSuccessfulCallInterface() {
364368 // session mock
365369 $ Session = $ this ->getMockBuilder ($ this ->classname )
366370 ->disableOriginalConstructor ()
367- ->setMethods (array ('openSession ' , 'closeSession ' , 'exitRemoteCall ' ))
371+ ->onlyMethods (array ('openSession ' , 'closeSession ' , 'exitRemoteCall ' ))
368372 ->getMock ();
369373
370374 new $ Session ($ this ->pluginId , $ this ->publicKey , null , 0 , $ handler );
@@ -387,7 +391,7 @@ public function testDeleteFailedCallInterface() {
387391
388392 // successfull remote call handler mock
389393 $ handler = $ this ->getMockBuilder (DeleteInstanceCallHandlerInterface::class)
390- ->setMethods (array ('deleteInstance ' , 'exitSuccess ' , 'exitFailure ' ))
394+ ->onlyMethods (array ('deleteInstance ' , 'exitSuccess ' , 'exitFailure ' ))
391395 ->getMock ();
392396
393397 $ handler ->method ('deleteInstance ' )
@@ -405,7 +409,7 @@ public function testDeleteFailedCallInterface() {
405409 // session mock
406410 $ Session = $ this ->getMockBuilder ($ this ->classname )
407411 ->disableOriginalConstructor ()
408- ->setMethods (array ('openSession ' , 'closeSession ' , 'exitRemoteCall ' ))
412+ ->onlyMethods (array ('openSession ' , 'closeSession ' , 'exitRemoteCall ' ))
409413 ->getMock ();
410414
411415 new $ Session ($ this ->pluginId , $ this ->publicKey , null , 0 , $ handler );
0 commit comments