Skip to content

Commit

Permalink
Use phpDoc type hints compatible with apereo/phpcas methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tepeds committed Sep 2, 2024
1 parent 727704f commit d995cd7
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 14 deletions.
79 changes: 65 additions & 14 deletions src/Subfission/Cas/PhpCasProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Subfission\Cas;

use CAS_ServiceBaseUrl_Interface;
use phpCAS;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -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);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/CasManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit d995cd7

Please sign in to comment.