Skip to content

Commit

Permalink
Simplify and type Auth tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 25, 2024
1 parent a41d32c commit 90178f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
34 changes: 16 additions & 18 deletions module/VuFind/tests/unit-tests/src/VuFindTest/Auth/LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace VuFindTest\Auth;

use Laminas\Config\Config;
use Laminas\Http\Request;
use VuFind\Auth\LDAP;

/**
Expand All @@ -48,19 +49,16 @@ class LDAPTest extends \PHPUnit\Framework\TestCase
/**
* Get an authentication object.
*
* @param Config $config Configuration to use (null for default)
* @param ?Config $config Configuration to use (null for default)
*
* @return LDAP
*/
public function getAuthObject($config = null)
public function getAuthObject(?Config $config = null): LDAP
{
if (null === $config) {
$config = $this->getAuthConfig();
}
$authManager = new \VuFind\Auth\PluginManager(
new \VuFindTest\Container\MockContainer($this)
);
$obj = $authManager->get('LDAP');
$obj = new LDAP();
$obj->setConfig($config);
return $obj;
}
Expand All @@ -70,7 +68,7 @@ public function getAuthObject($config = null)
*
* @return Config
*/
public function getAuthConfig()
public function getAuthConfig(): Config
{
$ldapConfig = new Config(
[
Expand All @@ -89,7 +87,7 @@ public function getAuthConfig()
*
* @return void
*/
public function testWithMissingHost()
public function testWithMissingHost(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand All @@ -103,7 +101,7 @@ public function testWithMissingHost()
*
* @return void
*/
public function testWithMissingPort()
public function testWithMissingPort(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand All @@ -117,7 +115,7 @@ public function testWithMissingPort()
*
* @return void
*/
public function testWithMissingBaseDN()
public function testWithMissingBaseDN(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand All @@ -131,7 +129,7 @@ public function testWithMissingBaseDN()
*
* @return void
*/
public function testWithMissingUid()
public function testWithMissingUid(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand All @@ -145,7 +143,7 @@ public function testWithMissingUid()
*
* @return void
*/
public function testCaseNormalization()
public function testCaseNormalization(): void
{
$config = $this->getAuthConfig();
$config->LDAP->username = 'UPPER';
Expand All @@ -168,7 +166,7 @@ public function testCaseNormalization()
*
* @return void
*/
public function testCreateIsDisallowed()
public function testCreateIsDisallowed(): void
{
$this->assertFalse($this->getAuthObject()->supportsCreation());
}
Expand All @@ -179,14 +177,14 @@ public function testCreateIsDisallowed()
*
* @param array $overrides Associative array of parameters to override.
*
* @return \Laminas\Http\Request
* @return Request
*/
protected function getLoginRequest($overrides = [])
protected function getLoginRequest(array $overrides = []): Request
{
$post = $overrides + [
'username' => 'testuser', 'password' => 'testpass',
];
$request = new \Laminas\Http\Request();
$request = new Request();
$request->setPost(new \Laminas\Stdlib\Parameters($post));
return $request;
}
Expand All @@ -196,7 +194,7 @@ protected function getLoginRequest($overrides = [])
*
* @return void
*/
public function testLoginWithBlankUsername()
public function testLoginWithBlankUsername(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand All @@ -209,7 +207,7 @@ public function testLoginWithBlankUsername()
*
* @return void
*/
public function testLoginWithBlankPassword()
public function testLoginWithBlankPassword(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand Down
24 changes: 11 additions & 13 deletions module/VuFind/tests/unit-tests/src/VuFindTest/Auth/SIP2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace VuFindTest\Auth;

use Laminas\Config\Config;
use \Laminas\Http\Request;
use VuFind\Auth\SIP2;

/**
Expand All @@ -46,19 +47,16 @@ class SIP2Test extends \PHPUnit\Framework\TestCase
/**
* Get an authentication object.
*
* @param Config $config Configuration to use (null for default)
* @param ?Config $config Configuration to use (null for default)
*
* @return LDAP
* @return SIP2
*/
public function getAuthObject($config = null)
public function getAuthObject(?Config $config = null): SIP2
{
if (null === $config) {
$config = $this->getAuthConfig();
}
$authManager = new \VuFind\Auth\PluginManager(
new \VuFindTest\Container\MockContainer($this)
);
$obj = $authManager->get('SIP2');
$obj = new SIP2();
$obj->setConfig($config);
return $obj;
}
Expand All @@ -68,7 +66,7 @@ public function getAuthObject($config = null)
*
* @return Config
*/
public function getAuthConfig()
public function getAuthConfig(): Config
{
$config = new Config(
[
Expand All @@ -86,14 +84,14 @@ public function getAuthConfig()
*
* @param array $overrides Associative array of parameters to override.
*
* @return \Laminas\Http\Request
* @return Request
*/
protected function getLoginRequest($overrides = [])
protected function getLoginRequest(array $overrides = []): Request
{
$post = $overrides + [
'username' => 'testuser', 'password' => 'testpass',
];
$request = new \Laminas\Http\Request();
$request = new Request();
$request->setPost(new \Laminas\Stdlib\Parameters($post));
return $request;
}
Expand All @@ -103,7 +101,7 @@ protected function getLoginRequest($overrides = [])
*
* @return void
*/
public function testLoginWithBlankUsername()
public function testLoginWithBlankUsername(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand All @@ -116,7 +114,7 @@ public function testLoginWithBlankUsername()
*
* @return void
*/
public function testLoginWithBlankPassword()
public function testLoginWithBlankPassword(): void
{
$this->expectException(\VuFind\Exception\Auth::class);

Expand Down

0 comments on commit 90178f9

Please sign in to comment.