From 3d121046c4839a99833fffd2ea78b45258b1bbae Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Fri, 10 May 2019 16:36:50 +0200
Subject: [PATCH] Remove expectedException annotations (#1113)

---
 TESTING.md                                    | 11 +++--
 tests/lib/SimpleSAML/ConfigurationTest.php    | 43 ++++++++++---------
 tests/lib/SimpleSAML/DatabaseTest.php         |  6 +--
 .../Metadata/MetaDataStorageSourceTest.php    |  4 +-
 tests/lib/SimpleSAML/ModuleTest.php           |  9 ++--
 tests/lib/SimpleSAML/StoreTest.php            |  8 ++--
 tests/lib/SimpleSAML/Utils/AttributesTest.php | 34 +++++++--------
 tests/lib/SimpleSAML/Utils/ConfigTest.php     |  4 +-
 tests/lib/SimpleSAML/Utils/CryptoTest.php     | 23 ++++------
 tests/lib/SimpleSAML/Utils/EMailTestCase.php  |  8 ++--
 tests/lib/SimpleSAML/Utils/HTTPTest.php       | 12 +++---
 tests/lib/SimpleSAML/Utils/SystemTest.php     |  4 +-
 tests/lib/SimpleSAML/Utils/XMLTest.php        | 16 +++----
 tests/lib/SimpleSAML/XML/ParserTest.php       | 14 +++---
 .../XML/Shib13/AuthnResponseTest.php          |  2 +-
 tests/lib/SimpleSAML/XML/SignerTest.php       |  2 +-
 tests/lib/SimpleSAML/XML/ValidatorTest.php    |  8 ++--
 .../lib/Auth/Process/AttributeAddTest.php     |  6 +--
 .../lib/Auth/Process/AttributeAlterTest.php   | 18 +++-----
 .../lib/Auth/Process/AttributeCopyTest.php    |  6 +--
 .../lib/Auth/Process/AttributeLimitTest.php   |  9 ++--
 .../lib/Auth/Process/AttributeMapTest.php     |  6 +--
 .../lib/Auth/Process/AttributeRealmTest.php   |  3 +-
 .../Auth/Process/AttributeValueMapTest.php    |  6 +--
 .../core/lib/Auth/Process/CardinalityTest.php | 20 ++++-----
 .../modules/core/lib/Auth/Process/PHPTest.php |  8 ++--
 .../core/lib/Auth/Process/TargetedIDTest.php  | 12 ++----
 .../core/lib/Auth/UserPassBaseTest.php        |  4 +-
 tests/modules/core/lib/ControllerTest.php     |  2 +-
 .../lib/Auth/Source/MultiAuthTest.php         |  8 ++--
 30 files changed, 141 insertions(+), 175 deletions(-)

diff --git a/TESTING.md b/TESTING.md
index c38db47e8..302fb309a 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 18a21fe05..6b5d507bf 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 f48246fd2..14b002e64 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 591fd7fbf..6134676c0 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 a0c72b5f5..228ab0aed 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 ebaa1c5fb..4c54e574f 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 42685215a..fd66017a9 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 6077a6301..10a3d4e60 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 044fb054a..ed4d2b470 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 0117d2e1a..971d6a278 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 071840884..ad8516be6 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 6b2c49b28..37270a1bd 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 1e9bacb8b..a65d527e9 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 2e4e1891e..b0b84bd1c 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 c2e266929..c8a654917 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 0d39df0e3..57a7aa4e2 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 c38cc05b4..772f2619e 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 50cf5b3d1..b8701a877 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 b8f9c7bb9..5c113ccb3 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 538bd10e0..1193fa2de 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 01e2a6bee..16eac7506 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 64ca49232..c89dcbf89 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 f7d0ef606..609b0c643 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 ddf074273..491638fe7 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 1dec455bb..5f3302c1b 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 e37bee1ad..56745710a 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 b4ef4ee4b..33089c033 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 f477ad2ab..242ff79db 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 9f2edea91..f85225a28 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 1f2993f78..632fca862 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',
-- 
GitLab