diff --git a/tests/lib/SimpleSAML/Auth/SimpleTest.php b/tests/lib/SimpleSAML/Auth/SimpleTest.php index 7e5799634165577e75e7d482ffd1311fe9503aa6..b78f24b446f04c1b63503d6d74f6abbb188f3ab5 100644 --- a/tests/lib/SimpleSAML/Auth/SimpleTest.php +++ b/tests/lib/SimpleSAML/Auth/SimpleTest.php @@ -2,6 +2,8 @@ namespace SimpleSAML\Test\Auth; +use SimpleSAML\Auth; + /** * Tests for \SimpleSAML\Auth\Simple * @@ -14,7 +16,7 @@ class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetProcessedURL() { - $class = new \ReflectionClass('\SimpleSAML\Auth\Simple'); + $class = new \ReflectionClass(Auth\Simple::class); $method = $class->getMethod('getProcessedURL'); $method->setAccessible(true); diff --git a/tests/lib/SimpleSAML/Auth/SourceTest.php b/tests/lib/SimpleSAML/Auth/SourceTest.php index 26c382c54dc4ae799f8a26f275fab5c159726a9d..fe326f5d0666fe0093570b55ab3f4ed1f4729237 100644 --- a/tests/lib/SimpleSAML/Auth/SourceTest.php +++ b/tests/lib/SimpleSAML/Auth/SourceTest.php @@ -16,16 +16,16 @@ class SourceTest extends ClearStateTestCase */ public function testParseAuthSource() { - $class = new \ReflectionClass('\SimpleSAML\Auth\Source'); + $class = new \ReflectionClass(\SimpleSAML\Auth\Source::class); $method = $class->getMethod('parseAuthSource'); $method->setAccessible(true); // test direct instantiation of the auth source object - $authSource = $method->invokeArgs(null, ['test', ['SimpleSAML\Test\Utils\TestAuthSource']]); - $this->assertInstanceOf('SimpleSAML\Test\Utils\TestAuthSource', $authSource); + $authSource = $method->invokeArgs(null, ['test', [TestAuthSource::class]]); + $this->assertInstanceOf(TestAuthSource::class, $authSource); // test instantiation via an auth source factory - $authSource = $method->invokeArgs(null, ['test', ['SimpleSAML\Test\Utils\TestAuthSourceFactory']]); - $this->assertInstanceOf('SimpleSAML\Test\Utils\TestAuthSource', $authSource); + $authSource = $method->invokeArgs(null, ['test', [TestAuthSourceFactory::class]]); + $this->assertInstanceOf(TestAuthSource::class, $authSource); } } diff --git a/tests/lib/SimpleSAML/ConfigurationTest.php b/tests/lib/SimpleSAML/ConfigurationTest.php index fcc463003573bc37dde1b02a24029c10fb2d5e0c..9c15f78b3f922eb3226e6d27f5344e8845162bd1 100644 --- a/tests/lib/SimpleSAML/ConfigurationTest.php +++ b/tests/lib/SimpleSAML/ConfigurationTest.php @@ -526,8 +526,8 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $this->assertNull($c->getConfigItem('missing_opt', null)); $opt = $c->getConfigItem('opt'); $notOpt = $c->getConfigItem('notOpt'); - $this->assertInstanceOf('SimpleSAML\Configuration', $opt); - $this->assertInstanceOf('SimpleSAML\Configuration', $notOpt); + $this->assertInstanceOf(Configuration::class, $opt); + $this->assertInstanceOf(Configuration::class, $notOpt); $this->assertEquals($opt->getValue('a'), 42); } @@ -562,9 +562,9 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $opts = $c->getConfigList('opts'); $this->assertInternalType('array', $opts); $this->assertEquals(array_keys($opts), ['a', 'b']); - $this->assertInstanceOf('SimpleSAML\Configuration', $opts['a']); + $this->assertInstanceOf(Configuration::class, $opts['a']); $this->assertEquals($opts['a']->getValue('opt1'), 'value1'); - $this->assertInstanceOf('SimpleSAML\Configuration', $opts['b']); + $this->assertInstanceOf(Configuration::class, $opts['b']); $this->assertEquals($opts['b']->getValue('opt2'), 'value2'); } diff --git a/tests/lib/SimpleSAML/DatabaseTest.php b/tests/lib/SimpleSAML/DatabaseTest.php index 0e98f91577166ad8462e153c8caa7a0dbff1d51f..18cac06cc12116b68a27b290ec7d0a247404b4eb 100644 --- a/tests/lib/SimpleSAML/DatabaseTest.php +++ b/tests/lib/SimpleSAML/DatabaseTest.php @@ -3,6 +3,8 @@ namespace SimpleSAML\Test; use PHPUnit\Framework\TestCase; +use SimpleSAML\Configuration; +use SimpleSAML\Database; /** * This test ensures that the \SimpleSAML\Database class can properly @@ -37,7 +39,7 @@ class DatabaseTest extends TestCase */ protected static function getMethod($getMethod) { - $class = new \ReflectionClass('SimpleSAML\Database'); + $class = new \ReflectionClass(Database::class); $method = $class->getMethod($getMethod); $method->setAccessible(true); return $method; @@ -62,16 +64,16 @@ class DatabaseTest extends TestCase 'database.slaves' => [], ]; - $this->config = new \SimpleSAML\Configuration($config, "test/SimpleSAML/DatabaseTest.php"); + $this->config = new Configuration($config, "test/SimpleSAML/DatabaseTest.php"); // Ensure that we have a functional configuration class - $this->assertInstanceOf('SimpleSAML\Configuration', $this->config); + $this->assertInstanceOf(Configuration::class, $this->config); $this->assertEquals($config['database.dsn'], $this->config->getString('database.dsn')); - $this->db = \SimpleSAML\Database::getInstance($this->config); + $this->db = Database::getInstance($this->config); // Ensure that we have a functional database class. - $this->assertInstanceOf('SimpleSAML\Database', $this->db); + $this->assertInstanceOf(Database::class, $this->db); } @@ -95,8 +97,8 @@ class DatabaseTest extends TestCase 'database.slaves' => [], ]; - $this->config = new \SimpleSAML\Configuration($config, "test/SimpleSAML/DatabaseTest.php"); - \SimpleSAML\Database::getInstance($this->config); + $this->config = new Configuration($config, "test/SimpleSAML/DatabaseTest.php"); + Database::getInstance($this->config); } @@ -127,13 +129,13 @@ class DatabaseTest extends TestCase 'database.slaves' => [], ]; - $config1 = new \SimpleSAML\Configuration($config, "test/SimpleSAML/DatabaseTest.php"); - $config2 = new \SimpleSAML\Configuration($config2, "test/SimpleSAML/DatabaseTest.php"); - $config3 = new \SimpleSAML\Configuration($config, "test/SimpleSAML/DatabaseTest.php"); + $config1 = new Configuration($config, "test/SimpleSAML/DatabaseTest.php"); + $config2 = new Configuration($config2, "test/SimpleSAML/DatabaseTest.php"); + $config3 = new Configuration($config, "test/SimpleSAML/DatabaseTest.php"); - $db1 = \SimpleSAML\Database::getInstance($config1); - $db2 = \SimpleSAML\Database::getInstance($config2); - $db3 = \SimpleSAML\Database::getInstance($config3); + $db1 = Database::getInstance($config1); + $db2 = Database::getInstance($config2); + $db3 = Database::getInstance($config3); $generateInstanceId = self::getMethod('generateInstanceId'); @@ -202,8 +204,8 @@ class DatabaseTest extends TestCase ], ]; - $sspConfiguration = new \SimpleSAML\Configuration($config, "test/SimpleSAML/DatabaseTest.php"); - $msdb = \SimpleSAML\Database::getInstance($sspConfiguration); + $sspConfiguration = new Configuration($config, "test/SimpleSAML/DatabaseTest.php"); + $msdb = Database::getInstance($sspConfiguration); $slaves = \PHPUnit\Framework\Assert::readAttribute($msdb, 'dbSlaves'); $gotSlave = spl_object_hash($getSlave->invokeArgs($msdb, [])); diff --git a/tests/lib/SimpleSAML/SessionHandlerPHPTest.php b/tests/lib/SimpleSAML/SessionHandlerPHPTest.php index 1ae63c4449e239946220e45182e5e296a3a299e8..279fe0725bef72468bfc386ab263bcd6f6c4630d 100644 --- a/tests/lib/SimpleSAML/SessionHandlerPHPTest.php +++ b/tests/lib/SimpleSAML/SessionHandlerPHPTest.php @@ -56,7 +56,7 @@ class SessionHandlerPHPTest extends ClearStateTestCase { Configuration::loadFromArray($this->sessionConfig, '[ARRAY]', 'simplesaml'); $sh = SessionHandlerPHP::getSessionHandler(); - $this->assertInstanceOf('\SimpleSAML\SessionHandlerPHP', $sh); + $this->assertInstanceOf(SessionHandlerPHP::class, $sh); } diff --git a/tests/lib/SimpleSAML/Store/RedisTest.php b/tests/lib/SimpleSAML/Store/RedisTest.php index 3f5593360bed8f0fbc4f16c740a2205456352067..690ad36da7cd66ea239daa3a8c7812a53a2b679b 100644 --- a/tests/lib/SimpleSAML/Store/RedisTest.php +++ b/tests/lib/SimpleSAML/Store/RedisTest.php @@ -3,6 +3,7 @@ namespace SimpleSAML\Test\Store; use PHPUnit\Framework\TestCase; +use Predis\Client; use SimpleSAML\Configuration; use SimpleSAML\Store; @@ -33,7 +34,7 @@ class RedisTest extends TestCase { $this->config = []; - $this->mocked_redis = $this->getMockBuilder('Predis\Client') + $this->mocked_redis = $this->getMockBuilder(Client::class) ->setMethods(['get', 'set', 'setex', 'del', 'disconnect']) ->disableOriginalConstructor() ->getMock(); @@ -127,10 +128,10 @@ class RedisTest extends TestCase /** @var \SimpleSAML\Store\Redis $store */ $store = Store::getInstance(); - $this->assertInstanceOf('SimpleSAML\Store\Redis', $store); + $this->assertInstanceOf(Store\Redis::class, $store); - $this->clearInstance($config, '\SimpleSAML\Configuration'); - $this->clearInstance($store, '\SimpleSAML\Store'); + $this->clearInstance($config, Configuration::Class); + $this->clearInstance($store, Store::class); } @@ -151,10 +152,10 @@ class RedisTest extends TestCase /** @var \SimpleSAML\Store\Redis $store */ $store = Store::getInstance(); - $this->assertInstanceOf('SimpleSAML\Store\Redis', $store); + $this->assertInstanceOf(Store\Redis::class, $store); - $this->clearInstance($config, '\SimpleSAML\Configuration'); - $this->clearInstance($store, '\SimpleSAML\Store'); + $this->clearInstance($config, Configuration::class); + $this->clearInstance($store, Store::class); } diff --git a/tests/lib/SimpleSAML/StoreTest.php b/tests/lib/SimpleSAML/StoreTest.php index 8b95bede1b5df91ea9b11e914f24f34ff5051aae..65d429d362a2c1c5318b0455c3f14a4e7ddfd8c9 100644 --- a/tests/lib/SimpleSAML/StoreTest.php +++ b/tests/lib/SimpleSAML/StoreTest.php @@ -63,7 +63,7 @@ class StoreTest extends TestCase $store = Store::getInstance(); - $this->assertInstanceOf('\SimpleSAML\Store\Memcache', $store); + $this->assertInstanceOf(Store\Memcache::class, $store); } @@ -82,7 +82,7 @@ class StoreTest extends TestCase $store = Store::getInstance(); - $this->assertInstanceOf('SimpleSAML\Store\SQL', $store); + $this->assertInstanceOf(Store\SQL::class, $store); } @@ -101,7 +101,7 @@ class StoreTest extends TestCase $store = Store::getInstance(); - $this->assertInstanceOf('SimpleSAML\Store\SQL', $store); + $this->assertInstanceOf(Store\SQL::class, $store); } @@ -132,8 +132,8 @@ class StoreTest extends TestCase /** @var \SimpleSAML\Store $store */ $store = Store::getInstance(); - $this->clearInstance($config, '\SimpleSAML\Configuration'); - $this->clearInstance($store, '\SimpleSAML\Store'); + $this->clearInstance($config, Configuration::class); + $this->clearInstance($store, Store::class); } diff --git a/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php b/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php index 53cc8a104894c412887e4c0d2583b92910a0b3ba..9c01dbeb008d05de76e603ed836f00f1028d40ea 100644 --- a/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php +++ b/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php @@ -2,6 +2,8 @@ namespace SimpleSAML\Test\Module\core\Auth\Process; +use SimpleSAML\Utils\HTTPAdapter; + /** * Test for the core:CardinalitySingle filter. */ @@ -38,7 +40,7 @@ class CardinalitySingleTest extends \PHPUnit\Framework\TestCase protected function setUp() { \SimpleSAML\Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); - $this->http = $this->getMockBuilder('SimpleSAML\Utils\HTTPAdapter') + $this->http = $this->getMockBuilder(HTTPAdapter::class) ->setMethods(['redirectTrustedURL']) ->getMock(); } diff --git a/tests/modules/core/lib/Auth/Process/CardinalityTest.php b/tests/modules/core/lib/Auth/Process/CardinalityTest.php index 3b666c25e31ce7deb784094eec2ab502128c01d2..edccfbab0a19f3a25216f4826f6beef56f82a336 100644 --- a/tests/modules/core/lib/Auth/Process/CardinalityTest.php +++ b/tests/modules/core/lib/Auth/Process/CardinalityTest.php @@ -2,6 +2,9 @@ namespace SimpleSAML\Test\Module\core\Auth\Process; +use SimpleSAML\Error\Exception as SspException; +use SimpleSAML\Utils\HTTPAdapter; + /** * Test for the core:Cardinality filter. */ @@ -38,7 +41,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase protected function setUp() { \SimpleSAML\Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); - $this->http = $this->getMockBuilder('SimpleSAML\Utils\HTTPAdapter') + $this->http = $this->getMockBuilder(HTTPAdapter::class) ->setMethods(['redirectTrustedURL']) ->getMock(); } @@ -185,7 +188,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase */ public function testMinInvalid() { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(SspException::class); $this->expectExceptionMessageRegExp('/Minimum/'); $config = [ 'mail' => ['min' => false], @@ -205,7 +208,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase */ public function testMinNegative() { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(SspException::class); $this->expectExceptionMessageRegExp('/Minimum/'); $config = [ 'mail' => ['min' => -1], @@ -225,7 +228,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase */ public function testMaxInvalid() { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(SspException::class); $this->expectExceptionMessageRegExp('/Maximum/'); $config = [ 'mail' => ['max' => false], @@ -245,7 +248,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase */ public function testMinGreaterThanMax() { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(SspException::class); $this->expectExceptionMessageRegExp('/less than/'); $config = [ 'mail' => ['min' => 2, 'max' => 1], @@ -265,7 +268,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase */ public function testInvalidAttributeName() { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(SspException::class); $this->expectExceptionMessageRegExp('/Invalid attribute/'); $config = [ ['min' => 2, 'max' => 1], diff --git a/tests/modules/core/lib/Auth/UserPassBaseTest.php b/tests/modules/core/lib/Auth/UserPassBaseTest.php index 089f3c345217f9a0d8652e966e14fd4d19299113..bb897b9eaddf27bb855b0e774a31aa69ca7dfef9 100644 --- a/tests/modules/core/lib/Auth/UserPassBaseTest.php +++ b/tests/modules/core/lib/Auth/UserPassBaseTest.php @@ -2,6 +2,10 @@ namespace SimpleSAML\Test\Module\core\Auth; +use SAML2\Constants; +use SimpleSAML\Error\Error as SspError; +use SimpleSAML\Module\core\Auth\UserPassBase; + class UserPassBaseTest extends \PHPUnit\Framework\TestCase { /** @@ -10,7 +14,7 @@ class UserPassBaseTest extends \PHPUnit\Framework\TestCase public function testAuthenticateECPCallsLoginAndSetsAttributes() { $state = [ - 'saml:Binding' => \SAML2\Constants::BINDING_PAOS, + 'saml:Binding' => Constants::BINDING_PAOS, ]; $attributes = ['attrib' => 'val']; @@ -18,7 +22,7 @@ class UserPassBaseTest extends \PHPUnit\Framework\TestCase $password = $_SERVER['PHP_AUTH_PW'] = 'password'; /** @var \SimpleSAML\Module\core\Auth\UserPassBase $stub */ - $stub = $this->getMockBuilder('\SimpleSAML\Module\core\Auth\UserPassBase') + $stub = $this->getMockBuilder(UserPassBase::class) ->disableOriginalConstructor() ->setMethods(['login']) ->getMockForAbstractClass(); @@ -43,18 +47,18 @@ class UserPassBaseTest extends \PHPUnit\Framework\TestCase */ public function testAuthenticateECPMissingUsername() { - $this->expectException(\SimpleSAML\Error\Error::class); + $this->expectException(SspError::class); $this->expectExceptionMessage('WRONGUSERPASS'); $state = [ - 'saml:Binding' => \SAML2\Constants::BINDING_PAOS, + 'saml:Binding' => Constants::BINDING_PAOS, ]; unset($_SERVER['PHP_AUTH_USER']); $_SERVER['PHP_AUTH_PW'] = 'password'; /** @var \SimpleSAML\Module\core\Auth\UserPassBase $stub */ - $stub = $this->getMockBuilder('\SimpleSAML\Module\core\Auth\UserPassBase') + $stub = $this->getMockBuilder(UserPassBase::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -67,17 +71,17 @@ class UserPassBaseTest extends \PHPUnit\Framework\TestCase */ public function testAuthenticateECPMissingPassword() { - $this->expectException(\SimpleSAML\Error\Error::class); + $this->expectException(SspError::class); $this->expectExceptionMessage('WRONGUSERPASS'); $state = [ - 'saml:Binding' => \SAML2\Constants::BINDING_PAOS, + 'saml:Binding' => Constants::BINDING_PAOS, ]; $_SERVER['PHP_AUTH_USER'] = 'username'; unset($_SERVER['PHP_AUTH_PW']); - $stub = $this->getMockBuilder('\SimpleSAML\Module\core\Auth\UserPassBase') + $stub = $this->getMockBuilder(UserPassBase::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -92,7 +96,7 @@ class UserPassBaseTest extends \PHPUnit\Framework\TestCase public function testAuthenticateECPCallsLoginWithForcedUsername() { $state = [ - 'saml:Binding' => \SAML2\Constants::BINDING_PAOS, + 'saml:Binding' => Constants::BINDING_PAOS, ]; $attributes = []; @@ -102,7 +106,7 @@ class UserPassBaseTest extends \PHPUnit\Framework\TestCase $password = $_SERVER['PHP_AUTH_PW'] = 'password'; /** @var \SimpleSAML\Module\core\Auth\UserPassBase $stub */ - $stub = $this->getMockBuilder('\SimpleSAML\Module\core\Auth\UserPassBase') + $stub = $this->getMockBuilder(UserPassBase::class) ->disableOriginalConstructor() ->setMethods(['login']) ->getMockForAbstractClass();