From d995cd74ba77eeb87f7080c6bda1a7335587f90a Mon Sep 17 00:00:00 2001 From: Dirk Tepe Date: Sun, 1 Sep 2024 20:46:04 -0400 Subject: [PATCH] Use phpDoc type hints compatible with apereo/phpcas methods --- src/Subfission/Cas/PhpCasProxy.php | 79 ++++++++++++++++++++++++------ tests/CasManagerTest.php | 27 ++++++++++ 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/Subfission/Cas/PhpCasProxy.php b/src/Subfission/Cas/PhpCasProxy.php index 7c96fa3..853d5de 100644 --- a/src/Subfission/Cas/PhpCasProxy.php +++ b/src/Subfission/Cas/PhpCasProxy.php @@ -2,6 +2,7 @@ namespace Subfission\Cas; +use CAS_ServiceBaseUrl_Interface; use phpCAS; use Psr\Log\LoggerInterface; @@ -67,26 +68,76 @@ public function setLogger(LoggerInterface $logger = null): void phpCAS::setLogger($logger); } + /** + * phpCAS client initializer. + * + * @param string $server_version the version of the CAS server + * @param string $server_hostname the hostname of the CAS server + * @param int $server_port the port the CAS server is running on + * @param string $server_uri the URI the CAS server is responding on + * @param string|string[]|CAS_ServiceBaseUrl_Interface + * $service_base_url the base URL (protocol, host and the + * optional port) of the CAS client; pass + * in an array to use auto discovery with + * an allowlist; pass in + * CAS_ServiceBaseUrl_Interface for custom + * behavior. Added in 1.6.0. Similar to + * serverName config in other CAS clients. + * @param bool $changeSessionID Allow phpCAS to change the session_id + * (Single Sign Out/handleLogoutRequests + * is based on that change) + * @param \SessionHandlerInterface $sessionHandler the session handler + * + * @return void a newly created CAS_Client object + * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be + * called, only once, and before all other methods (except phpCAS::getVersion() + * and phpCAS::setDebug()). + */ public function client( - string $server_version, - string $server_hostname, - int $server_port, - string $server_uri, - string $service_base_url, - bool $changeSessionID = true, - \SessionHandlerInterface $sessionHandler = null + $server_version, + $server_hostname, + $server_port, + $server_uri, + $service_base_url, + $changeSessionID = true, + $sessionHandler = null ): void { phpCAS::client($server_version, $server_hostname, $server_port, $server_uri, $service_base_url, $changeSessionID, $sessionHandler); } + /** + * phpCAS proxy initializer. + * + * @param string $server_version the version of the CAS server + * @param string $server_hostname the hostname of the CAS server + * @param string $server_port the port the CAS server is running on + * @param string $server_uri the URI the CAS server is responding on + * @param string|string[]|CAS_ServiceBaseUrl_Interface + * $service_base_url the base URL (protocol, host and the + * optional port) of the CAS client; pass + * in an array to use auto discovery with + * an allowlist; pass in + * CAS_ServiceBaseUrl_Interface for custom + * behavior. Added in 1.6.0. Similar to + * serverName config in other CAS clients. + * @param bool $changeSessionID Allow phpCAS to change the session_id + * (Single Sign Out/handleLogoutRequests + * is based on that change) + * @param \SessionHandlerInterface $sessionHandler the session handler + * + * @return void a newly created CAS_Client object + * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be + * called, only once, and before all other methods (except phpCAS::getVersion() + * and phpCAS::setDebug()). + */ public function proxy( - string $server_version, - string $server_hostname, - int $server_port, - string $server_uri, - string $service_base_url, - bool $changeSessionID = true, - \SessionHandlerInterface $sessionHandler = null + $server_version, + $server_hostname, + $server_port, + $server_uri, + $service_base_url, + $changeSessionID = true, + $sessionHandler = null ): void { phpCAS::proxy($server_version, $server_hostname, $server_port, $server_uri, $service_base_url, $changeSessionID, $sessionHandler); } diff --git a/tests/CasManagerTest.php b/tests/CasManagerTest.php index 5637280..f3df7de 100644 --- a/tests/CasManagerTest.php +++ b/tests/CasManagerTest.php @@ -570,4 +570,31 @@ private function makeCasManager(array $config = []): CasManager { return new CasManager($config, $this->casProxy, $this->sessionProxy, $this->logoutStrategy); } + + public function testConfiguresCasWithServiceBaseArray(): void + { + $config = [ + 'cas_enable_saml' => false, + 'cas_hostname' => $this->faker->domainName(), + 'cas_port' => $this->faker->numberBetween(1, 1024), + 'cas_uri' => $this->faker->url(), + 'cas_client_service' => [$this->faker->url(), $this->faker->url()], + 'cas_control_session' => $this->faker->boolean(), + ]; + + $this->casProxy->expects($this->once())->method('serverTypeCas') + ->willReturnArgument(0); + + $this->casProxy->expects($this->once())->method('client') + ->with( + $this->anything(), + $this->equalTo($config['cas_hostname']), + $this->equalTo($config['cas_port']), + $this->equalTo($config['cas_uri']), + $this->equalTo($config['cas_client_service']), + $this->equalTo($config['cas_control_session']) + ); + + $this->makeCasManager($config); + } }