55namespace SimpleSAML \Module \casserver \Tests \Controller ;
66
77use PHPUnit \Framework \Attributes \DataProvider ;
8- use PHPUnit \Framework \MockObject \MockObject ;
98use PHPUnit \Framework \TestCase ;
109use SimpleSAML \CAS \Constants as C ;
1110use SimpleSAML \Configuration ;
1211use SimpleSAML \Module ;
1312use SimpleSAML \Module \casserver \Cas \Factories \TicketFactory ;
1413use SimpleSAML \Module \casserver \Cas \Ticket \FileSystemTicketStore ;
15- use SimpleSAML \Module \casserver \Cas \TicketValidator ;
1614use SimpleSAML \Module \casserver \Controller \Cas20Controller ;
17- use SimpleSAML \Session ;
1815use SimpleSAML \Utils ;
1916use Symfony \Component \HttpFoundation \Request ;
2017use Symfony \Component \HttpFoundation \Response ;
@@ -23,8 +20,6 @@ class Cas20ControllerTest extends TestCase
2320{
2421 private array $ moduleConfig ;
2522
26- private Session $ sessionMock ;
27-
2823 private Request $ samlValidateRequest ;
2924
3025 private string $ sessionId ;
@@ -33,10 +28,6 @@ class Cas20ControllerTest extends TestCase
3328
3429 private FileSystemTicketStore $ ticketStore ;
3530
36- private TicketValidator $ ticketValidatorMock ;
37-
38- private Utils \HTTP |MockObject $ utilsHttpMock ;
39-
4031 private array $ ticket ;
4132
4233 private array $ proxyTicket ;
@@ -59,21 +50,6 @@ protected function setUp(): void
5950 // Hard code the ticket store
6051 $ this ->ticketStore = new FileSystemTicketStore (Configuration::loadFromArray ($ this ->moduleConfig ));
6152
62- $ this ->ticketValidatorMock = $ this ->getMockBuilder (TicketValidator::class)
63- ->setConstructorArgs ([Configuration::loadFromArray ($ this ->moduleConfig )])
64- ->onlyMethods (['validateAndDeleteTicket ' ])
65- ->getMock ();
66-
67- $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
68- ->disableOriginalConstructor ()
69- ->onlyMethods (['getSessionId ' ])
70- ->getMock ();
71-
72- $ this ->utilsHttpMock = $ this ->getMockBuilder (Utils \HTTP ::class)
73- ->disableOriginalConstructor ()
74- ->onlyMethods (['fetch ' ])
75- ->getMock ();
76-
7753 $ this ->ticket = [
7854 'id ' => 'ST- ' . $ this ->sessionId ,
7955 'validBefore ' => 1731111111 ,
@@ -152,6 +128,7 @@ public function testProxyValidatePassesTheCorrectMethodToValidate(string $prefix
152128 $ controllerMock ->expects ($ this ->once ())
153129 ->method ('validate ' )
154130 ->with ($ request , $ method , false , null , $ prefix . $ this ->sessionId , 'https://myservice.com/abcd ' , null );
131+
155132 $ controllerMock ->$ method ($ request , ...$ requestParameters );
156133 }
157134
@@ -355,7 +332,7 @@ public function testProxyReturnsProxyTicket(): void
355332 $ xml ->registerXPathNamespace ('cas ' , 'serviceResponse ' );
356333 $ this ->assertEquals ('serviceResponse ' , $ xml ->getName ());
357334 $ this ->assertNotNull ($ xml ->xpath ('//cas:proxySuccess ' ));
358- $ ticketId = (string )$ xml ->xpath ('//cas:proxyTicket ' )[0 ];
335+ $ ticketId = (string ) $ xml ->xpath ('//cas:proxyTicket ' )[0 ];
359336 $ proxyTicket = $ this ->ticketStore ->getTicket ($ ticketId );
360337 $ this ->assertTrue (filter_var ($ ticketFactory ->isProxyTicket ($ proxyTicket ), FILTER_VALIDATE_BOOLEAN ));
361338 }
@@ -748,14 +725,19 @@ public function testThrowOnProxyServiceIdentityFail(): void
748725 parameters: $ params ,
749726 );
750727
751- $ this ->utilsHttpMock ->expects ($ this ->once ())
728+ $ httpUtilsMock = $ this ->getMockBuilder (Utils \HTTP ::class)
729+ ->disableOriginalConstructor ()
730+ ->onlyMethods (['fetch ' ])
731+ ->getMock ();
732+
733+ $ httpUtilsMock ->expects ($ this ->once ())
752734 ->method ('fetch ' )
753735 ->willThrowException (new \Exception ());
754736
755737 $ cas20Controller = new Cas20Controller (
756738 sspConfig: $ this ->sspConfig ,
757739 casConfig: $ config ,
758- httpUtils: $ this -> utilsHttpMock ,
740+ httpUtils: $ httpUtilsMock ,
759741 );
760742 $ ticketStore = $ cas20Controller ->getTicketStore ();
761743 $ ticketStore ->addTicket ($ this ->ticket );
0 commit comments