diff --git a/TESTING.md b/TESTING.md index c38db47e8f070fb652931a0599c3cfaf8d520d39..302fb309a30fb4b27d4cad87c37b6793f95b805f 100644 --- a/TESTING.md +++ b/TESTING.md @@ -40,15 +40,14 @@ throws an exception in a specific situation: ```php /** * Test SimpleSAML\Utils\HTTP::addURLParameters(). - * - * @expectedException \InvalidArgumentException */ public function testAddURLParametersInvalidParameters() { + $this->expectException(ExpectedException::class); ``` -Refer to [the `phpunit 4.8` documentation](https://phpunit.de/manual/4.8/en/installation.html) -for more information on how to write tests. We currently use the `phpunit 4.8` -since it is the last version to support php 5.3. +Refer to [the `phpunit 5.7` documentation](https://phpunit.de/manual/5.7/en/installation.html) +for more information on how to write tests. We currently use the `phpunit 5.7` +since it is the last version to support php 5.6. Once you have implemented your tests, you can run them locally. First, make sure the `config` directory is **not** in the root of your @@ -59,7 +58,7 @@ you have `phpunit` installed and run: phpunit -c ./phpunit.xml ``` -If your default version of `phpunit` is more recent than 4.8, you can run +If your default version of `phpunit` is more recent than 5.7, you can run the old version installed by composer ```sh diff --git a/tests/lib/SimpleSAML/ConfigurationTest.php b/tests/lib/SimpleSAML/ConfigurationTest.php index 18a21fe057e6c0101034122a8238d74e8fbbe0ea..6b5d507bf36f8f96374a1e239a97297da818e972 100644 --- a/tests/lib/SimpleSAML/ConfigurationTest.php +++ b/tests/lib/SimpleSAML/ConfigurationTest.php @@ -2,7 +2,8 @@ namespace SimpleSAML\Test; -use \SimpleSAML\Configuration; +use SimpleSAML\Configuration; +use SimpleSAML\Error\CriticalConfigurationError; /** * Tests for \SimpleSAML\Configuration @@ -20,10 +21,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test that the default instance fails to load even if we previously loaded another instance. - * @expectedException \SimpleSAML\Error\CriticalConfigurationError */ public function testLoadDefaultInstance() { + $this->expectException(CriticalConfigurationError::class); Configuration::loadFromArray(['key' => 'value'], '', 'dummy'); Configuration::getInstance(); } @@ -70,10 +71,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getValue(), REQUIRED_OPTION flag. - * @expectedException Exception */ public function testGetValueRequired() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([]); $c->getValue('missing', Configuration::REQUIRED_OPTION); } @@ -239,20 +240,20 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getBoolean() missing option - * @expectedException Exception */ public function testGetBooleanMissing() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([]); $c->getBoolean('missing_opt'); } /** * Test \SimpleSAML\Configuration::getBoolean() wrong option - * @expectedException Exception */ public function testGetBooleanWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'wrong' => 'true', ]); @@ -273,20 +274,20 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getString() missing option - * @expectedException Exception */ public function testGetStringMissing() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([]); $c->getString('missing_opt'); } /** * Test \SimpleSAML\Configuration::getString() wrong option - * @expectedException Exception */ public function testGetStringWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'wrong' => false, ]); @@ -307,20 +308,20 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getInteger() missing option - * @expectedException Exception */ public function testGetIntegerMissing() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([]); $c->getInteger('missing_opt'); } /** * Test \SimpleSAML\Configuration::getInteger() wrong option - * @expectedException Exception */ public function testGetIntegerWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'wrong' => '42', ]); @@ -341,10 +342,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getIntegerRange() below limit - * @expectedException Exception */ public function testGetIntegerRangeBelow() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'int_opt' => 9, ]); @@ -353,10 +354,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getIntegerRange() above limit - * @expectedException Exception */ public function testGetIntegerRangeAbove() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'int_opt' => 101, ]); @@ -377,10 +378,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getValueValidate() wrong option - * @expectedException Exception */ public function testGetValueValidateWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'd', ]); @@ -401,10 +402,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getArray() wrong option - * @expectedException Exception */ public function testGetArrayWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'not_an_array', ]); @@ -444,10 +445,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getArrayizeString() option * with an array that contains something that isn't a string. - * @expectedException Exception */ public function testGetArrayizeStringWrongValue() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => ['a', 'b', 42], ]); @@ -470,10 +471,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getConfigItem() wrong option - * @expectedException Exception */ public function testGetConfigItemWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'not_an_array', ]); @@ -503,10 +504,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getConfigList() wrong option - * @expectedException Exception */ public function testGetConfigListWrong() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => 'not_an_array', ]); @@ -516,10 +517,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getConfigList() with an array of wrong options. - * @expectedException Exception */ public function testGetConfigListWrongArrayValues() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opts' => [ 'a', @@ -895,10 +896,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getLocalizedString() not array nor simple string - * @expectedException Exception */ public function testGetLocalizedStringNotArray() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => 42, ]); @@ -907,10 +908,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getLocalizedString() not string key - * @expectedException Exception */ public function testGetLocalizedStringNotStringKey() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => [42 => 'text'], ]); @@ -919,10 +920,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getLocalizedString() not string value - * @expectedException Exception */ public function testGetLocalizedStringNotStringValue() { + $this->expectException(\Exception::class); $c = Configuration::loadFromArray([ 'opt' => ['en' => 42], ]); @@ -931,10 +932,10 @@ class ConfigurationTest extends \SimpleSAML\Test\Utils\ClearStateTestCase /** * Test \SimpleSAML\Configuration::getConfig() nonexistent file - * @expectedException Exception */ public function testGetConfigNonexistentFile() { + $this->expectException(\Exception::class); Configuration::getConfig('nonexistent-nopreload.php'); } diff --git a/tests/lib/SimpleSAML/DatabaseTest.php b/tests/lib/SimpleSAML/DatabaseTest.php index f48246fd2b7503135e4f378cff0ac68ed0d7b2aa..14b002e644de00274d58f036f31066ad77c26d47 100644 --- a/tests/lib/SimpleSAML/DatabaseTest.php +++ b/tests/lib/SimpleSAML/DatabaseTest.php @@ -79,11 +79,11 @@ class DatabaseTest extends TestCase * @covers SimpleSAML\Database::generateInstanceId * @covers SimpleSAML\Database::__construct * @covers SimpleSAML\Database::connect - * @expectedException Exception * @test */ public function connectionFailure() { + $this->expectException(\Exception::class); $config = [ 'database.dsn' => 'mysql:host=localhost;dbname=saml', 'database.username' => 'notauser', @@ -263,11 +263,11 @@ class DatabaseTest extends TestCase /** * @covers SimpleSAML\Database::read * @covers SimpleSAML\Database::query - * @expectedException Exception * @test */ public function readFailure() { + $this->expectException(\Exception::class); $table = $this->db->applyPrefix("sspdbt"); $this->assertEquals($this->config->getString('database.prefix')."sspdbt", $table); @@ -278,11 +278,11 @@ class DatabaseTest extends TestCase /** * @covers SimpleSAML\Database::write * @covers SimpleSAML\Database::exec - * @expectedException Exception * @test */ public function noSuchTable() { + $this->expectException(\Exception::class); $this->db->write("DROP TABLE phpunit_nonexistent", false); } diff --git a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php index 591fd7fbffe57a9b44cbb087d9b60495862ca92f..6134676c08fb081e86f439bf427407bd47b7f36d 100644 --- a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php +++ b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php @@ -10,19 +10,19 @@ class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase { /** * Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig XML bad source - * @expectedException \Exception */ public function testBadXMLSource() { + $this->expectException(\Exception::class); \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type"=>"xml", "foo"=>"baa"]); } /** * Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig invalid static XML source - * @expectedException Exception */ public function testInvalidStaticXMLSource() { + $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> diff --git a/tests/lib/SimpleSAML/ModuleTest.php b/tests/lib/SimpleSAML/ModuleTest.php index a0c72b5f58d7ee4ab7a744b4dd6f58dab16e5a11..228ab0aed6b029041b0dc91b4c3cab9b07c5c8bd 100644 --- a/tests/lib/SimpleSAML/ModuleTest.php +++ b/tests/lib/SimpleSAML/ModuleTest.php @@ -65,11 +65,10 @@ class ModuleTest extends TestCase * Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if we are not asking * for a class inside a module (that is, there is no colon separating the name of the module and the name of the * class). - * - * @expectedException \Exception */ public function testResolveClassNoModule() { + $this->expectException(\Exception::class); Module::resolveClass('nomodule', ''); } @@ -77,11 +76,10 @@ class ModuleTest extends TestCase /** * Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if the class we are * asking for cannot be found. - * - * @expectedException \Exception */ public function testResolveClassNotFound() { + $this->expectException(\Exception::class); Module::resolveClass('core:Missing', ''); } @@ -89,11 +87,10 @@ class ModuleTest extends TestCase /** * Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if the class we are * asking for can be resolved, but does not extend a given class. - * - * @expectedException \Exception */ public function testResolveClassNotSubclass() { + $this->expectException(\Exception::class); Module::resolveClass('core:PHP', 'Auth_Process', '\Exception'); } diff --git a/tests/lib/SimpleSAML/StoreTest.php b/tests/lib/SimpleSAML/StoreTest.php index ebaa1c5fb09b7d23e52ffdec3bc47746ae5e76e5..4c54e574f43c1b0b0b05f0bb17f89ab1990c0046 100644 --- a/tests/lib/SimpleSAML/StoreTest.php +++ b/tests/lib/SimpleSAML/StoreTest.php @@ -3,8 +3,10 @@ namespace SimpleSAML\Test; use PHPUnit\Framework\TestCase; -use \SimpleSAML\Configuration; -use \SimpleSAML\Store; + +use SimpleSAML\Configuration; +use SimpleSAML\Error\CriticalConfigurationError; +use SimpleSAML\Store; /** * Tests for the Store abstract class. @@ -101,11 +103,11 @@ class StoreTest extends TestCase /** * @covers \SimpleSAML\Store::getInstance - * @expectedException \SimpleSAML\Error\CriticalConfigurationError * @test */ public function notFoundStoreException() { + $this->expectException(CriticalConfigurationError::class); Configuration::loadFromArray([ 'store.type' => '\Test\SimpleSAML\Store\Dummy', 'store.sql.dsn' => 'sqlite::memory:', diff --git a/tests/lib/SimpleSAML/Utils/AttributesTest.php b/tests/lib/SimpleSAML/Utils/AttributesTest.php index 42685215a8a07d09ff5eec620d26929379ee21d5..fd66017a9b14ab80b8a67a277b0ebd61c9e56a57 100644 --- a/tests/lib/SimpleSAML/Utils/AttributesTest.php +++ b/tests/lib/SimpleSAML/Utils/AttributesTest.php @@ -12,7 +12,6 @@ use SimpleSAML\Utils\Attributes; */ class AttributesTest extends TestCase { - /** * Test the getExpectedAttribute() method with invalid attributes array. */ @@ -21,8 +20,8 @@ class AttributesTest extends TestCase // check with empty array as input $attributes = 'string'; $expected = 'string'; - $this->setExpectedException( - 'InvalidArgumentException', + $this->expectException( + \InvalidArgumentException::class, 'The attributes array is not an array, it is: '.print_r($attributes, true).'.' ); Attributes::getExpectedAttribute($attributes, $expected); @@ -37,8 +36,8 @@ class AttributesTest extends TestCase // check with invalid attribute name $attributes = []; $expected = false; - $this->setExpectedException( - 'InvalidArgumentException', + $this->expectException( + \InvalidArgumentException::class, 'The expected attribute is not a string, it is: '.print_r($expected, true).'.' ); Attributes::getExpectedAttribute($attributes, $expected); @@ -55,8 +54,8 @@ class AttributesTest extends TestCase 'attribute' => 'value', ]; $expected = 'attribute'; - $this->setExpectedException( - 'InvalidArgumentException', + $this->expectException( + \InvalidArgumentException::class, 'The attributes array is not normalized, values should be arrays.' ); Attributes::getExpectedAttribute($attributes, $expected); @@ -73,8 +72,8 @@ class AttributesTest extends TestCase 'attribute' => ['value'], ]; $expected = 'missing'; - $this->setExpectedException( - '\SimpleSAML\Error\Exception', + $this->expectException( + \SimpleSAML\Error\Exception::class, "No such attribute '".$expected."' found." ); Attributes::getExpectedAttribute($attributes, $expected); @@ -91,8 +90,8 @@ class AttributesTest extends TestCase 'attribute' => [], ]; $expected = 'attribute'; - $this->setExpectedException( - '\SimpleSAML\Error\Exception', + $this->expectException( + \SimpleSAML\Error\Exception::class, "Empty attribute '".$expected."'.'" ); Attributes::getExpectedAttribute($attributes, $expected); @@ -112,8 +111,8 @@ class AttributesTest extends TestCase ], ]; $expected = 'attribute'; - $this->setExpectedException( - '\SimpleSAML\Error\Exception', + $this->expectException( + \SimpleSAML\Error\Exception::class, 'More than one value found for the attribute, multiple values not allowed.' ); Attributes::getExpectedAttribute($attributes, $expected); @@ -145,31 +144,28 @@ class AttributesTest extends TestCase /** * Test the normalizeAttributesArray() function with input not being an array - * - * @expectedException \InvalidArgumentException */ public function testNormalizeAttributesArrayBadInput() { + $this->expectException(\InvalidArgumentException::class); Attributes::normalizeAttributesArray('string'); } /** * Test the normalizeAttributesArray() function with an array with non-string attribute names. - * - * @expectedException \InvalidArgumentException */ public function testNormalizeAttributesArrayBadKeys() { + $this->expectException(\InvalidArgumentException::class); Attributes::normalizeAttributesArray(['attr1' => 'value1', 1 => 'value2']); } /** * Test the normalizeAttributesArray() function with an array with non-string attribute values. - * - * @expectedException \InvalidArgumentException */ public function testNormalizeAttributesArrayBadValues() { + $this->expectException(\InvalidArgumentException::class); Attributes::normalizeAttributesArray(['attr1' => 'value1', 'attr2' => 0]); } diff --git a/tests/lib/SimpleSAML/Utils/ConfigTest.php b/tests/lib/SimpleSAML/Utils/ConfigTest.php index 6077a6301c45627eb860ac672343b29217ad21f0..10a3d4e6020f2af6068e479677a917b0bf148ad6 100644 --- a/tests/lib/SimpleSAML/Utils/ConfigTest.php +++ b/tests/lib/SimpleSAML/Utils/ConfigTest.php @@ -68,8 +68,8 @@ class ConfigTest extends TestCase $invalidDir = __DIR__.'/e9826ad19cbc4f5bf20c0913ffcd2ce6'; putenv('SIMPLESAMLPHP_CONFIG_DIR='.$invalidDir); - $this->setExpectedException( - 'InvalidArgumentException', + $this->expectException( + \InvalidArgumentException::class, 'Config directory specified by environment variable SIMPLESAMLPHP_CONFIG_DIR is not a directory. '. 'Given: "'.$invalidDir.'"' ); diff --git a/tests/lib/SimpleSAML/Utils/CryptoTest.php b/tests/lib/SimpleSAML/Utils/CryptoTest.php index 044fb054a460e7c3d941c9f8ec696c51bac97df9..ed4d2b47015c0ee4cc49862b08676d53013d83eb 100644 --- a/tests/lib/SimpleSAML/Utils/CryptoTest.php +++ b/tests/lib/SimpleSAML/Utils/CryptoTest.php @@ -32,12 +32,11 @@ class CryptoTest extends TestCase /** * Test invalid input provided to the aesDecrypt() method. * - * @expectedException \InvalidArgumentException - * * @covers \SimpleSAML\Utils\Crypto::aesDecrypt */ public function testAesDecryptBadInput() { + $this->expectException(\InvalidArgumentException::class); $m = new \ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesDecrypt'); $m->setAccessible(true); @@ -48,12 +47,11 @@ class CryptoTest extends TestCase /** * Test invalid input provided to the aesEncrypt() method. * - * @expectedException \InvalidArgumentException - * * @covers \SimpleSAML\Utils\Crypto::aesEncrypt */ public function testAesEncryptBadInput() { + $this->expectException(\InvalidArgumentException::class); $m = new \ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesEncrypt'); $m->setAccessible(true); @@ -70,7 +68,7 @@ class CryptoTest extends TestCase public function testAesDecrypt() { if (!extension_loaded('openssl')) { - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException(\SimpleSAML\Error\Exception::class); } $secret = 'SUPER_SECRET_SALT'; @@ -92,7 +90,7 @@ class CryptoTest extends TestCase public function testAesEncrypt() { if (!extension_loaded('openssl')) { - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException(\SimpleSAML\Error\Exception::class); } $secret = 'SUPER_SECRET_SALT'; @@ -198,13 +196,13 @@ PHP; } /** - * @expectedException \SimpleSAML\Error\Exception * @deprecated To be removed for 2.0 * * @covers \SimpleSAML\Utils\Crypto::pwHash */ public function testBadHashAlgorithm() { + $this->expectException(\SimpleSAML\Error\Exception::class); $pw = "password"; $algorithm = "wtf"; @@ -271,13 +269,13 @@ PHP; } /** - * @expectedException \SimpleSAML\Error\Exception * @deprecated To be removed for 2.0 * * @covers \SimpleSAML\Utils\Crypto::pwValid */ public function testBadHashAlgorithmValid() { + $this->expectException(\SimpleSAML\Error\Exception::class); $algorithm = "wtf"; $hash = "{".$algorithm."}B64STRING"; @@ -305,12 +303,11 @@ PHP; } /** - * @expectedException \SimpleSAML\Error\Exception - * * @covers \SimpleSAML\Utils\Crypto::loadPrivateKey */ public function testLoadPrivateKeyRequiredMetadataMissing() { + $this->expectException(\SimpleSAML\Error\Exception::class); $config = new Configuration([], 'test'); $required = true; @@ -331,12 +328,11 @@ PHP; } /** - * @expectedException \SimpleSAML\Error\Exception - * * @covers \SimpleSAML\Utils\Crypto::loadPrivateKey */ public function testLoadPrivateKeyMissingFile() { + $this->expectException(\SimpleSAML\Error\Exception::class); $config = new Configuration(['privatekey' => 'nonexistant'], 'test'); Crypto::loadPrivateKey($config, false, '', true); @@ -412,12 +408,11 @@ PHP; } /** - * @expectedException \SimpleSAML\Error\Exception - * * @covers \SimpleSAML\Utils\Crypto::loadPublicKey */ public function testLoadPublicKeyRequiredMetadataMissing() { + $this->expectException(\SimpleSAML\Error\Exception::class); $config = new Configuration([], 'test'); $required = true; diff --git a/tests/lib/SimpleSAML/Utils/EMailTestCase.php b/tests/lib/SimpleSAML/Utils/EMailTestCase.php index 0117d2e1ab26d3629869860c0a5248da40e091f9..971d6a2788a6255d15fb8c691e0dc621090bf99a 100644 --- a/tests/lib/SimpleSAML/Utils/EMailTestCase.php +++ b/tests/lib/SimpleSAML/Utils/EMailTestCase.php @@ -25,28 +25,28 @@ class EMailTestCase extends ClearStateTestCase /** * Test that an exception is thrown if using default configuration, * and no custom from address is specified. - * @expectedException Exception */ public function testMailFromDefaultConfigurationException() { + $this->expectException(\Exception::class); new EMail('test', null, 'phpunit@simplesamlphp.org'); } /** * Test that an exception is thrown if using an invalid "From"-address - * @expectedException Exception */ public function testInvalidFromAddressException() { + $this->expectException(\Exception::class); new EMail('test', "phpunit@simplesamlphp.org\nLorem Ipsum", 'phpunit@simplesamlphp.org'); } /** * Test that an exception is thrown if using an invalid "To"-address - * @expectedException Exception */ public function testInvalidToAddressException() { + $this->expectException(\Exception::class); new EMail('test', 'phpunit@simplesamlphp.org', "phpunit@simplesamlphp.org\nLorem Ipsum"); } @@ -65,10 +65,10 @@ class EMailTestCase extends ClearStateTestCase $this->assertRegexp('/(key-){6}/', $result); $this->assertRegexp('/(value-){6}/', $result); } + /** All templates that should be tested in #testMailContents($template) */ public static function mailTemplates() { return [['mailtxt.twig'], ['mailhtml.twig']]; } - } diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php index 07184088482e75bfbc1871aadbd7625b3ca715b7..ad8516be64dcbb8f5ed5ee66c202c0534eef16e8 100644 --- a/tests/lib/SimpleSAML/Utils/HTTPTest.php +++ b/tests/lib/SimpleSAML/Utils/HTTPTest.php @@ -34,21 +34,19 @@ class HTTPTest extends TestCase /** * Test SimpleSAML\Utils\HTTP::addURLParameters(). - * - * @expectedException \InvalidArgumentException */ public function testAddURLParametersInvalidURL() { + $this->expectException(\InvalidArgumentException::class); HTTP::addURLParameters([], []); } /** * Test SimpleSAML\Utils\HTTP::addURLParameters(). - * - * @expectedException \InvalidArgumentException */ public function testAddURLParametersInvalidParameters() { + $this->expectException(\InvalidArgumentException::class); HTTP::addURLParameters('string', 'string'); } @@ -314,7 +312,7 @@ class HTTPTest extends TestCase $this->assertEquals(HTTP::checkURLAllowed($url), $url); } - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException(\SimpleSAML\Error\Exception::class); HTTP::checkURLAllowed('https://evil.com'); $_SERVER = $original; @@ -346,7 +344,7 @@ class HTTPTest extends TestCase $this->assertEquals(HTTP::checkURLAllowed($url), $url); } - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException(\SimpleSAML\Error\Exception::class); HTTP::checkURLAllowed('https://evil.com'); $_SERVER = $original; @@ -411,7 +409,7 @@ class HTTPTest extends TestCase $_SERVER['REQUEST_URI'] = '/module.php'; - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException(\SimpleSAML\Error\Exception::class); HTTP::checkURLAllowed('https://app.example.com.evil.com'); $_SERVER = $original; diff --git a/tests/lib/SimpleSAML/Utils/SystemTest.php b/tests/lib/SimpleSAML/Utils/SystemTest.php index 6b2c49b28e91105a413bf08a576a8926452d08e1..37270a1bd550c79e15a75064bfe9c7891119d898 100644 --- a/tests/lib/SimpleSAML/Utils/SystemTest.php +++ b/tests/lib/SimpleSAML/Utils/SystemTest.php @@ -135,7 +135,7 @@ class SystemTest extends TestCase */ public function testWriteFileInvalidArguments() { - $this->setExpectedException('\InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); System::writeFile(null, null, null); } @@ -255,7 +255,7 @@ class SystemTest extends TestCase chown($tempdir, $bad_uid); - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException(\SimpleSAML\Error\Exception::class); System::getTempDir(); $this->clearInstance($config, '\SimpleSAML\Configuration'); diff --git a/tests/lib/SimpleSAML/Utils/XMLTest.php b/tests/lib/SimpleSAML/Utils/XMLTest.php index 1e9bacb8b986cada2225e18e2635877914df4891..a65d527e9565bf67da91273cb1086d078ba1a221 100644 --- a/tests/lib/SimpleSAML/Utils/XMLTest.php +++ b/tests/lib/SimpleSAML/Utils/XMLTest.php @@ -3,8 +3,9 @@ namespace SimpleSAML\Test\Utils; use PHPUnit\Framework\TestCase; -use \SimpleSAML\Configuration; -use \SimpleSAML\Utils\XML; + +use SimpleSAML\Configuration; +use SimpleSAML\Utils\XML; /** * Tests for SimpleSAML\Utils\XML. @@ -27,13 +28,12 @@ class XMLTest extends TestCase } /** - * @expectedException \InvalidArgumentException - * * @covers \SimpleSAML\Utils\XML::isDOMNodeOfType * @test */ public function testIsDomNodeOfTypeMissingNamespace() { + $this->expectException(\InvalidArgumentException::class); $name = 'name'; $namespace_uri = '@missing'; $element = new \DOMElement($name, 'value', $namespace_uri); @@ -141,13 +141,12 @@ class XMLTest extends TestCase } /** - * @expectedException \SimpleSAML\Error\Exception - * * @covers \SimpleSAML\Utils\XML::getDOMText * @test */ public function testGetDomTextIncorrectType() { + $this->expectException(\SimpleSAML\Error\Exception::class); $dom = new \DOMDocument(); $element = $dom->appendChild(new \DOMElement('root')); $element->appendChild(new \DOMComment('')); @@ -325,13 +324,12 @@ NOWDOC; } /** - * @expectedException \DOMException - * * @covers \SimpleSAML\Utils\XML::formatXMLString * @test */ public function testFormatXmlStringMalformedXml() { + $this->expectException(\DOMException::class); $xml = '<root><nested>text'; XML::formatXMLString($xml); @@ -385,7 +383,7 @@ NOWDOC; */ public function testCheckSAMLMessageInvalidType() { - $this->setExpectedException('\InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); XML::checkSAMLMessage('<test></test>', 'blub'); } } diff --git a/tests/lib/SimpleSAML/XML/ParserTest.php b/tests/lib/SimpleSAML/XML/ParserTest.php index 2e4e1891e1479496fc778c5ad9ceb49a21897dfc..b0b84bd1ced253883d9239e454cf437262bb6259 100644 --- a/tests/lib/SimpleSAML/XML/ParserTest.php +++ b/tests/lib/SimpleSAML/XML/ParserTest.php @@ -63,11 +63,11 @@ XML; /** * @covers \SimpleSAML\XML\Parser::getValue * @covers \SimpleSAML\XML\Parser::__construct - * @expectedException \Exception * @test */ public function getValueException() { + $this->expectException(\Exception::class); $this->xml->getValue('/Root/Foo', true); } @@ -131,17 +131,17 @@ XML; /** * @covers \SimpleSAML\XML\Parser::getValueAlternatives * @covers \SimpleSAML\XML\Parser::__construct - * @expectedException \Exception * @test */ public function getValueAlternativesException() { - $this - ->xml - ->getValueAlternatives([ + $this->expectException(\Exception::class); + $this->xml->getValueAlternatives( + [ '/Root/Foo', '/Root/Bar' - ], true) - ; + ], + true + ); } } diff --git a/tests/lib/SimpleSAML/XML/Shib13/AuthnResponseTest.php b/tests/lib/SimpleSAML/XML/Shib13/AuthnResponseTest.php index c2e266929c2a254117be5a3fec30f9323944f306..c8a654917e672c4c4075f68963463e8d5b4f0eaf 100644 --- a/tests/lib/SimpleSAML/XML/Shib13/AuthnResponseTest.php +++ b/tests/lib/SimpleSAML/XML/Shib13/AuthnResponseTest.php @@ -91,11 +91,11 @@ XML; /** * @covers \SimpleSAML\XML\Shib13\AuthnResponse::getIssuer * @covers \SimpleSAML\XML\Shib13\AuthnResponse::setXML - * @expectedException \Exception * @test */ public function getIssuerException() { + $this->expectException(\Exception::class); $xml = new AuthnResponse(); $xml->setXML(static::BADXMLDOC); diff --git a/tests/lib/SimpleSAML/XML/SignerTest.php b/tests/lib/SimpleSAML/XML/SignerTest.php index 0d39df0e327dfac16463f23f2bce0862262aae66..57a7aa4e23e1515fe8a32600d13c5989f2c033ba 100644 --- a/tests/lib/SimpleSAML/XML/SignerTest.php +++ b/tests/lib/SimpleSAML/XML/SignerTest.php @@ -151,7 +151,7 @@ NOWDOC; $signer = new Signer([]); - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); $signer->sign($element, $insertInto); } diff --git a/tests/lib/SimpleSAML/XML/ValidatorTest.php b/tests/lib/SimpleSAML/XML/ValidatorTest.php index c38cc05b48f7ff9e5804db8913b43f92785d502b..772f2619e32c82d5388faaf6c1dfa5d01776dcc9 100644 --- a/tests/lib/SimpleSAML/XML/ValidatorTest.php +++ b/tests/lib/SimpleSAML/XML/ValidatorTest.php @@ -21,7 +21,7 @@ class ValidatorTest extends SigningTestCase $doc = new \DOMDocument(); $doc->loadXML('<?xml version="1.0"?><node>value</node>'); - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); new Validator($doc); } @@ -90,7 +90,7 @@ class ValidatorTest extends SigningTestCase $signer->loadCertificate($this->good_certificate_file, true); $signer->sign($node, $signature_parent); - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); new Validator($doc, 'node', ['certFingerprint' => []]); } @@ -136,7 +136,7 @@ class ValidatorTest extends SigningTestCase $validator = new Validator($doc, 'node'); - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); $validator->validateFingerprint($fingerprint); } @@ -193,7 +193,7 @@ class ValidatorTest extends SigningTestCase { $ca_file = $this->ca_certificate_file.'NOT'; - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); Validator::validateCertificate($this->good_certificate, $ca_file); } } diff --git a/tests/modules/core/lib/Auth/Process/AttributeAddTest.php b/tests/modules/core/lib/Auth/Process/AttributeAddTest.php index 50cf5b3d19186357255dce4c649cd817524ab005..b8701a8777cbe0e7e3a023d0f041b2e058252aae 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeAddTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeAddTest.php @@ -141,11 +141,10 @@ class AttributeAddTest extends TestCase /** * Test wrong usage generates exceptions - * - * @expectedException Exception */ public function testWrongFlag() { + $this->expectException(\Exception::class); $config = [ '%nonsense', 'test' => ['value2'], @@ -160,11 +159,10 @@ class AttributeAddTest extends TestCase /** * Test wrong attribute value - * - * @expectedException Exception */ public function testWrongAttributeValue() { + $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 b8f9c7bb9b2649f041ea15c3b61797c6b6e39521..5c113ccb3acba442d7c6c98d6233030e45765ce5 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php @@ -214,11 +214,10 @@ class AttributeAlterTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testWrongConfig() { + $this->expectException(\Exception::class); $config = [ 'subject' => 'eduPersonAffiliation', 'pattern' => '/^emper/', @@ -234,11 +233,10 @@ class AttributeAlterTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testIncompleteConfig() { + $this->expectException(\Exception::class); $config = [ 'subject' => 'eduPersonAffiliation', ]; @@ -252,11 +250,10 @@ class AttributeAlterTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testIncompleteConfig2() { + $this->expectException(\Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', @@ -272,11 +269,10 @@ class AttributeAlterTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testIncompleteConfig3() { + $this->expectException(\Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', @@ -294,11 +290,10 @@ class AttributeAlterTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testIncompleteConfig4() { + $this->expectException(\Exception::class); $config = [ 'subject' => 'test', 'pattern' => '/wrong/', @@ -317,11 +312,10 @@ class AttributeAlterTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testIncompleteConfig5() { + $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 538bd10e09464b607fa351ba0e2e2770485cf2e6..1193fa2de545ed3dfcba6e76ec3342aeeadbe269 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeCopyTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeCopyTest.php @@ -128,11 +128,10 @@ class AttributeCopyTest extends TestCase /** * Test wrong attribute name - * - * @expectedException Exception */ public function testWrongAttributeName() { + $this->expectException(\Exception::class); $config = [ ['value2'], ]; @@ -146,11 +145,10 @@ class AttributeCopyTest extends TestCase /** * Test wrong attribute value - * - * @expectedException Exception */ public function testWrongAttributeValue() { + $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 01e2a6bee53060c72a1c9a3aae39e8a1b82b1267..16eac75063d5641ea682c6ff060cad48c3c131f5 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeLimitTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeLimitTest.php @@ -199,11 +199,10 @@ class AttributeLimitTest extends TestCase /** * Test for exception with illegal config. - * - * @expectedException Exception */ public function testInvalidConfig() { + $this->expectException(\Exception::class); $config = [ 'invalidArg' => true, ]; @@ -213,11 +212,10 @@ class AttributeLimitTest extends TestCase /** * Test for invalid attribute name - * - * @expectedException Exception */ public function testInvalidAttributeName() { + $this->expectException(\Exception::class); $config = [ null ]; @@ -441,11 +439,10 @@ class AttributeLimitTest extends TestCase * * This test is very unlikely and would require malformed metadata processing. * Cannot be generated via config options. - * - * @expectedException Exception */ public function testMatchAttributeValuesNotArray() { + $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 64ca49232aa3bfae4f1a9f5a1fc06062bbe94f2d..c89dcbf89ca16b27cf91e69dd006583abd695723 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeMapTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeMapTest.php @@ -166,7 +166,7 @@ class AttributeMapTest extends TestCase ], ]; - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); self::processFilter($config, $request); } @@ -181,7 +181,7 @@ class AttributeMapTest extends TestCase ], ]; - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); self::processFilter($config, $request); } @@ -196,7 +196,7 @@ class AttributeMapTest extends TestCase ], ]; - $this->setExpectedException('\Exception'); + $this->expectException(\Exception::class); self::processFilter($config, $request); } diff --git a/tests/modules/core/lib/Auth/Process/AttributeRealmTest.php b/tests/modules/core/lib/Auth/Process/AttributeRealmTest.php index f7d0ef60637720f0041bd85d1e4d0b9e8bfcf9ac..609b0c6437330680719cfbcf54ace95873764670 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeRealmTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeRealmTest.php @@ -43,11 +43,10 @@ class AttributeRealmTest extends TestCase /** * Test no userid set - * - * @expectedException Exception */ public function testNoUserID() { + $this->expectException(\Exception::class); $config = [ ]; $request = [ diff --git a/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php b/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php index ddf07427342248d0bd30e86c8374cfbe9c44b359..491638fe74193d227c8d31e640f2d36e5ccd8116 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeValueMapTest.php @@ -190,11 +190,10 @@ class AttributeValueMapTest extends TestCase * * @covers SimpleSAML\Module\core\Auth\Process\AttributeValueMap::__construct * @covers SimpleSAML\Module\core\Auth\Process\AttributeValueMap::process - * - * @expectedException \Exception */ public function testMissingSourceAttribute() { + $this->expectException(\Exception::class); $config = [ 'targetattribute' => 'affiliation', 'values' => [ @@ -217,11 +216,10 @@ class AttributeValueMapTest extends TestCase * * @covers SimpleSAML\Module\core\Auth\Process\AttributeValueMap::__construct * @covers SimpleSAML\Module\core\Auth\Process\AttributeValueMap::process - * - * @expectedException \Exception */ public function testMissingTargetAttribute() { + $this->expectException(\Exception::class); $config = [ 'sourceattribute' => 'memberOf', 'values' => [ diff --git a/tests/modules/core/lib/Auth/Process/CardinalityTest.php b/tests/modules/core/lib/Auth/Process/CardinalityTest.php index 1dec455bb82065eac4257f6d461fb9f2587aea38..5f3302c1be92af17bc415a432b2c359f95a3c373 100644 --- a/tests/modules/core/lib/Auth/Process/CardinalityTest.php +++ b/tests/modules/core/lib/Auth/Process/CardinalityTest.php @@ -159,11 +159,11 @@ class CardinalityTest extends \PHPUnit_Framework_TestCase /** * Test invalid minimum values - * @expectedException \SimpleSAML\Error\Exception - * @expectedExceptionMessageRegExp /Minimum/ */ public function testMinInvalid() { + $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectExceptionMessageRegExp('/Minimum/'); $config = [ 'mail' => ['min' => false], ]; @@ -177,11 +177,11 @@ class CardinalityTest extends \PHPUnit_Framework_TestCase /** * Test invalid minimum values - * @expectedException \SimpleSAML\Error\Exception - * @expectedExceptionMessageRegExp /Minimum/ */ public function testMinNegative() { + $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectExceptionMessageRegExp('/Minimum/'); $config = [ 'mail' => ['min' => -1], ]; @@ -195,11 +195,11 @@ class CardinalityTest extends \PHPUnit_Framework_TestCase /** * Test invalid maximum values - * @expectedException \SimpleSAML\Error\Exception - * @expectedExceptionMessageRegExp /Maximum/ */ public function testMaxInvalid() { + $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectExceptionMessageRegExp('/Maximum/'); $config = [ 'mail' => ['max' => false], ]; @@ -213,11 +213,11 @@ class CardinalityTest extends \PHPUnit_Framework_TestCase /** * Test maximum < minimum - * @expectedException \SimpleSAML\Error\Exception - * @expectedExceptionMessageRegExp /less than/ */ public function testMinGreaterThanMax() { + $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectExceptionMessageRegExp('/less than/'); $config = [ 'mail' => ['min' => 2, 'max' => 1], ]; @@ -231,11 +231,11 @@ class CardinalityTest extends \PHPUnit_Framework_TestCase /** * Test invalid attribute name - * @expectedException \SimpleSAML\Error\Exception - * @expectedExceptionMessageRegExp /Invalid attribute/ */ public function testInvalidAttributeName() { + $this->expectException(\SimpleSAML\Error\Exception::class); + $this->expectExceptionMessageRegExp('/Invalid attribute/'); $config = [ ['min' => 2, 'max' => 1], ]; diff --git a/tests/modules/core/lib/Auth/Process/PHPTest.php b/tests/modules/core/lib/Auth/Process/PHPTest.php index e37bee1adb2bd60098c1c04ed4ef789e55526a7e..56745710a19c9359997cf8cd63d734158423e147 100644 --- a/tests/modules/core/lib/Auth/Process/PHPTest.php +++ b/tests/modules/core/lib/Auth/Process/PHPTest.php @@ -31,8 +31,8 @@ class PHPTest extends TestCase public function testInvalidConfiguration() { $config = []; - $this->setExpectedException( - "\SimpleSAML\Error\Exception", + $this->expectException( + \SimpleSAML\Error\Exception::class, "core:PHP: missing mandatory configuration option 'code'." ); new \SimpleSAML\Module\core\Auth\Process\PHP($config, null); @@ -107,8 +107,8 @@ class PHPTest extends TestCase ] ]; - $this->setExpectedException( - "Exception", + $this->expectException( + \Exception::class, "Missing uid attribute." ); $this->processFilter($config, $request); diff --git a/tests/modules/core/lib/Auth/Process/TargetedIDTest.php b/tests/modules/core/lib/Auth/Process/TargetedIDTest.php index b4ef4ee4b0b11fbe32da02223e64cca8bbdc94d6..33089c033681c86331ad40e1bde26fffea631f2c 100644 --- a/tests/modules/core/lib/Auth/Process/TargetedIDTest.php +++ b/tests/modules/core/lib/Auth/Process/TargetedIDTest.php @@ -162,11 +162,10 @@ class TargetedIDTest extends TestCase /** * Test no userid set - * - * @expectedException Exception */ public function testNoUserID() { + $this->expectException(\Exception::class); $config = []; $request = [ 'Attributes' => [], @@ -176,11 +175,10 @@ class TargetedIDTest extends TestCase /** * Test with specified attribute not set - * - * @expectedException Exception */ public function testAttributeNotExists() { + $this->expectException(\Exception::class); $config = [ 'attributename' => 'uid', ]; @@ -194,11 +192,10 @@ class TargetedIDTest extends TestCase /** * Test with configuration error 1 - * - * @expectedException Exception */ public function testConfigInvalidAttributeName() { + $this->expectException(\Exception::class); $config = [ 'attributename' => 5, ]; @@ -212,11 +209,10 @@ class TargetedIDTest extends TestCase /** * Test with configuration error 2 - * - * @expectedException Exception */ public function testConfigInvalidNameId() { + $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 f477ad2abbf4b8310e9998f8e57f1c1db264060a..242ff79dbb9d41b936dbb13c267312fbd4c98fa9 100644 --- a/tests/modules/core/lib/Auth/UserPassBaseTest.php +++ b/tests/modules/core/lib/Auth/UserPassBaseTest.php @@ -32,7 +32,7 @@ class UserPassBaseTest extends \PHPUnit_Framework_TestCase public function testAuthenticateECPMissingUsername() { - $this->setExpectedException('\SimpleSAML\Error\Error', 'WRONGUSERPASS'); + $this->expectException(\SimpleSAML\Error\Error::class, 'WRONGUSERPASS'); $state = [ 'saml:Binding' => \SAML2\Constants::BINDING_PAOS, @@ -51,7 +51,7 @@ class UserPassBaseTest extends \PHPUnit_Framework_TestCase public function testAuthenticateECPMissingPassword() { - $this->setExpectedException('\SimpleSAML\Error\Error', 'WRONGUSERPASS'); + $this->expectException(\SimpleSAML\Error\Error::class, 'WRONGUSERPASS'); $state = [ 'saml:Binding' => \SAML2\Constants::BINDING_PAOS, diff --git a/tests/modules/core/lib/ControllerTest.php b/tests/modules/core/lib/ControllerTest.php index 9f2edea91b9409784e2b0f97e2161d634d32fca5..f85225a28d8b8a24cca06240362a6d66c78d64b4 100644 --- a/tests/modules/core/lib/ControllerTest.php +++ b/tests/modules/core/lib/ControllerTest.php @@ -135,7 +135,7 @@ class ControllerTest extends ClearStateTestCase $session = Session::getSessionFromRequest(); $factory = new AuthenticationFactory($this->config, $session); $c = new Controller($this->config, $session, $factory); - $this->setExpectedException(Exception::class); + $this->expectException(Exception::class); $c->login($request, 'invalid-auth-source'); } diff --git a/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php b/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php index 1f2993f7870fd34671a8be368890f27a2845281b..632fca86235f51638ada02e473deffea78029cba 100644 --- a/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php +++ b/tests/modules/multiauth/lib/Auth/Source/MultiAuthTest.php @@ -56,11 +56,11 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase } /** - * @expectedException \Exception - * @expectedExceptionMessage The required "sources" config option was not found */ public function testSourcesMustBePresent() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The required "sources" config option was not found'); $sourceConfig = Configuration::loadFromArray(array( 'example-multi' => array( 'multiauth:MultiAuth', @@ -73,11 +73,11 @@ class MultiAuthTest extends \SimpleSAML\Test\Utils\ClearStateTestCase } /** - * @expectedException \Exception - * @expectedExceptionMessage The optional "preselect" config option must be present in "sources" */ public function testPreselectMustBeValid() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The optional "preselect" config option must be present in "sources"'); $sourceConfig = Configuration::loadFromArray(array( 'example-multi' => array( 'multiauth:MultiAuth',