From 721d73f10e25dad39ee4ec3ae60c8a2feec24558 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Wed, 6 May 2020 00:57:13 +0200 Subject: [PATCH] tests: namespace cleanup --- lib/SimpleSAML/Store.php | 3 +- tests/Utils/ReduceSpillOverTest.php | 11 ++- tests/Utils/SpTester.php | 3 +- tests/lib/SimpleSAML/Auth/SimpleTest.php | 19 ++-- tests/lib/SimpleSAML/Auth/SourceTest.php | 4 +- tests/lib/SimpleSAML/Auth/StateTest.php | 11 ++- tests/lib/SimpleSAML/ConfigurationTest.php | 99 ++++++++++--------- tests/lib/SimpleSAML/DatabaseTest.php | 12 ++- tests/lib/SimpleSAML/Locale/TranslateTest.php | 3 +- .../Metadata/MetaDataStorageSourceTest.php | 17 ++-- .../SimpleSAML/Metadata/SAMLParserTest.php | 20 ++-- tests/lib/SimpleSAML/ModuleTest.php | 10 +- tests/lib/SimpleSAML/Utils/AttributesTest.php | 7 +- .../SimpleSAML/Utils/Config/MetadataTest.php | 22 +++-- tests/lib/SimpleSAML/Utils/CryptoTest.php | 18 ++-- tests/lib/SimpleSAML/Utils/EMailTest.php | 12 ++- tests/lib/SimpleSAML/Utils/HTTPTest.php | 8 +- tests/lib/SimpleSAML/Utils/SystemTest.php | 3 +- tests/lib/SimpleSAML/Utils/TimeTest.php | 20 ++-- tests/lib/SimpleSAML/Utils/XMLTest.php | 89 +++++++++-------- tests/lib/SimpleSAML/XML/ErrorsTest.php | 3 +- tests/lib/SimpleSAML/XML/ParserTest.php | 5 +- tests/lib/SimpleSAML/XML/ValidatorTest.php | 11 ++- .../lib/Auth/Process/AttributeAddTest.php | 8 +- .../lib/Auth/Process/AttributeAlterTest.php | 16 +-- .../lib/Auth/Process/AttributeCopyTest.php | 8 +- .../lib/Auth/Process/AttributeLimitTest.php | 13 ++- .../lib/Auth/Process/AttributeMapTest.php | 3 +- .../Auth/Process/AttributeValueMapTest.php | 5 +- .../Auth/Process/CardinalitySingleTest.php | 6 +- .../core/lib/Auth/Process/CardinalityTest.php | 9 +- .../modules/core/lib/Auth/Process/PHPTest.php | 8 +- .../lib/Auth/Process/ScopeAttributeTest.php | 3 +- .../Auth/Process/ScopeFromAttributeTest.php | 3 +- .../core/lib/Auth/Process/TargetedIDTest.php | 12 ++- .../core/lib/Auth/UserPassBaseTest.php | 3 +- .../core/lib/Auth/UserPassOrgBaseTest.php | 3 +- .../modules/core/lib/Controller/LoginTest.php | 5 +- .../lib/Storage/SQLPermanentStorageTest.php | 6 +- .../lib/Auth/Source/MultiAuthTest.php | 18 ++-- .../lib/Auth/Process/FilterScopesTest.php | 3 +- .../lib/Auth/Source/Auth_Source_SP_Test.php | 20 ++-- tests/modules/saml/lib/IdP/SQLNameIDTest.php | 3 +- tests/routers/configLoader.php | 6 +- 44 files changed, 327 insertions(+), 244 deletions(-) diff --git a/lib/SimpleSAML/Store.php b/lib/SimpleSAML/Store.php index 3f2c35e27..18a18cf73 100644 --- a/lib/SimpleSAML/Store.php +++ b/lib/SimpleSAML/Store.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML; +use Exception; use SimpleSAML\Error; /** @@ -57,7 +58,7 @@ abstract class Store implements Utils\ClearableState // datastore from module try { $className = Module::resolveClass($storeType, 'Store', '\SimpleSAML\Store'); - } catch (\Exception $e) { + } catch (Exception $e) { $c = $config->toArray(); $c['store.type'] = 'phpsession'; throw new Error\CriticalConfigurationError( diff --git a/tests/Utils/ReduceSpillOverTest.php b/tests/Utils/ReduceSpillOverTest.php index d276f893c..6554d5587 100644 --- a/tests/Utils/ReduceSpillOverTest.php +++ b/tests/Utils/ReduceSpillOverTest.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Utils; +use SimpleSAML\Configuration; +use SimpleSAML\Error; + /** * Test that ensures state doesn't spill over between tests * @package SimpleSAML\Test\Utils @@ -17,8 +20,8 @@ class ReduceSpillOverTest extends ClearStateTestCase public function testSetState(): void { $_SERVER['QUERY_STRING'] = 'a=b'; - \SimpleSAML\Configuration::loadFromArray(['a' => 'b'], '[ARRAY]', 'simplesaml'); - $this->assertEquals('b', \SimpleSAML\Configuration::getInstance()->getString('a')); + Configuration::loadFromArray(['a' => 'b'], '[ARRAY]', 'simplesaml'); + $this->assertEquals('b', Configuration::getInstance()->getString('a')); putenv('SIMPLESAMLPHP_CONFIG_DIR=' . __DIR__); } @@ -35,9 +38,9 @@ class ReduceSpillOverTest extends ClearStateTestCase $env = getenv('SIMPLESAMLPHP_CONFIG_DIR'); $this->assertFalse($env); try { - \SimpleSAML\Configuration::getInstance(); + Configuration::getInstance(); $this->fail('Expected config configured in other tests to no longer be valid'); - } catch (\SimpleSAML\Error\ConfigurationError $error) { + } catch (Error\ConfigurationError $error) { // Expected error } } diff --git a/tests/Utils/SpTester.php b/tests/Utils/SpTester.php index bca15ff61..64ef75503 100644 --- a/tests/Utils/SpTester.php +++ b/tests/Utils/SpTester.php @@ -8,13 +8,14 @@ use ReflectionObject; use SAML2\AuthnRequest; use SAML2\Binding; use SimpleSAML\Configuration; +use SimpleSAML\Module\saml\Auth\Source\SP; /** * Wrap the SSP \SimpleSAML\Module\saml\Auth\Source\SP class * - Use introspection to make startSSO2Test available * - Override sendSAML2AuthnRequest() to catch the AuthnRequest being sent */ -class SpTester extends \SimpleSAML\Module\saml\Auth\Source\SP +class SpTester extends SP { /** * @param array $info diff --git a/tests/lib/SimpleSAML/Auth/SimpleTest.php b/tests/lib/SimpleSAML/Auth/SimpleTest.php index 0d41f2052..7acd28041 100644 --- a/tests/lib/SimpleSAML/Auth/SimpleTest.php +++ b/tests/lib/SimpleSAML/Auth/SimpleTest.php @@ -4,13 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Test\Auth; +use ReflectionClass; use SimpleSAML\Auth; +use SimpleSAML\Configuration; +use SimpleSAML\Test\Utils\ClearStateTestCase; /** * Tests for \SimpleSAML\Auth\Simple * */ -class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase +class SimpleTest extends ClearStateTestCase { /** * @test @@ -18,7 +21,7 @@ class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetProcessedURL(): void { - $class = new \ReflectionClass(Auth\Simple::class); + $class = new ReflectionClass(Auth\Simple::class); $method = $class->getMethod('getProcessedURL'); $method->setAccessible(true); @@ -26,13 +29,13 @@ class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $_SERVER['REQUEST_URI'] = '/'; // test merging configuration option with passed URL - \SimpleSAML\Configuration::loadFromArray([ + Configuration::loadFromArray([ 'application' => [ 'baseURL' => 'https://example.org' ] ], '[ARRAY]', 'simplesaml'); - $s = new \SimpleSAML\Auth\Simple(''); + $s = new Auth\Simple(''); $this->assertEquals('https://example.org/', $method->invokeArgs($s, [null])); @@ -54,12 +57,12 @@ class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $this->assertEquals('https://example.org/foo/bar?a=b#fragment', $method->invokeArgs($s, [null])); // test config option with ending with / and port - \SimpleSAML\Configuration::loadFromArray([ + Configuration::loadFromArray([ 'application' => [ 'baseURL' => 'http://example.org:8080/' ] ], '[ARRAY]', 'simplesaml'); - $s = new \SimpleSAML\Auth\Simple(''); + $s = new Auth\Simple(''); $this->assertEquals('http://example.org:8080/foo/bar?a=b#fragment', $method->invokeArgs($s, [null])); // test again with a relative URL as a parameter @@ -70,8 +73,8 @@ class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase // now test with no configuration $_SERVER['SERVER_NAME'] = 'example.org'; - \SimpleSAML\Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); - $s = new \SimpleSAML\Auth\Simple(''); + Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); + $s = new Auth\Simple(''); $this->assertEquals('http://example.org:1234/foo/bar?a=b#fragment', $method->invokeArgs($s, [null])); // no configuration, https and port diff --git a/tests/lib/SimpleSAML/Auth/SourceTest.php b/tests/lib/SimpleSAML/Auth/SourceTest.php index 0fa611cd2..c8d2cdcb0 100644 --- a/tests/lib/SimpleSAML/Auth/SourceTest.php +++ b/tests/lib/SimpleSAML/Auth/SourceTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Test\Auth; +use ReflectionClass; +use SimpleSAML\Auth; use SimpleSAML\Test\Utils\ClearStateTestCase; use SimpleSAML\Test\Utils\TestAuthSource; use SimpleSAML\Test\Utils\TestAuthSourceFactory; @@ -18,7 +20,7 @@ class SourceTest extends ClearStateTestCase */ public function testParseAuthSource(): void { - $class = new \ReflectionClass(\SimpleSAML\Auth\Source::class); + $class = new ReflectionClass(Auth\Source::class); $method = $class->getMethod('parseAuthSource'); $method->setAccessible(true); diff --git a/tests/lib/SimpleSAML/Auth/StateTest.php b/tests/lib/SimpleSAML/Auth/StateTest.php index dda7f439d..43b153dc0 100644 --- a/tests/lib/SimpleSAML/Auth/StateTest.php +++ b/tests/lib/SimpleSAML/Auth/StateTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Auth; use PHPUnit\Framework\TestCase; +use SimpleSAML\Auth; /** * Tests for \SimpleSAML\Auth\State @@ -31,7 +32,7 @@ class StateTest extends TestCase $expected = $mandatory; $this->assertEquals( $expected, - \SimpleSAML\Auth\State::getPersistentAuthData($state), + Auth\State::getPersistentAuthData($state), 'Mandatory state attributes did not survive as expected' . print_r($expected, true) ); @@ -41,7 +42,7 @@ class StateTest extends TestCase $expected = $state; $this->assertEquals( $expected, - \SimpleSAML\Auth\State::getPersistentAuthData($state), + Auth\State::getPersistentAuthData($state), 'Some error occurred with missing mandatory parameters' ); @@ -54,7 +55,7 @@ class StateTest extends TestCase $expected = $mandatory; $this->assertEquals( $expected, - \SimpleSAML\Auth\State::getPersistentAuthData($state), + Auth\State::getPersistentAuthData($state), 'Additional parameters survived' ); @@ -66,7 +67,7 @@ class StateTest extends TestCase unset($expected['PersistentAuthData']); $this->assertEquals( $expected, - \SimpleSAML\Auth\State::getPersistentAuthData($state), + Auth\State::getPersistentAuthData($state), 'Some error occurred with additional, persistent parameters' ); @@ -77,7 +78,7 @@ class StateTest extends TestCase unset($expected['PersistentAuthData']); $this->assertEquals( $expected, - \SimpleSAML\Auth\State::getPersistentAuthData($state), + Auth\State::getPersistentAuthData($state), 'Some error occurred with additional, persistent parameters, and no mandatory ones' ); } diff --git a/tests/lib/SimpleSAML/ConfigurationTest.php b/tests/lib/SimpleSAML/ConfigurationTest.php index eb0bade19..4992c3404 100644 --- a/tests/lib/SimpleSAML/ConfigurationTest.php +++ b/tests/lib/SimpleSAML/ConfigurationTest.php @@ -4,13 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Test; +use Exception; +use SAML2\Constants; use SimpleSAML\Configuration; -use SimpleSAML\Error\CriticalConfigurationError; +use SimpleSAML\Error; +use SimpleSAML\Test\Utils\ClearStateTestCase; /** * Tests for \SimpleSAML\Configuration */ -class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase +class ConfigurationTest extends ClearStateTestCase { /** * Test \SimpleSAML\Configuration::getVersion() @@ -29,7 +32,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testLoadDefaultInstance(): void { - $this->expectException(CriticalConfigurationError::class); + $this->expectException(Error\CriticalConfigurationError::class); Configuration::loadFromArray(['key' => 'value'], '', 'dummy'); Configuration::getInstance(); } @@ -45,7 +48,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase try { Configuration::getInstance(); $this->fail('Exception expected'); - } catch (\SimpleSAML\Error\CriticalConfigurationError $var) { + } catch (Error\CriticalConfigurationError $var) { // This exception is expected. } /* @@ -84,7 +87,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetValueRequired(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([]); $c->getValue('missing', Configuration::REQUIRED_OPTION); } @@ -269,7 +272,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetBooleanMissing(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([]); $c->getBoolean('missing_opt'); } @@ -281,7 +284,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetBooleanWrong(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'wrong' => 'true', ]); @@ -309,7 +312,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetStringMissing(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([]); $c->getString('missing_opt'); } @@ -321,7 +324,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetStringWrong(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'wrong' => false, ]); @@ -349,7 +352,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetIntegerMissing(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([]); $c->getInteger('missing_opt'); } @@ -361,7 +364,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetIntegerWrong(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'wrong' => '42', ]); @@ -389,7 +392,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetIntegerRangeBelow(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'int_opt' => 9, ]); @@ -403,7 +406,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetIntegerRangeAbove(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'int_opt' => 101, ]); @@ -431,7 +434,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetValueValidateWrong(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'd', ]); @@ -459,7 +462,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetArrayWrong(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'not_an_array', ]); @@ -508,7 +511,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetArrayizeStringWrongValue(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => ['a', 'b', 42], ]); @@ -540,7 +543,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetConfigItemWrong(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'not_an_array', ]); @@ -601,14 +604,14 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase [ [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ], ], // define the ResponseLocation too [ [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, 'ResponseLocation' => 'https://example.com/endpoint.php', ], ], @@ -617,12 +620,12 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase [ 'index' => 1, 'Location' => 'https://www1.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, ], [ 'index' => 2, 'Location' => 'https://www2.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ], ], // make sure isDefault has priority over indexes @@ -630,13 +633,13 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase [ 'index' => 1, 'Location' => 'https://www2.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ], [ 'index' => 2, 'isDefault' => true, 'Location' => 'https://www1.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, ], ], // make sure endpoints with invalid bindings are ignored and those marked as NOT default are still used @@ -650,7 +653,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase 'index' => 2, 'isDefault' => false, 'Location' => 'https://www2.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ], ], ]; @@ -658,34 +661,34 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase // output should be completed with the default binding (HTTP-POST for ACS) [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ], // we should just get the first endpoint with the default binding [ 'Location' => 'https://www1.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ], // if we specify the binding, we should get it back [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST + 'Binding' => Constants::BINDING_HTTP_POST ], // if we specify ResponseLocation, we should get it back too [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, 'ResponseLocation' => 'https://example.com/endpoint.php', ], // indexes must NOT be taken into account, order is the only thing that matters here [ 'Location' => 'https://www1.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, 'index' => 1, ], // isDefault must have higher priority than indexes [ 'Location' => 'https://www1.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, 'isDefault' => true, 'index' => 2, ], @@ -694,7 +697,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase 'index' => 2, 'isDefault' => false, 'Location' => 'https://www2.example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_POST, + 'Binding' => Constants::BINDING_HTTP_POST, ] ]; @@ -709,11 +712,11 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase ]; $valid_bindings = [ - \SAML2\Constants::BINDING_HTTP_POST, - \SAML2\Constants::BINDING_HTTP_REDIRECT, - \SAML2\Constants::BINDING_HOK_SSO, - \SAML2\Constants::BINDING_HTTP_ARTIFACT, - \SAML2\Constants::BINDING_SOAP, + Constants::BINDING_HTTP_POST, + Constants::BINDING_HTTP_REDIRECT, + Constants::BINDING_HOK_SSO, + Constants::BINDING_HTTP_ARTIFACT, + Constants::BINDING_SOAP, ]; // run all general tests with AssertionConsumerService endpoint type @@ -731,14 +734,14 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $this->assertEquals( [ 'Location' => 'https://example.com/ars', - 'Binding' => \SAML2\Constants::BINDING_SOAP, + 'Binding' => Constants::BINDING_SOAP, ], $c->getDefaultEndpoint('ArtifactResolutionService') ); $this->assertEquals( [ 'Location' => 'https://example.com/slo', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, ], $c->getDefaultEndpoint('SingleLogoutService') ); @@ -755,7 +758,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase try { $c->getDefaultEndpoint('SingleLogoutService', $valid_bindings); $this->fail('Failed to detect invalid endpoint binding.'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertEquals( '[ARRAY][\'SingleLogoutService\']:Could not find a supported SingleLogoutService ' . 'endpoint.', $e->getMessage() @@ -766,7 +769,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase try { $c->getDefaultEndpoint('SingleSignOnService'); $this->fail('No valid metadata set specified.'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertStringStartsWith('Missing default binding for', $e->getMessage()); } } @@ -787,7 +790,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $e = [ [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, 'ResponseLocation' => 'https://example.com/response.php', ] ]; @@ -838,7 +841,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase [ [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, 'ResponseLocation' => 1234, ], ], @@ -846,7 +849,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase [ [ 'Location' => 'https://example.com/endpoint.php', - 'Binding' => \SAML2\Constants::BINDING_HTTP_REDIRECT, + 'Binding' => Constants::BINDING_HTTP_REDIRECT, 'index' => 'string', ], ], @@ -870,7 +873,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase $c = Configuration::loadFromArray($a); try { $c->getEndpoints('SingleSignOnService'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertStringEndsWith($msgs[$i], $e->getMessage()); } } @@ -902,7 +905,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetLocalizedStringNotArray(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => 42, ]); @@ -916,7 +919,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetLocalizedStringNotStringKey(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => [42 => 'text'], ]); @@ -930,7 +933,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetLocalizedStringNotStringValue(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $c = Configuration::loadFromArray([ 'opt' => ['en' => 42], ]); @@ -944,7 +947,7 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testGetConfigNonexistentFile(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); Configuration::getConfig('nonexistent-nopreload.php'); } diff --git a/tests/lib/SimpleSAML/DatabaseTest.php b/tests/lib/SimpleSAML/DatabaseTest.php index 2a059c8c6..579025af2 100644 --- a/tests/lib/SimpleSAML/DatabaseTest.php +++ b/tests/lib/SimpleSAML/DatabaseTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Test; +use Exception; +use PDO; use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionMethod; @@ -44,7 +46,7 @@ class DatabaseTest extends TestCase */ protected static function getMethod($getMethod) { - $class = new \ReflectionClass(Database::class); + $class = new ReflectionClass(Database::class); $method = $class->getMethod($getMethod); $method->setAccessible(true); return $method; @@ -88,7 +90,7 @@ class DatabaseTest extends TestCase */ public function connectionFailure(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'database.dsn' => 'mysql:host=localhost;dbname=saml', 'database.username' => 'notauser', @@ -268,7 +270,7 @@ class DatabaseTest extends TestCase $ssp_value = md5(strval(rand(0, 10000))); $stmt = $this->db->write( "INSERT INTO $table (ssp_key, ssp_value) VALUES (:ssp_key, :ssp_value)", - ['ssp_key' => [$ssp_key, \PDO::PARAM_INT], 'ssp_value' => $ssp_value] + ['ssp_key' => [$ssp_key, PDO::PARAM_INT], 'ssp_value' => $ssp_value] ); $this->assertEquals(1, $stmt, "Could not insert data into $table."); @@ -286,7 +288,7 @@ class DatabaseTest extends TestCase */ public function readFailure(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $table = $this->db->applyPrefix("sspdbt"); $this->assertEquals($this->config->getString('database.prefix') . "sspdbt", $table); @@ -302,7 +304,7 @@ class DatabaseTest extends TestCase */ public function noSuchTable(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->db->write("DROP TABLE phpunit_nonexistent"); } diff --git a/tests/lib/SimpleSAML/Locale/TranslateTest.php b/tests/lib/SimpleSAML/Locale/TranslateTest.php index 534d2660b..f08de6f33 100644 --- a/tests/lib/SimpleSAML/Locale/TranslateTest.php +++ b/tests/lib/SimpleSAML/Locale/TranslateTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Locale; use PHPUnit\Framework\TestCase; +use SimpleSAML\Configuration; use SimpleSAML\Locale\Translate; class TranslateTest extends TestCase @@ -16,7 +17,7 @@ class TranslateTest extends TestCase public function testNoop(): void { // test default - $c = \SimpleSAML\Configuration::loadFromArray([]); + $c = Configuration::loadFromArray([]); $t = new Translate($c); $testString = 'Blablabla'; $this->assertEquals($testString, $t->noop($testString)); diff --git a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php index 75c8724cb..35f33f0d1 100644 --- a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php +++ b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php @@ -4,13 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Test\Metadata; +use Exception; +use PHPUnit\Framework\TestCase; use SimpleSAML\Configuration; +use SimpleSAML\Metadata\MetaDataStorageSource; /** * Class MetaDataStorageSourceTest */ -class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase +class MetaDataStorageSourceTest extends TestCase { /** * Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig XML bad source @@ -18,8 +21,8 @@ class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase */ public function testBadXMLSource(): void { - $this->expectException(\Exception::class); - \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type" => "xml", "foo" => "baa"]); + $this->expectException(Exception::class); + MetaDataStorageSource::getSource(["type" => "xml", "foo" => "baa"]); } @@ -29,12 +32,12 @@ class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase */ public function testInvalidStaticXMLSource(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $strTestXML = " <EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"https://saml.idp/entityid\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\"> </EntityDescriptor> "; - \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type" => "xml", "xml" => $strTestXML]); + MetaDataStorageSource::getSource(["type" => "xml", "xml" => $strTestXML]); } @@ -49,7 +52,7 @@ class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase // The primary test here is that - in contrast to the others above - this loads without error // As a secondary thing, check that the entity ID from the static source provided can be extracted - $source = \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type" => "xml", "xml" => $strTestXML]); + $source = MetaDataStorageSource::getSource(["type" => "xml", "xml" => $strTestXML]); $idpSet = $source->getMetadataSet("saml20-idp-remote"); $this->assertArrayHasKey( $testEntityId, @@ -82,7 +85,7 @@ class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase $xml2 </EntitiesDescriptor> "; - $source = \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type" => "xml", "xml" => $strTestXML]); + $source = MetaDataStorageSource::getSource(["type" => "xml", "xml" => $strTestXML]); // search that is a single entity $entities = $source->getMetaDataForEntities([$entityId2], "saml20-idp-remote"); $this->assertCount(1, $entities, 'Only 1 entity loaded'); diff --git a/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php b/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php index ac5187ce0..95bdc3572 100644 --- a/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php +++ b/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php @@ -4,8 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Test\Metadata; +use DOMDocument; use PHPUnit\Framework\TestCase; use RobRichards\XMLSecLibs\XMLSecurityDSig; +use SAML2\DOMDocumentFactory; use SimpleSAML\XML\Signer; use SimpleSAML\Metadata\SAMLParser; @@ -24,7 +26,7 @@ class SAMLParserTest extends \SimpleSAML\Test\SigningTestCase 'registrationAuthority' => 'https://incommon.org', ]; - $document = \SAML2\DOMDocumentFactory::fromString( + $document = DOMDocumentFactory::fromString( <<<XML <EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi"> <EntityDescriptor entityID="theEntityID"> @@ -38,7 +40,7 @@ XML ); - $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement); + $entities = SAMLParser::parseDescriptorsElement($document->documentElement); $this->assertArrayHasKey('theEntityID', $entities); // RegistrationInfo is accessible in the SP or IDP metadata accessors /** @var array $metadata */ @@ -58,7 +60,7 @@ XML 'registrationAuthority' => 'https://incommon.org', ]; - $document = \SAML2\DOMDocumentFactory::fromString( + $document = DOMDocumentFactory::fromString( <<<XML <EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi"> <Extensions> @@ -82,7 +84,7 @@ XML XML ); - $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement); + $entities = SAMLParser::parseDescriptorsElement($document->documentElement); $this->assertArrayHasKey('theEntityID', $entities); $this->assertArrayHasKey('subEntityId', $entities); // RegistrationInfo is accessible in the SP or IDP metadata accessors @@ -106,7 +108,7 @@ XML */ public function testAttributeConsumingServiceParsing(): void { - $document = \SAML2\DOMDocumentFactory::fromString( + $document = DOMDocumentFactory::fromString( <<<XML <EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi"> <EntityDescriptor entityID="theEntityID"> @@ -129,7 +131,7 @@ XML XML ); - $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement); + $entities = SAMLParser::parseDescriptorsElement($document->documentElement); $this->assertArrayHasKey('theEntityID', $entities); /** @var array $metadata */ @@ -155,7 +157,7 @@ XML */ public function makeTestDocument(): \DOMDocument { - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $doc->loadXML( <<<XML <?xml version="1.0"?> @@ -215,7 +217,7 @@ XML 'name' => ['en' => 'DisplayName', 'af' => 'VertoonNaam'], ]; - $document = \SAML2\DOMDocumentFactory::fromString( + $document = DOMDocumentFactory::fromString( <<<XML <EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui"> <EntityDescriptor entityID="theEntityID"> @@ -247,7 +249,7 @@ XML XML ); - $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement); + $entities = SAMLParser::parseDescriptorsElement($document->documentElement); $this->assertArrayHasKey('theEntityID', $entities); // Various MDUI elements are accessible /** @var array $metadata */ diff --git a/tests/lib/SimpleSAML/ModuleTest.php b/tests/lib/SimpleSAML/ModuleTest.php index b52e49f3f..4dae7539d 100644 --- a/tests/lib/SimpleSAML/ModuleTest.php +++ b/tests/lib/SimpleSAML/ModuleTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test; +use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Configuration; use SimpleSAML\Module; class ModuleTest extends TestCase @@ -40,7 +42,7 @@ class ModuleTest extends TestCase */ public function testGetModuleURL(): void { - \SimpleSAML\Configuration::loadFromArray([ + Configuration::loadFromArray([ 'baseurlpath' => 'https://example.com/simplesaml/' ], '', 'simplesaml'); $this->assertEquals( @@ -75,7 +77,7 @@ class ModuleTest extends TestCase */ public function testResolveClassNoModule(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); Module::resolveClass('nomodule', ''); } @@ -87,7 +89,7 @@ class ModuleTest extends TestCase */ public function testResolveClassNotFound(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); Module::resolveClass('core:Missing', ''); } @@ -99,7 +101,7 @@ class ModuleTest extends TestCase */ public function testResolveClassNotSubclass(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); Module::resolveClass('core:PHP', 'Auth_Process', '\Exception'); } diff --git a/tests/lib/SimpleSAML/Utils/AttributesTest.php b/tests/lib/SimpleSAML/Utils/AttributesTest.php index a3c8d5dd0..74f3f8bb0 100644 --- a/tests/lib/SimpleSAML/Utils/AttributesTest.php +++ b/tests/lib/SimpleSAML/Utils/AttributesTest.php @@ -6,6 +6,7 @@ namespace SimpleSAML\Test\Utils; use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use SimpleSAML\Error; use SimpleSAML\Utils\Attributes; /** @@ -45,7 +46,7 @@ class AttributesTest extends TestCase 'attribute' => ['value'], ]; $expected = 'missing'; - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $this->expectExceptionMessage("No such attribute '" . $expected . "' found."); Attributes::getExpectedAttribute($attributes, $expected); } @@ -62,7 +63,7 @@ class AttributesTest extends TestCase 'attribute' => [], ]; $expected = 'attribute'; - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $this->expectExceptionMessage("Empty attribute '" . $expected . "'.'"); Attributes::getExpectedAttribute($attributes, $expected); } @@ -82,7 +83,7 @@ class AttributesTest extends TestCase ], ]; $expected = 'attribute'; - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $this->expectExceptionMessage( 'More than one value found for the attribute, multiple values not allowed.' ); diff --git a/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php b/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php index 17cd4d361..f8480392c 100644 --- a/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php +++ b/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php @@ -5,7 +5,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Utils\Config; use DOMDocument; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use SAML2\Constants; use SimpleSAML\Utils\Config\Metadata; use TypeError; @@ -26,7 +28,7 @@ class MetadataTest extends TestCase ]; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage()); } @@ -36,7 +38,7 @@ class MetadataTest extends TestCase ]; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage()); } @@ -106,7 +108,7 @@ class MetadataTest extends TestCase $contact['givenName'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals('"givenName" must be a string and cannot be empty.', $e->getMessage()); } } @@ -120,7 +122,7 @@ class MetadataTest extends TestCase $contact['surName'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals('"surName" must be a string and cannot be empty.', $e->getMessage()); } } @@ -134,7 +136,7 @@ class MetadataTest extends TestCase $contact['company'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals('"company" must be a string and cannot be empty.', $e->getMessage()); } } @@ -148,7 +150,7 @@ class MetadataTest extends TestCase $contact['emailAddress'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals( '"emailAddress" must be a string or an array and cannot be empty.', $e->getMessage() @@ -160,7 +162,7 @@ class MetadataTest extends TestCase $contact['emailAddress'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals( 'Email addresses must be a string and cannot be empty.', $e->getMessage() @@ -183,7 +185,7 @@ class MetadataTest extends TestCase $contact['telephoneNumber'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals( '"telephoneNumber" must be a string or an array and cannot be empty.', $e->getMessage() @@ -195,7 +197,7 @@ class MetadataTest extends TestCase $contact['telephoneNumber'] = $type; try { Metadata::getContact($contact); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertEquals('Telephone numbers must be a string and cannot be empty.', $e->getMessage()); } } @@ -272,7 +274,7 @@ class MetadataTest extends TestCase // Test null or unset $nameIdPolicy = null; $this->assertEquals( - ['Format' => \SAML2\Constants::NAMEID_TRANSIENT, 'AllowCreate' => true], + ['Format' => Constants::NAMEID_TRANSIENT, 'AllowCreate' => true], Metadata::parseNameIdPolicy($nameIdPolicy) ); diff --git a/tests/lib/SimpleSAML/Utils/CryptoTest.php b/tests/lib/SimpleSAML/Utils/CryptoTest.php index 3426d0aa1..d2cc235c5 100644 --- a/tests/lib/SimpleSAML/Utils/CryptoTest.php +++ b/tests/lib/SimpleSAML/Utils/CryptoTest.php @@ -6,7 +6,9 @@ namespace SimpleSAML\Test\Utils; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; +use ReflectionMethod; use SimpleSAML\Configuration; +use SimpleSAML\Error; use SimpleSAML\Utils\Crypto; /** @@ -55,11 +57,11 @@ class CryptoTest extends TestCase public function testAesDecrypt(): void { if (!extension_loaded('openssl')) { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); } $secret = 'SUPER_SECRET_SALT'; - $m = new \ReflectionMethod('\SimpleSAML\Utils\Crypto', 'aesDecryptInternal'); + $m = new ReflectionMethod('\SimpleSAML\Utils\Crypto', 'aesDecryptInternal'); $m->setAccessible(true); $plaintext = 'SUPER_SECRET_TEXT'; @@ -79,12 +81,12 @@ class CryptoTest extends TestCase public function testAesEncrypt(): void { if (!extension_loaded('openssl')) { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); } $secret = 'SUPER_SECRET_SALT'; - $e = new \ReflectionMethod('\SimpleSAML\Utils\Crypto', 'aesEncryptInternal'); - $d = new \ReflectionMethod('\SimpleSAML\Utils\Crypto', 'aesDecryptInternal'); + $e = new ReflectionMethod('\SimpleSAML\Utils\Crypto', 'aesEncryptInternal'); + $d = new ReflectionMethod('\SimpleSAML\Utils\Crypto', 'aesDecryptInternal'); $e->setAccessible(true); $d->setAccessible(true); @@ -205,7 +207,7 @@ PHP; */ public function testLoadPrivateKeyRequiredMetadataMissing(): void { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $config = new Configuration([], 'test'); $required = true; @@ -234,7 +236,7 @@ PHP; */ public function testLoadPrivateKeyMissingFile(): void { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $config = new Configuration(['privatekey' => 'nonexistant'], 'test'); Crypto::loadPrivateKey($config, false, '', true); @@ -322,7 +324,7 @@ PHP; */ public function testLoadPublicKeyRequiredMetadataMissing(): void { - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $config = new Configuration([], 'test'); $required = true; diff --git a/tests/lib/SimpleSAML/Utils/EMailTest.php b/tests/lib/SimpleSAML/Utils/EMailTest.php index 8bdcbb24b..dae13bb18 100644 --- a/tests/lib/SimpleSAML/Utils/EMailTest.php +++ b/tests/lib/SimpleSAML/Utils/EMailTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Test\Utils; +use Exception; +use InvalidArgumentException; use SimpleSAML\Configuration; use SimpleSAML\Test\Utils\TestCase; use SimpleSAML\Utils\EMail; @@ -34,7 +36,7 @@ class EMailTest extends ClearStateTestCase */ public function testMailFromDefaultConfigurationException(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); new EMail('test', null, 'phpunit@simplesamlphp.org'); } @@ -45,7 +47,7 @@ class EMailTest extends ClearStateTestCase */ public function testInvalidFromAddressException(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); new EMail('test', "phpunit@simplesamlphp.org\nLorem Ipsum", 'phpunit@simplesamlphp.org'); } @@ -56,7 +58,7 @@ class EMailTest extends ClearStateTestCase */ public function testInvalidToAddressException(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); new EMail('test', 'phpunit@simplesamlphp.org', "phpunit@simplesamlphp.org\nLorem Ipsum"); } @@ -108,7 +110,7 @@ class EMailTest extends ClearStateTestCase ]), '[ARRAY]', 'simplesaml'); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new Email('Test', 'phpunit@simplesamlphp.org', 'phpunit@simplesamlphp.org'); // reset the configuration @@ -127,7 +129,7 @@ class EMailTest extends ClearStateTestCase // set the transport option to smtp but don't set any transport options (invalid state) // NOTE: this is the same method that the constructor calls, so this should be logically equivalent // to setting it via the configuration file. - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $email->setTransportMethod('smtp'); } diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php index ec02f0226..96ce29e4e 100644 --- a/tests/lib/SimpleSAML/Utils/HTTPTest.php +++ b/tests/lib/SimpleSAML/Utils/HTTPTest.php @@ -5,9 +5,11 @@ declare(strict_types=1); namespace SimpleSAML\Test\Utils; use PHPUnit\Framework\TestCase; + +use SimpleSAML\Configuration; +use SimpleSAML\Error; use SimpleSAML\Test\Utils\ClearStateTestCase; use SimpleSAML\Utils\HTTP; -use SimpleSAML\Configuration; use Webmozart\Assert\Assert; class HTTPTest extends ClearStateTestCase @@ -419,7 +421,7 @@ class HTTPTest extends ClearStateTestCase $_SERVER['REQUEST_URI'] = '/module.php'; - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); HTTP::checkURLAllowed('https://app.example.com.evil.com'); $_SERVER = $original; @@ -504,7 +506,7 @@ class HTTPTest extends ClearStateTestCase */ public function testSetCookieInsecure(): void { - $this->expectException(\SimpleSAML\Error\CannotSetCookie::class); + $this->expectException(Error\CannotSetCookie::class); $original = $_SERVER; Configuration::loadFromArray([ diff --git a/tests/lib/SimpleSAML/Utils/SystemTest.php b/tests/lib/SimpleSAML/Utils/SystemTest.php index ceb96534f..ab10c1c71 100644 --- a/tests/lib/SimpleSAML/Utils/SystemTest.php +++ b/tests/lib/SimpleSAML/Utils/SystemTest.php @@ -9,6 +9,7 @@ use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use ReflectionClass; use SimpleSAML\Configuration; +use SimpleSAML\Error; use SimpleSAML\Utils\System; /** @@ -278,7 +279,7 @@ class SystemTest extends TestCase chmod($tempdir, 0440); - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); System::getTempDir(); $this->clearInstance($config, Configuration::class); diff --git a/tests/lib/SimpleSAML/Utils/TimeTest.php b/tests/lib/SimpleSAML/Utils/TimeTest.php index 7319fe57b..55dc074c8 100644 --- a/tests/lib/SimpleSAML/Utils/TimeTest.php +++ b/tests/lib/SimpleSAML/Utils/TimeTest.php @@ -4,7 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Test\Utils; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use ReflectionProperty; +use SimpleSAML\Configuration; +use SimpleSAML\Error; use SimpleSAML\Utils\Time; class TimeTest extends TestCase @@ -40,31 +44,31 @@ class TimeTest extends TestCase } // test guessing timezone from the OS - \SimpleSAML\Configuration::loadFromArray(['timezone' => null], '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray(['timezone' => null], '[ARRAY]', 'simplesaml'); @Time::initTimezone(); $this->assertEquals($os, @date_default_timezone_get()); // clear initialization - $c = new \ReflectionProperty('\SimpleSAML\Utils\Time', 'tz_initialized'); + $c = new ReflectionProperty('\SimpleSAML\Utils\Time', 'tz_initialized'); $c->setAccessible(true); $c->setValue(false); // test unknown timezone - \SimpleSAML\Configuration::loadFromArray(['timezone' => 'INVALID'], '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray(['timezone' => 'INVALID'], '[ARRAY]', 'simplesaml'); try { @Time::initTimezone(); $this->fail('Failed to recognize an invalid timezone.'); - } catch (\SimpleSAML\Error\Exception $e) { + } catch (Error\Exception $e) { $this->assertEquals('Invalid timezone set in the "timezone" option in config.php.', $e->getMessage()); } // test a valid timezone - \SimpleSAML\Configuration::loadFromArray(['timezone' => $tz], '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray(['timezone' => $tz], '[ARRAY]', 'simplesaml'); @Time::initTimezone(); $this->assertEquals($tz, @date_default_timezone_get()); // make sure initialization happens only once - \SimpleSAML\Configuration::loadFromArray(['timezone' => 'Europe/Madrid'], '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray(['timezone' => 'Europe/Madrid'], '[ARRAY]', 'simplesaml'); @Time::initTimezone(); $this->assertEquals($tz, @date_default_timezone_get()); } @@ -143,14 +147,14 @@ class TimeTest extends TestCase // invalid string Time::parseDuration('abcdefg'); $this->fail("Did not fail with invalid ISO 8601 duration."); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertStringStartsWith('Invalid ISO 8601 duration: ', $e->getMessage()); } try { // missing T delimiter Time::parseDuration('P1S'); $this->fail("Did not fail with duration missing T delimiter."); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertStringStartsWith('Invalid ISO 8601 duration: ', $e->getMessage()); } } diff --git a/tests/lib/SimpleSAML/Utils/XMLTest.php b/tests/lib/SimpleSAML/Utils/XMLTest.php index 2bafc5627..b0a6e5b41 100644 --- a/tests/lib/SimpleSAML/Utils/XMLTest.php +++ b/tests/lib/SimpleSAML/Utils/XMLTest.php @@ -4,8 +4,15 @@ declare(strict_types=1); namespace SimpleSAML\Test\Utils; +use DOMComment; +use DOMDocument; +use DOMElement; +use DOMException; +use DOMText; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use SimpleSAML\Configuration; +use SimpleSAML\Error; use SimpleSAML\Utils\XML; /** @@ -24,7 +31,7 @@ class XMLTest extends TestCase { $name = 'name'; $namespace_uri = 'ns'; - $element = new \DOMElement($name, 'value', $namespace_uri); + $element = new DOMElement($name, 'value', $namespace_uri); $res = XML::isDOMNodeOfType($element, $name, $namespace_uri); @@ -39,10 +46,10 @@ class XMLTest extends TestCase */ public function testIsDomNodeOfTypeMissingNamespace(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $name = 'name'; $namespace_uri = '@missing'; - $element = new \DOMElement($name, 'value', $namespace_uri); + $element = new DOMElement($name, 'value', $namespace_uri); XML::isDOMNodeOfType($element, $name, $namespace_uri); } @@ -57,7 +64,7 @@ class XMLTest extends TestCase { $name = 'name'; $namespace_uri = ''; - $element = new \DOMElement($name); + $element = new DOMElement($name); $res = XML::isDOMNodeOfType($element, $name, $namespace_uri); @@ -75,7 +82,7 @@ class XMLTest extends TestCase $name = 'name'; $namespace_uri = 'urn:oasis:names:tc:SAML:2.0:metadata'; $short_namespace_uri = '@md'; - $element = new \DOMElement($name, 'value', $namespace_uri); + $element = new DOMElement($name, 'value', $namespace_uri); $res = XML::isDOMNodeOfType($element, $name, $short_namespace_uri); @@ -93,7 +100,7 @@ class XMLTest extends TestCase $name = 'name'; $bad_name = 'bad name'; $namespace_uri = 'ns'; - $element = new \DOMElement($name, 'value', $namespace_uri); + $element = new DOMElement($name, 'value', $namespace_uri); $res = XML::isDOMNodeOfType($element, $bad_name, $namespace_uri); @@ -111,7 +118,7 @@ class XMLTest extends TestCase $name = 'name'; $namespace_uri = 'ns'; $bad_namespace_uri = 'bad name'; - $element = new \DOMElement($name, 'value', $namespace_uri); + $element = new DOMElement($name, 'value', $namespace_uri); $res = XML::isDOMNodeOfType($element, $name, $bad_namespace_uri); @@ -127,9 +134,9 @@ class XMLTest extends TestCase public function testGetDomTextBasic(): void { $data = 'root value'; - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $element = $dom->appendChild(new \DOMElement('root')); - $element->appendChild(new \DOMText($data)); + $element->appendChild(new DOMText($data)); $res = XML::getDOMText($element); $expected = $data; @@ -147,10 +154,10 @@ class XMLTest extends TestCase { $data1 = 'root value 1'; $data2 = 'root value 2'; - $dom = new \DOMDocument(); - $element = $dom->appendChild(new \DOMElement('root')); - $element->appendChild(new \DOMText($data1)); - $element->appendChild(new \DOMText($data2)); + $dom = new DOMDocument(); + $element = $dom->appendChild(new DOMElement('root')); + $element->appendChild(new DOMText($data1)); + $element->appendChild(new DOMText($data2)); $res = XML::getDOMText($element); $expected = $data1 . $data2 . $data1 . $data2; @@ -166,10 +173,10 @@ class XMLTest extends TestCase */ public function testGetDomTextIncorrectType(): void { - $this->expectException(\SimpleSAML\Error\Exception::class); - $dom = new \DOMDocument(); - $element = $dom->appendChild(new \DOMElement('root')); - $element->appendChild(new \DOMComment('')); + $this->expectException(Error\Exception::class); + $dom = new DOMDocument(); + $element = $dom->appendChild(new DOMElement('root')); + $element->appendChild(new DOMComment('')); XML::getDOMText($element); } @@ -184,8 +191,8 @@ class XMLTest extends TestCase { $name = 'name'; $namespace_uri = 'ns'; - $dom = new \DOMDocument(); - $element = new \DOMElement($name, 'value', $namespace_uri); + $dom = new DOMDocument(); + $element = new DOMElement($name, 'value', $namespace_uri); $dom->appendChild($element); $res = XML::getDOMChildren($dom, $name, $namespace_uri); @@ -202,9 +209,9 @@ class XMLTest extends TestCase */ public function testGetDomChildrenIncorrectType(): void { - $dom = new \DOMDocument(); - $text = new \DOMText('text'); - $comment = new \DOMComment('comment'); + $dom = new DOMDocument(); + $text = new DOMText('text'); + $comment = new DOMComment('comment'); $dom->appendChild($text); $dom->appendChild($comment); @@ -224,8 +231,8 @@ class XMLTest extends TestCase $name = 'name'; $bad_name = 'bad name'; $namespace_uri = 'ns'; - $dom = new \DOMDocument(); - $element = new \DOMElement($name, 'value', $namespace_uri); + $dom = new DOMDocument(); + $element = new DOMElement($name, 'value', $namespace_uri); $dom->appendChild($element); $res = XML::getDOMChildren($dom, $bad_name, $namespace_uri); @@ -241,8 +248,8 @@ class XMLTest extends TestCase */ public function testFormatDomElementBasic(): void { - $dom = new \DOMDocument(); - $root = new \DOMElement('root'); + $dom = new DOMDocument(); + $root = new DOMElement('root'); $dom->appendChild($root); $root->appendChild(new \DOMText('text')); @@ -265,12 +272,12 @@ NOWDOC; */ public function testFormatDomElementNested(): void { - $dom = new \DOMDocument(); - $root = new \DOMElement('root'); - $nested = new \DOMElement('nested'); + $dom = new DOMDocument(); + $root = new DOMElement('root'); + $nested = new DOMElement('nested'); $dom->appendChild($root); $root->appendChild($nested); - $nested->appendChild(new \DOMText('text')); + $nested->appendChild(new DOMText('text')); XML::formatDOMElement($root); $res = $dom->saveXML(); @@ -294,12 +301,12 @@ NOWDOC; public function testFormatDomElementIndentBase(): void { $indent_base = 'base'; - $dom = new \DOMDocument(); - $root = new \DOMElement('root'); - $nested = new \DOMElement('nested'); + $dom = new DOMDocument(); + $root = new DOMElement('root'); + $nested = new DOMElement('nested'); $dom->appendChild($root); $root->appendChild($nested); - $nested->appendChild(new \DOMText('text')); + $nested->appendChild(new DOMText('text')); XML::formatDOMElement($root, $indent_base); $res = $dom->saveXML(); @@ -322,11 +329,11 @@ HEREDOC; */ public function testFormatDomElementTextAndChild(): void { - $dom = new \DOMDocument(); - $root = new \DOMElement('root'); + $dom = new DOMDocument(); + $root = new DOMElement('root'); $dom->appendChild($root); - $root->appendChild(new \DOMText('text')); - $root->appendChild(new \DOMElement('child')); + $root->appendChild(new DOMText('text')); + $root->appendChild(new DOMElement('child')); XML::formatDOMElement($root); $res = $dom->saveXML(); @@ -367,7 +374,7 @@ NOWDOC; */ public function testFormatXmlStringMalformedXml(): void { - $this->expectException(\DOMException::class); + $this->expectException(DOMException::class); $xml = '<root><nested>text'; XML::formatXMLString($xml); @@ -400,7 +407,7 @@ NOWDOC; $schema = 'saml-schema-metadata-2.0.xsd'; $xml = file_get_contents(self::FRAMEWORK . '/metadata/xml/valid-metadata-selfsigned.xml'); - $dom = new \DOMDocument('1.0'); + $dom = new DOMDocument('1.0'); $dom->loadXML($xml, LIBXML_NONET); $res = XML::isValid($dom, $schema); @@ -413,7 +420,7 @@ NOWDOC; */ public function testCheckSAMLMessageInvalidType(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); XML::checkSAMLMessage('<test></test>', 'blub'); } } diff --git a/tests/lib/SimpleSAML/XML/ErrorsTest.php b/tests/lib/SimpleSAML/XML/ErrorsTest.php index 6eb306feb..38d49317b 100644 --- a/tests/lib/SimpleSAML/XML/ErrorsTest.php +++ b/tests/lib/SimpleSAML/XML/ErrorsTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\XML; +use LibXMLError; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Errors; @@ -48,7 +49,7 @@ class ErrorsTest extends TestCase */ public function formatErrors(): void { - $error = new \LibXMLError(); + $error = new LibXMLError(); $error->level = 3; $error->code = 76; $error->line = 1; diff --git a/tests/lib/SimpleSAML/XML/ParserTest.php b/tests/lib/SimpleSAML/XML/ParserTest.php index 82ca0c1b6..baac66222 100644 --- a/tests/lib/SimpleSAML/XML/ParserTest.php +++ b/tests/lib/SimpleSAML/XML/ParserTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\XML; +use Exception; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Parser; @@ -77,7 +78,7 @@ XML; */ public function getValueException(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->xml->getValue('/Root/Foo', true); } @@ -152,7 +153,7 @@ XML; */ public function getValueAlternativesException(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->xml->getValueAlternatives( [ '/Root/Foo', diff --git a/tests/lib/SimpleSAML/XML/ValidatorTest.php b/tests/lib/SimpleSAML/XML/ValidatorTest.php index afbcd2276..331b55931 100644 --- a/tests/lib/SimpleSAML/XML/ValidatorTest.php +++ b/tests/lib/SimpleSAML/XML/ValidatorTest.php @@ -6,6 +6,7 @@ namespace SimpleSAML\Test\XML; use DOMDocument; use DOMElement; +use Exception; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use SimpleSAML\Test\SigningTestCase; @@ -22,10 +23,10 @@ class ValidatorTest extends SigningTestCase */ public function testValidatorMissingSignature(): void { - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0"?><node>value</node>'); - $this->expectException(\Exception::class); + $this->expectException(Exception::class); new Validator($doc); } @@ -41,7 +42,7 @@ class ValidatorTest extends SigningTestCase /** @psalm-var DOMElement $node */ $node = $doc->getElementsByTagName('node')->item(0); - $signature_parent = $doc->appendChild(new \DOMElement('signature_parent')); + $signature_parent = $doc->appendChild(new DOMElement('signature_parent')); $signer = new Signer([]); $signer->loadPrivateKey($this->good_private_key_file, null, true); @@ -70,7 +71,7 @@ class ValidatorTest extends SigningTestCase /** @psalm-var DOMElement $node */ $node = $doc->getElementsByTagName('node')->item(0); - $signature_parent = $doc->appendChild(new \DOMElement('signature_parent')); + $signature_parent = $doc->appendChild(new DOMElement('signature_parent')); $signer = new Signer([]); $signer->loadPrivateKey($this->good_private_key_file, null, true); @@ -102,7 +103,7 @@ class ValidatorTest extends SigningTestCase /** @psalm-var DOMElement $node2 */ $node2 = $doc->getElementsByTagName('node2')->item(0); - $signature_parent = $doc->appendChild(new \DOMElement('signature_parent')); + $signature_parent = $doc->appendChild(new DOMElement('signature_parent')); $signer = new Signer([]); $signer->loadPrivateKey($this->good_private_key_file, null, true); diff --git a/tests/modules/core/lib/Auth/Process/AttributeAddTest.php b/tests/modules/core/lib/Auth/Process/AttributeAddTest.php index e285d6a6a..3e40c73e4 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeAddTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeAddTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\AttributeAdd; /** * Test for the core:AttributeAdd filter. @@ -20,7 +22,7 @@ class AttributeAddTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\AttributeAdd($config, null); + $filter = new AttributeAdd($config, null); $filter->process($request); return $request; } @@ -159,7 +161,7 @@ class AttributeAddTest extends TestCase */ public function testWrongFlag(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ '%nonsense', 'test' => ['value2'], @@ -179,7 +181,7 @@ class AttributeAddTest extends TestCase */ public function testWrongAttributeValue(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ '%replace', 'test' => [true], diff --git a/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php b/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php index 2edb6f90d..72de230ca 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\AttributeAlter; /** * Test for the core:AttributeAlter filter. @@ -20,7 +22,7 @@ class AttributeAlterTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\AttributeAlter($config, null); + $filter = new AttributeAlter($config, null); $filter->process($request); return $request; } @@ -236,7 +238,7 @@ class AttributeAlterTest extends TestCase */ public function testWrongConfig(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'subject' => 'eduPersonAffiliation', 'pattern' => '/^emper/', @@ -257,7 +259,7 @@ class AttributeAlterTest extends TestCase */ public function testIncompleteConfig(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'subject' => 'eduPersonAffiliation', ]; @@ -276,7 +278,7 @@ class AttributeAlterTest extends TestCase */ public function testIncompleteConfig2(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', @@ -297,7 +299,7 @@ class AttributeAlterTest extends TestCase */ public function testIncompleteConfig3(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', @@ -320,7 +322,7 @@ class AttributeAlterTest extends TestCase */ public function testIncompleteConfig4(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', @@ -343,7 +345,7 @@ class AttributeAlterTest extends TestCase */ public function testIncompleteConfig5(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', diff --git a/tests/modules/core/lib/Auth/Process/AttributeCopyTest.php b/tests/modules/core/lib/Auth/Process/AttributeCopyTest.php index a8428c4e9..81a2da1c7 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeCopyTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeCopyTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\AttributeCopy; /** * Test for the core:AttributeCopy filter. @@ -20,7 +22,7 @@ class AttributeCopyTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\AttributeCopy($config, null); + $filter = new AttributeCopy($config, null); $filter->process($request); return $request; } @@ -144,7 +146,7 @@ class AttributeCopyTest extends TestCase */ public function testWrongAttributeName(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ ['value2'], ]; @@ -163,7 +165,7 @@ class AttributeCopyTest extends TestCase */ public function testWrongAttributeValue(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'test' => 100, ]; diff --git a/tests/modules/core/lib/Auth/Process/AttributeLimitTest.php b/tests/modules/core/lib/Auth/Process/AttributeLimitTest.php index 7a2155b38..d5453c0d9 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeLimitTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeLimitTest.php @@ -4,7 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Configuration; +use SimpleSAML\Module\core\Auth\Process\AttributeLimit; /** * Test for the core:AttributeLimit filter. @@ -27,7 +30,7 @@ class AttributeLimitTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\AttributeLimit($config, null); + $filter = new AttributeLimit($config, null); $filter->process($request); return $request; } @@ -221,7 +224,7 @@ class AttributeLimitTest extends TestCase */ public function testInvalidConfig(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'invalidArg' => true, ]; @@ -236,7 +239,7 @@ class AttributeLimitTest extends TestCase */ public function testInvalidAttributeName(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ null ]; @@ -375,7 +378,7 @@ class AttributeLimitTest extends TestCase public function testMatchAttributeValuesRegex(): void { // SSP Logger requires a configuration to be set. - \SimpleSAML\Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); $state = self::$request; $state['Attributes']['eduPersonEntitlement'] = [ 'urn:mace:example.terena.org:tcs:personal-user', @@ -476,7 +479,7 @@ class AttributeLimitTest extends TestCase */ public function testMatchAttributeValuesNotArray(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ ]; diff --git a/tests/modules/core/lib/Auth/Process/AttributeMapTest.php b/tests/modules/core/lib/Auth/Process/AttributeMapTest.php index 682de2c6c..f8f453e74 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeMapTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeMapTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\AttributeMap; /** * Test for the core:AttributeMap filter. @@ -20,7 +21,7 @@ class AttributeMapTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\AttributeMap($config, null); + $filter = new AttributeMap($config, null); $filter->process($request); return $request; } diff --git a/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php b/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php index 7842b2e6f..489f2c6b5 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use Exception; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\core\Auth\Process\AttributeValueMap; @@ -200,7 +201,7 @@ class AttributeValueMapTest extends TestCase */ public function testMissingSourceAttribute(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'targetattribute' => 'affiliation', 'values' => [ @@ -227,7 +228,7 @@ class AttributeValueMapTest extends TestCase */ public function testMissingTargetAttribute(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'sourceattribute' => 'memberOf', 'values' => [ diff --git a/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php b/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php index b95978fa6..a17bb90cc 100644 --- a/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php +++ b/tests/modules/core/lib/Auth/Process/CardinalitySingleTest.php @@ -4,12 +4,14 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use PHPUnit\Framework\TestCase; use SimpleSAML\Utils\HttpAdapter; +use SimpleSAML\Module\core\Auth\Process\CardinalitySingle; /** * Test for the core:CardinalitySingle filter. */ -class CardinalitySingleTest extends \PHPUnit\Framework\TestCase +class CardinalitySingleTest extends TestCase { /** @var \SimpleSAML\Utils\HttpAdapter|\PHPUnit\Framework\MockObject\MockObject */ private $http; @@ -30,7 +32,7 @@ class CardinalitySingleTest extends \PHPUnit\Framework\TestCase /** @var \SimpleSAML\Utils\HttpAdapter $http */ $http = $this->http; - $filter = new \SimpleSAML\Module\core\Auth\Process\CardinalitySingle($config, null, $http); + $filter = new CardinalitySingle($config, null, $http); $filter->process($request); return $request; } diff --git a/tests/modules/core/lib/Auth/Process/CardinalityTest.php b/tests/modules/core/lib/Auth/Process/CardinalityTest.php index ebeb8ed1a..af0262a09 100644 --- a/tests/modules/core/lib/Auth/Process/CardinalityTest.php +++ b/tests/modules/core/lib/Auth/Process/CardinalityTest.php @@ -4,13 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use PHPUnit\Framework\TestCase; +use SimpleSAML\Configuration; use SimpleSAML\Error\Exception as SspException; +use SimpleSAML\Module\core\Auth\Process\Cardinality; use SimpleSAML\Utils\HttpAdapter; /** * Test for the core:Cardinality filter. */ -class CardinalityTest extends \PHPUnit\Framework\TestCase +class CardinalityTest extends TestCase { /** @var \SimpleSAML\Utils\HttpAdapter|\PHPUnit\Framework\MockObject\MockObject */ private $http; @@ -31,7 +34,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase /** @var \SimpleSAML\Utils\HttpAdapter $http */ $http = $this->http; - $filter = new \SimpleSAML\Module\core\Auth\Process\Cardinality($config, null, $http); + $filter = new Cardinality($config, null, $http); $filter->process($request); return $request; } @@ -42,7 +45,7 @@ class CardinalityTest extends \PHPUnit\Framework\TestCase */ protected function setUp(): void { - \SimpleSAML\Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); $this->http = $this->getMockBuilder(HttpAdapter::class) ->setMethods(['redirectTrustedURL']) ->getMock(); diff --git a/tests/modules/core/lib/Auth/Process/PHPTest.php b/tests/modules/core/lib/Auth/Process/PHPTest.php index 0377dfafb..4be06b9f5 100644 --- a/tests/modules/core/lib/Auth/Process/PHPTest.php +++ b/tests/modules/core/lib/Auth/Process/PHPTest.php @@ -6,6 +6,8 @@ namespace SimpleSAML\Test\Module\core\Auth\Process; use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Error; +use SimpleSAML\Module\core\Auth\Process\PHP; /** * Test for the core:PHP filter. @@ -22,7 +24,7 @@ class PHPTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\PHP($config, null); + $filter = new PHP($config, null); @$filter->process($request); return $request; } @@ -35,11 +37,11 @@ class PHPTest extends TestCase public function testInvalidConfiguration(): void { $config = []; - $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectException(Error\Exception::class); $this->expectExceptionMessage( "core:PHP: missing mandatory configuration option 'code'." ); - new \SimpleSAML\Module\core\Auth\Process\PHP($config, null); + new PHP($config, null); } diff --git a/tests/modules/core/lib/Auth/Process/ScopeAttributeTest.php b/tests/modules/core/lib/Auth/Process/ScopeAttributeTest.php index 72fe7c3d9..a957ddbac 100644 --- a/tests/modules/core/lib/Auth/Process/ScopeAttributeTest.php +++ b/tests/modules/core/lib/Auth/Process/ScopeAttributeTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\ScopeAttribute; /** * Test for the core:ScopeAttribute filter. @@ -20,7 +21,7 @@ class ScopeAttributeTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\ScopeAttribute($config, null); + $filter = new ScopeAttribute($config, null); $filter->process($request); return $request; } diff --git a/tests/modules/core/lib/Auth/Process/ScopeFromAttributeTest.php b/tests/modules/core/lib/Auth/Process/ScopeFromAttributeTest.php index 8aa26159a..5c5e2203d 100644 --- a/tests/modules/core/lib/Auth/Process/ScopeFromAttributeTest.php +++ b/tests/modules/core/lib/Auth/Process/ScopeFromAttributeTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\ScopeFromAttribute; /** * Test for the core:ScopeFromAttribute filter. @@ -20,7 +21,7 @@ class ScopeFromAttributeTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\ScopeFromAttribute($config, null); + $filter = new ScopeFromAttribute($config, null); $filter->process($request); return $request; } diff --git a/tests/modules/core/lib/Auth/Process/TargetedIDTest.php b/tests/modules/core/lib/Auth/Process/TargetedIDTest.php index 59357bc29..ff79c21b4 100644 --- a/tests/modules/core/lib/Auth/Process/TargetedIDTest.php +++ b/tests/modules/core/lib/Auth/Process/TargetedIDTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth\Process; +use Exception; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\core\Auth\Process\TargetedID; /** * Test for the core:TargetedID filter. @@ -20,7 +22,7 @@ class TargetedIDTest extends TestCase */ private static function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\core\Auth\Process\TargetedID($config, null); + $filter = new TargetedID($config, null); $filter->process($request); return $request; } @@ -181,7 +183,7 @@ class TargetedIDTest extends TestCase */ public function testNoUserID(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = []; $request = [ 'Attributes' => [], @@ -196,7 +198,7 @@ class TargetedIDTest extends TestCase */ public function testAttributeNotExists(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'attributename' => 'uid', ]; @@ -215,7 +217,7 @@ class TargetedIDTest extends TestCase */ public function testConfigInvalidAttributeName(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'attributename' => 5, ]; @@ -234,7 +236,7 @@ class TargetedIDTest extends TestCase */ public function testConfigInvalidNameId(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $config = [ 'nameId' => 'persistent', ]; diff --git a/tests/modules/core/lib/Auth/UserPassBaseTest.php b/tests/modules/core/lib/Auth/UserPassBaseTest.php index e3af95c1b..b8b9e2743 100644 --- a/tests/modules/core/lib/Auth/UserPassBaseTest.php +++ b/tests/modules/core/lib/Auth/UserPassBaseTest.php @@ -4,11 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth; +use PHPUnit\Framework\TestCase; use SAML2\Constants; use SimpleSAML\Error\Error as SspError; use SimpleSAML\Module\core\Auth\UserPassBase; -class UserPassBaseTest extends \PHPUnit\Framework\TestCase +class UserPassBaseTest extends TestCase { /** * @return void diff --git a/tests/modules/core/lib/Auth/UserPassOrgBaseTest.php b/tests/modules/core/lib/Auth/UserPassOrgBaseTest.php index fe6e8d657..ebc5f3c66 100644 --- a/tests/modules/core/lib/Auth/UserPassOrgBaseTest.php +++ b/tests/modules/core/lib/Auth/UserPassOrgBaseTest.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Auth; +use PHPUnit\Framework\TestCase; use SimpleSAML\Module\core\Auth\UserPassOrgBase; -class UserPassOrgBaseTest extends \PHPUnit\Framework\TestCase +class UserPassOrgBaseTest extends TestCase { /** * @return void diff --git a/tests/modules/core/lib/Controller/LoginTest.php b/tests/modules/core/lib/Controller/LoginTest.php index d25d85d2f..ba7a0b1ee 100644 --- a/tests/modules/core/lib/Controller/LoginTest.php +++ b/tests/modules/core/lib/Controller/LoginTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Controller; +use ReflectionClass; use SimpleSAML\Auth\Simple; use SimpleSAML\Auth\AuthenticationFactory; use SimpleSAML\Configuration; @@ -158,7 +159,7 @@ class LoginTest extends ClearStateTestCase $session = Session::getSessionFromRequest(); $session->setConfiguration($this->config); - $class = new \ReflectionClass($session); + $class = new ReflectionClass($session); $authData = $class->getProperty('authData'); $authData->setAccessible(true); @@ -238,7 +239,7 @@ class LoginTest extends ClearStateTestCase $asConfig = Configuration::loadFromArray($this->authSources); Configuration::setPreLoadedConfig($asConfig, 'authsources.php'); $session = Session::getSessionFromRequest(); - $class = new \ReflectionClass($session); + $class = new ReflectionClass($session); $authData = $class->getProperty('authData'); $authData->setAccessible(true); $authData->setValue($session, [ diff --git a/tests/modules/core/lib/Storage/SQLPermanentStorageTest.php b/tests/modules/core/lib/Storage/SQLPermanentStorageTest.php index 493ce0a34..ea6441bf4 100644 --- a/tests/modules/core/lib/Storage/SQLPermanentStorageTest.php +++ b/tests/modules/core/lib/Storage/SQLPermanentStorageTest.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\core\Storage; use PHPUnit\Framework\TestCase; +use SimpleSAML\Configuration; +use SimpleSAML\Module\core\Storage\SQLPermanentStorage; /** * Test for the SQLPermanentStorage class. @@ -21,10 +23,10 @@ class SQLPermanentStorageTest extends TestCase public static function setUpBeforeClass(): void { // Create instance - $config = \SimpleSAML\Configuration::loadFromArray([ + $config = Configuration::loadFromArray([ 'datadir' => sys_get_temp_dir(), ]); - self::$sql = new \SimpleSAML\Module\core\Storage\SQLPermanentStorage('test', $config); + self::$sql = new SQLPermanentStorage('test', $config); } diff --git a/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php b/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php index 494fc40bc..879a6b4da 100644 --- a/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php +++ b/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php @@ -4,11 +4,13 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\multiauth\Auth\Source; -use PHPUnit\Framework\TestCase; +use Error; +use Exception; +use SimpleSAML\Test\Utils\ClearStateTestCase; use SimpleSAML\Configuration; use SimpleSAML\Module\multiauth\Auth\Source\MultiAuth; -class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase +class MultiAuthTest extends ClearStateTestCase { /** @var Configuration */ private $config; @@ -74,7 +76,7 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testSourcesMustBePresent(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('The required "sources" config option was not found'); $sourceConfig = Configuration::loadFromArray(array( 'example-multi' => array( @@ -93,7 +95,7 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase */ public function testPreselectMustBeValid(): void { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('The optional "preselect" config option must be present in "sources"'); $sourceConfig = Configuration::loadFromArray(array( 'example-multi' => array( @@ -185,8 +187,8 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase try { $source->authenticate($state); - } catch (\Error $e) { - } catch (\Exception $e) { + } catch (Error $e) { + } catch (Exception $e) { } $this->assertArrayNotHasKey('multiauth:preselect', $state); @@ -204,7 +206,7 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase try { $source->authenticate($state); - } catch (\Exception $e) { + } catch (Exception $e) { } $this->assertArrayHasKey('multiauth:preselect', $state); @@ -223,7 +225,7 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase try { $source->authenticate($state); - } catch (\Exception $e) { + } catch (Exception $e) { } $this->assertArrayHasKey('multiauth:preselect', $state); diff --git a/tests/modules/saml/lib/Auth/Process/FilterScopesTest.php b/tests/modules/saml/lib/Auth/Process/FilterScopesTest.php index 1c5c30bde..764d3caa7 100644 --- a/tests/modules/saml/lib/Auth/Process/FilterScopesTest.php +++ b/tests/modules/saml/lib/Auth/Process/FilterScopesTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\saml\Auth\Process; use PHPUnit\Framework\TestCase; +use SimpleSAML\Module\saml\Auth\Process\FilterScopes; /** * Test for the saml:FilterScopes filter. @@ -23,7 +24,7 @@ class FilterScopesTest extends TestCase */ private function processFilter(array $config, array $request): array { - $filter = new \SimpleSAML\Module\saml\Auth\Process\FilterScopes($config, null); + $filter = new FilterScopes($config, null); $filter->process($request); return $request; } diff --git a/tests/modules/saml/lib/Auth/Source/Auth_Source_SP_Test.php b/tests/modules/saml/lib/Auth/Source/Auth_Source_SP_Test.php index 023a1be0c..5baa54d1f 100644 --- a/tests/modules/saml/lib/Auth/Source/Auth_Source_SP_Test.php +++ b/tests/modules/saml/lib/Auth/Source/Auth_Source_SP_Test.php @@ -7,6 +7,8 @@ namespace SimpleSAML\Test\Module\saml\Auth\Source; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use SAML2\AuthnRequest; +use SAML2\Constants; +use SAML2\Utils; use SimpleSAML\Configuration; use SimpleSAML\Module\saml\Error\NoAvailableIDP; use SimpleSAML\Module\saml\Error\NoSupportedIDP; @@ -129,13 +131,13 @@ class SPTest extends ClearStateTestCase $xml = $ar->toSignedXML(); /** @var \DOMAttr[] $q */ - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/@Destination'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/@Destination'); $this->assertEquals( $this->idpConfigArray['SingleSignOnService'][0]['Location'], $q[0]->value ); - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/saml:Issuer'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/saml:Issuer'); $this->assertEquals( 'http://localhost/simplesaml/module.php/saml/sp/metadata.php/default-sp', $q[0]->textContent @@ -151,7 +153,7 @@ class SPTest extends ClearStateTestCase public function testNameID(): void { $state = [ - 'saml:NameID' => ['Value' => 'user@example.org', 'Format' => \SAML2\Constants::NAMEID_UNSPECIFIED] + 'saml:NameID' => ['Value' => 'user@example.org', 'Format' => Constants::NAMEID_UNSPECIFIED] ]; $ar = $this->createAuthnRequest($state); @@ -164,13 +166,13 @@ class SPTest extends ClearStateTestCase $xml = $ar->toSignedXML(); /** @var \DOMAttr[] $q */ - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/saml:Subject/saml:NameID/@Format'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/saml:Subject/saml:NameID/@Format'); $this->assertEquals( $state['saml:NameID']['Format'], $q[0]->value ); - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/saml:Subject/saml:NameID'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/saml:Subject/saml:NameID'); $this->assertEquals( $state['saml:NameID']['Value'], $q[0]->textContent @@ -200,7 +202,7 @@ class SPTest extends ClearStateTestCase $xml = $ar->toSignedXML(); - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/samlp:RequestedAuthnContext/saml:AuthnContextClassRef'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/samlp:RequestedAuthnContext/saml:AuthnContextClassRef'); $this->assertEquals( $state['saml:AuthnContextClassRef'], $q[0]->textContent @@ -230,7 +232,7 @@ class SPTest extends ClearStateTestCase $xml = $ar->toSignedXML(); /** @var \DOMAttr[] $q */ - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/@ForceAuthn'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/@ForceAuthn'); $this->assertEquals( $state['ForceAuthn'] ? 'true' : 'false', $q[0]->value @@ -317,7 +319,7 @@ class SPTest extends ClearStateTestCase $xml = $ar->toSignedXML(); /** @var \DOMAttr[] $q */ - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/@Destination'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/@Destination'); $this->assertEquals( 'https://saml.idp/sso/', $q[0]->value @@ -357,7 +359,7 @@ class SPTest extends ClearStateTestCase $xml = $ar->toSignedXML(); /** @var \DOMAttr[] $q */ - $q = \SAML2\Utils::xpQuery($xml, '/samlp:AuthnRequest/@Destination'); + $q = Utils::xpQuery($xml, '/samlp:AuthnRequest/@Destination'); $this->assertEquals( 'https://saml.idp/sso/', $q[0]->value diff --git a/tests/modules/saml/lib/IdP/SQLNameIDTest.php b/tests/modules/saml/lib/IdP/SQLNameIDTest.php index aa6513e1e..e9b546a3a 100644 --- a/tests/modules/saml/lib/IdP/SQLNameIDTest.php +++ b/tests/modules/saml/lib/IdP/SQLNameIDTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\saml\IdP; use PHPUnit\Framework\TestCase; +use ReflectionClass; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Module\saml\IdP\SQLNameID; @@ -106,7 +107,7 @@ class SQLNameIDTest extends TestCase */ protected function clearInstance($service, string $className): void { - $reflectedClass = new \ReflectionClass($className); + $reflectedClass = new ReflectionClass($className); $reflectedInstance = $reflectedClass->getProperty('instance'); $reflectedInstance->setAccessible(true); $reflectedInstance->setValue($service, null); diff --git a/tests/routers/configLoader.php b/tests/routers/configLoader.php index b148e80ba..f239c902b 100644 --- a/tests/routers/configLoader.php +++ b/tests/routers/configLoader.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use SimpleSAML\Configuration; + /* * This "router" (a script that's executed for every request received by PHP's built-in web server) will look * for a file in the system's temporary directory, with the PID of the current process as its name, and the @@ -31,11 +33,11 @@ declare(strict_types=1); include_once(sys_get_temp_dir() . '/' . getmypid() . '.lock'); // load SimpleSAMLphp's autoloader -require_once(dirname(__FILE__) . '/../../vendor/autoload.php'); +require_once(dirname(dirname(dirname(__FILE__))) . '/vendor/autoload.php'); // initialize configuration if (isset($config)) { - \SimpleSAML\Configuration::loadFromArray($config, '[ARRAY]', 'simplesaml'); + Configuration::loadFromArray($config, '[ARRAY]', 'simplesaml'); } // let the script proceed -- GitLab