From: James Valleroy <jvalleroy@mailbox.org>
Date: Tue, 16 Jun 2020 13:06:32 -0400
Subject: Modify tests for phpunit >= 6

Forwarded: not-needed
---
 tests/AppTest.php                      | 21 +++++++++++----------
 tests/CallableResolverTest.php         | 19 +++++++++++--------
 tests/CollectionTest.php               |  6 +++---
 tests/ContainerTest.php                |  6 +++---
 tests/DeferredCallableTest.php         |  4 ++--
 tests/Handlers/AbstractHandlerTest.php |  4 ++--
 tests/Handlers/ErrorTest.php           |  6 +++---
 tests/Handlers/NotAllowedTest.php      |  6 +++---
 tests/Handlers/NotFoundTest.php        |  6 +++---
 tests/Handlers/PhpErrorTest.php        |  6 +++---
 tests/Http/BodyTest.php                | 18 +++++++++---------
 tests/Http/CookiesTest.php             |  6 +++---
 tests/Http/EnvironmentTest.php         |  6 +++---
 tests/Http/HeadersTest.php             |  4 ++--
 tests/Http/MessageTest.php             |  4 ++--
 tests/Http/NonBufferedBodyTest.php     | 18 +++++++++++++-----
 tests/Http/RequestBodyTest.php         | 22 +++++++++++-----------
 tests/Http/RequestTest.php             |  4 ++--
 tests/Http/ResponseTest.php            |  4 ++--
 tests/Http/StreamTest.php              |  6 +++---
 tests/Http/UploadedFilesTest.php       | 14 +++++++-------
 tests/Http/UriTest.php                 |  4 ++--
 tests/MiddlewareAwareTest.php          |  8 ++++----
 tests/RouteTest.php                    |  8 ++++----
 tests/RouterTest.php                   | 20 +++++++++++++-------
 25 files changed, 124 insertions(+), 106 deletions(-)

diff --git a/tests/AppTest.php b/tests/AppTest.php
index 99ae8af..1dda3d6 100644
--- a/tests/AppTest.php
+++ b/tests/AppTest.php
@@ -10,7 +10,7 @@ namespace Slim\Tests;
 use BadMethodCallException;
 use Error;
 use Exception;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Psr\Http\Message\RequestInterface;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\UriInterface;
@@ -44,32 +44,33 @@ function header($value, $replace = true)
     \Slim\header($value, $replace);
 }
 
-class AppTest extends PHPUnit_Framework_TestCase
+class AppTest extends PHPUnit\Framework\TestCase
 {
-    public function setUp()
+    protected function setUp(): void
     {
         HeaderStack::reset();
     }
 
-    public function tearDown()
+    protected function tearDown(): void
     {
         HeaderStack::reset();
     }
 
-    public static function setupBeforeClass()
+    public static function setUpBeforeClass(): void
     {
         // ini_set('log_errors', 0);
         ini_set('error_log', tempnam(sys_get_temp_dir(), 'slim'));
     }
 
-    public static function tearDownAfterClass()
+    public static function tearDownAfterClass(): void
     {
         // ini_set('log_errors', 1);
     }
 
     public function testContainerInterfaceException()
     {
-        $this->setExpectedException('InvalidArgumentException', 'Expected a ContainerInterface');
+        $this->expectException('InvalidArgumentException');
+        $this->expectExceptionMessage('Expected a ContainerInterface');
         $app = new App('');
     }
 
@@ -1040,7 +1041,7 @@ class AppTest extends PHPUnit_Framework_TestCase
 
         // now test that exception is raised if the handler isn't registered
         unset($app->getContainer()['notAllowedHandler']);
-        $this->setExpectedException('Slim\Exception\MethodNotAllowedException');
+        $this->expectException('Slim\Exception\MethodNotAllowedException');
         $app($req, $res);
     }
 
@@ -1250,7 +1251,7 @@ class AppTest extends PHPUnit_Framework_TestCase
 
         // now test that exception is raised if the handler isn't registered
         unset($app->getContainer()['notFoundHandler']);
-        $this->setExpectedException('Slim\Exception\NotFoundException');
+        $this->expectException('Slim\Exception\NotFoundException');
         $app($req, $res);
     }
 
@@ -1317,7 +1318,7 @@ class AppTest extends PHPUnit_Framework_TestCase
 
         $app->get('/foo', 'foo:bar');
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
 
         // Invoke app
         $app($req, $res);
diff --git a/tests/CallableResolverTest.php b/tests/CallableResolverTest.php
index f3ac94d..6a2a2fb 100644
--- a/tests/CallableResolverTest.php
+++ b/tests/CallableResolverTest.php
@@ -7,20 +7,20 @@
 
 namespace Slim\Tests;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\CallableResolver;
 use Slim\Container;
 use Slim\Tests\Mocks\CallableTest;
 use Slim\Tests\Mocks\InvokableTest;
 
-class CallableResolverTest extends PHPUnit_Framework_TestCase
+class CallableResolverTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var Container
      */
     private $container;
 
-    public function setUp()
+    protected function setUp(): void
     {
         CallableTest::$CalledCount = 0;
         InvokableTest::$CalledCount = 0;
@@ -111,35 +111,38 @@ class CallableResolverTest extends PHPUnit_Framework_TestCase
     {
         $this->container['callable_service'] = new CallableTest();
         $resolver = new CallableResolver($this->container);
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $resolver->resolve('callable_service:noFound');
     }
 
     public function testFunctionNotFoundThrowException()
     {
         $resolver = new CallableResolver($this->container);
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $resolver->resolve('noFound');
     }
 
     public function testClassNotFoundThrowException()
     {
         $resolver = new CallableResolver($this->container);
-        $this->setExpectedException('\RuntimeException', 'Callable Unknown does not exist');
+        $this->expectException('\RuntimeException');
+        $this->expectExceptionMessage('Callable Unknown does not exist');
         $resolver->resolve('Unknown:notFound');
     }
 
     public function testCallableClassNotFoundThrowException()
     {
         $resolver = new CallableResolver($this->container);
-        $this->setExpectedException('\RuntimeException', 'is not resolvable');
+        $this->expectException('\RuntimeException');
+        $this->expectExceptionMessage('is not resolvable');
         $resolver->resolve(['Unknown', 'notFound']);
     }
 
     public function testCallableInvalidTypeThrowException()
     {
         $resolver = new CallableResolver($this->container);
-        $this->setExpectedException('\RuntimeException', 'is not resolvable');
+        $this->expectException('\RuntimeException');
+        $this->expectExceptionMessage('is not resolvable');
         $resolver->resolve(__LINE__);
     }
 }
diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php
index 7c21c66..b4feff6 100644
--- a/tests/CollectionTest.php
+++ b/tests/CollectionTest.php
@@ -7,11 +7,11 @@
 
 namespace Slim\Tests;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionProperty;
 use Slim\Collection;
 
-class CollectionTest extends PHPUnit_Framework_TestCase
+class CollectionTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var Collection
@@ -23,7 +23,7 @@ class CollectionTest extends PHPUnit_Framework_TestCase
      */
     protected $property;
 
-    public function setUp()
+    protected function setUp(): void
     {
         $this->bag = new Collection();
         $this->property = new ReflectionProperty($this->bag, 'data');
diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php
index b989bb2..a4e3b6d 100644
--- a/tests/ContainerTest.php
+++ b/tests/ContainerTest.php
@@ -8,18 +8,18 @@
 namespace Slim\Tests;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Psr\Container\ContainerInterface;
 use Slim\Container;
 
-class ContainerTest extends PHPUnit_Framework_TestCase
+class ContainerTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var Container
      */
     protected $container;
 
-    public function setUp()
+    protected function setUp(): void
     {
         $this->container = new Container;
     }
diff --git a/tests/DeferredCallableTest.php b/tests/DeferredCallableTest.php
index eb83383..453d482 100644
--- a/tests/DeferredCallableTest.php
+++ b/tests/DeferredCallableTest.php
@@ -7,12 +7,12 @@
 
 namespace Slim\Tests;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Container;
 use Slim\DeferredCallable;
 use Slim\Tests\Mocks\CallableTest;
 
-class DeferredCallableTest extends PHPUnit_Framework_TestCase
+class DeferredCallableTest extends PHPUnit\Framework\TestCase
 {
     public function testItResolvesCallable()
     {
diff --git a/tests/Handlers/AbstractHandlerTest.php b/tests/Handlers/AbstractHandlerTest.php
index aa7d08c..2e173e5 100644
--- a/tests/Handlers/AbstractHandlerTest.php
+++ b/tests/Handlers/AbstractHandlerTest.php
@@ -7,11 +7,11 @@
 
 namespace Slim\Tests\Handlers;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionClass;
 use Slim\Handlers\AbstractHandler;
 
-class AbstractHandlerTest extends PHPUnit_Framework_TestCase
+class AbstractHandlerTest extends PHPUnit\Framework\TestCase
 {
     public function testHalfValidContentType()
     {
diff --git a/tests/Handlers/ErrorTest.php b/tests/Handlers/ErrorTest.php
index d82c9a8..747c8bc 100644
--- a/tests/Handlers/ErrorTest.php
+++ b/tests/Handlers/ErrorTest.php
@@ -9,7 +9,7 @@ namespace Slim\Tests\Handlers;
 
 use Exception;
 use PHPUnit_Framework_MockObject_MockObject;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionClass;
 use RuntimeException;
 use Slim\Handlers\Error;
@@ -17,7 +17,7 @@ use Slim\Http\Request;
 use Slim\Http\Response;
 use UnexpectedValueException;
 
-class ErrorTest extends PHPUnit_Framework_TestCase
+class ErrorTest extends PHPUnit\Framework\TestCase
 {
     public function errorProvider()
     {
@@ -113,7 +113,7 @@ class ErrorTest extends PHPUnit_Framework_TestCase
         $renderHtmlExceptionorError = $class->getMethod('renderHtmlExceptionOrError');
         $renderHtmlExceptionorError->setAccessible(true);
 
-        $this->setExpectedException(RuntimeException::class);
+        $this->expectException(RuntimeException::class);
 
         $error = new Error();
         $renderHtmlExceptionorError->invokeArgs($error, ['foo']);
diff --git a/tests/Handlers/NotAllowedTest.php b/tests/Handlers/NotAllowedTest.php
index 49935b4..6c50b2f 100644
--- a/tests/Handlers/NotAllowedTest.php
+++ b/tests/Handlers/NotAllowedTest.php
@@ -8,12 +8,12 @@
 namespace Slim\Tests\Handlers;
 
 use PHPUnit_Framework_MockObject_MockObject;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Handlers\NotAllowed;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class NotAllowedTest extends PHPUnit_Framework_TestCase
+class NotAllowedTest extends PHPUnit\Framework\TestCase
 {
     public function invalidMethodProvider()
     {
@@ -64,7 +64,7 @@ class NotAllowedTest extends PHPUnit_Framework_TestCase
         $errorMock->method('determineContentType')
             ->will($this->returnValue('unknown/type'));
 
-        $this->setExpectedException('\UnexpectedValueException');
+        $this->expectException('\UnexpectedValueException');
         $errorMock->__invoke($this->getRequest('GET', 'unknown/type'), new Response(), ['POST']);
     }
 
diff --git a/tests/Handlers/NotFoundTest.php b/tests/Handlers/NotFoundTest.php
index 13351b2..9e4c652 100644
--- a/tests/Handlers/NotFoundTest.php
+++ b/tests/Handlers/NotFoundTest.php
@@ -8,13 +8,13 @@
 namespace Slim\Tests\Handlers;
 
 use PHPUnit_Framework_MockObject_MockObject;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Handlers\NotFound;
 use Slim\Http\Request;
 use Slim\Http\Response;
 use Slim\Http\Uri;
 
-class NotFoundTest extends PHPUnit_Framework_TestCase
+class NotFoundTest extends PHPUnit\Framework\TestCase
 {
     public function notFoundProvider()
     {
@@ -53,7 +53,7 @@ class NotFoundTest extends PHPUnit_Framework_TestCase
 
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
 
-        $this->setExpectedException('\UnexpectedValueException');
+        $this->expectException('\UnexpectedValueException');
         $errorMock->__invoke($req, new Response(), ['POST']);
     }
 
diff --git a/tests/Handlers/PhpErrorTest.php b/tests/Handlers/PhpErrorTest.php
index 864495e..405b88b 100644
--- a/tests/Handlers/PhpErrorTest.php
+++ b/tests/Handlers/PhpErrorTest.php
@@ -9,14 +9,14 @@ namespace Slim\Tests\Handlers;
 
 use Exception;
 use PHPUnit_Framework_MockObject_MockObject;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Handlers\PhpError;
 use Slim\Http\Request;
 use Slim\Http\Response;
 use Throwable;
 use UnexpectedValueException;
 
-class PhpErrorTest extends PHPUnit_Framework_TestCase
+class PhpErrorTest extends PHPUnit\Framework\TestCase
 {
     public function phpErrorProvider()
     {
@@ -79,7 +79,7 @@ class PhpErrorTest extends PHPUnit_Framework_TestCase
 
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
 
-        $this->setExpectedException('\UnexpectedValueException');
+        $this->expectException('\UnexpectedValueException');
         $errorMock->__invoke($req, new Response(), new Exception());
     }
 
diff --git a/tests/Http/BodyTest.php b/tests/Http/BodyTest.php
index d14a6b8..8dbe09d 100644
--- a/tests/Http/BodyTest.php
+++ b/tests/Http/BodyTest.php
@@ -8,11 +8,11 @@
 namespace Slim\Tests\Http;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionProperty;
 use Slim\Http\Body;
 
-class BodyTest extends PHPUnit_Framework_TestCase
+class BodyTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var string
@@ -25,7 +25,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
      */
     protected $stream;
 
-    protected function tearDown()
+    protected function tearDown(): void
     {
         if (is_resource($this->stream) === true) {
             fclose($this->stream);
@@ -198,7 +198,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
         $bodyStream->setAccessible(true);
         $bodyStream->setValue($body, null);
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $body->tell();
     }
 
@@ -319,7 +319,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
         $body = new Body($this->stream);
         $body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $body->seek(10);
     }
 
@@ -339,7 +339,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
         $body = new Body($this->stream);
         $body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $body->rewind();
     }
 
@@ -357,7 +357,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
         $body = new Body($this->stream);
         $body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $body->read(10);
     }
 
@@ -379,7 +379,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
         $body = new Body($this->stream);
         $body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $body->write('foo');
     }
 
@@ -398,7 +398,7 @@ class BodyTest extends PHPUnit_Framework_TestCase
         $body = new Body($this->stream);
         $body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $body->getContents();
     }
 }
diff --git a/tests/Http/CookiesTest.php b/tests/Http/CookiesTest.php
index 9370b73..962cb09 100644
--- a/tests/Http/CookiesTest.php
+++ b/tests/Http/CookiesTest.php
@@ -8,13 +8,13 @@
 namespace Slim\Tests\Http;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionClass;
 use ReflectionProperty;
 use Slim\Http\Cookies;
 use stdClass;
 
-class CookiesTest extends PHPUnit_Framework_TestCase
+class CookiesTest extends PHPUnit\Framework\TestCase
 {
     public function testConstructor()
     {
@@ -269,7 +269,7 @@ class CookiesTest extends PHPUnit_Framework_TestCase
 
     public function testParseHeaderException()
     {
-        $this->setExpectedException(InvalidArgumentException::class);
+        $this->expectException(InvalidArgumentException::class);
         Cookies::parseHeader(new stdClass);
     }
 }
diff --git a/tests/Http/EnvironmentTest.php b/tests/Http/EnvironmentTest.php
index c0d8a54..4270e2a 100644
--- a/tests/Http/EnvironmentTest.php
+++ b/tests/Http/EnvironmentTest.php
@@ -7,16 +7,16 @@
 
 namespace Slim\Tests\Http;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Http\Environment;
 
-class EnvironmentTest extends PHPUnit_Framework_TestCase
+class EnvironmentTest extends PHPUnit\Framework\TestCase
 {
     /**
      * Server settings for the default HTTP request
      * used by this script's tests.
      */
-    public function setUp()
+    protected function setUp(): void
     {
         $_SERVER['DOCUMENT_ROOT'] = '/var/www';
         $_SERVER['SCRIPT_NAME'] = '/foo/index.php';
diff --git a/tests/Http/HeadersTest.php b/tests/Http/HeadersTest.php
index c64de5b..3c664e4 100644
--- a/tests/Http/HeadersTest.php
+++ b/tests/Http/HeadersTest.php
@@ -7,12 +7,12 @@
 
 namespace Slim\Tests\Http;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionProperty;
 use Slim\Http\Environment;
 use Slim\Http\Headers;
 
-class HeadersTest extends PHPUnit_Framework_TestCase
+class HeadersTest extends PHPUnit\Framework\TestCase
 {
     public function testCreateFromEnvironment()
     {
diff --git a/tests/Http/MessageTest.php b/tests/Http/MessageTest.php
index 654fecd..ef73a5f 100644
--- a/tests/Http/MessageTest.php
+++ b/tests/Http/MessageTest.php
@@ -9,12 +9,12 @@ namespace Slim\Tests\Http;
 
 use InvalidArgumentException;
 use PHPUnit_Framework_MockObject_MockObject;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Http\Body;
 use Slim\Http\Headers;
 use Slim\Tests\Mocks\MessageStub;
 
-class MessageTest extends PHPUnit_Framework_TestCase
+class MessageTest extends PHPUnit\Framework\TestCase
 {
     public function testGetProtocolVersion()
     {
diff --git a/tests/Http/NonBufferedBodyTest.php b/tests/Http/NonBufferedBodyTest.php
index 537612a..894b5f0 100644
--- a/tests/Http/NonBufferedBodyTest.php
+++ b/tests/Http/NonBufferedBodyTest.php
@@ -7,19 +7,19 @@
 
 namespace Slim\Tests\Http;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Http\NonBufferedBody;
 use Slim\Http\Response;
 use Slim\Tests\Assets\HeaderStack;
 
-class NonBufferedBodyTest extends PHPUnit_Framework_TestCase
+class NonBufferedBodyTest extends PHPUnit\Framework\TestCase
 {
-    protected function setUp()
+    protected function setUp(): void
     {
         HeaderStack::reset();
     }
 
-    protected function tearDown()
+    protected function tearDown(): void
     {
         HeaderStack::reset();
     }
@@ -75,6 +75,9 @@ class NonBufferedBodyTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('buffer content: hello world', $contents);
     }
 
+    /**
+     * @runInSeparateProcess
+     */
     public function testWithHeader()
     {
         (new Response())
@@ -90,6 +93,9 @@ class NonBufferedBodyTest extends PHPUnit_Framework_TestCase
         ], HeaderStack::stack());
     }
 
+    /**
+     * @runInSeparateProcess
+     */
     public function testWithAddedHeader()
     {
         (new Response())
@@ -111,7 +117,9 @@ class NonBufferedBodyTest extends PHPUnit_Framework_TestCase
         ], HeaderStack::stack());
     }
 
-
+    /**
+     * @runInSeparateProcess
+     */
     public function testWithoutHeader()
     {
         (new Response())
diff --git a/tests/Http/RequestBodyTest.php b/tests/Http/RequestBodyTest.php
index 07f3b74..480f7d2 100644
--- a/tests/Http/RequestBodyTest.php
+++ b/tests/Http/RequestBodyTest.php
@@ -7,11 +7,11 @@
 
 namespace Slim\Tests\Http;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionProperty;
 use Slim\Http\RequestBody;
 
-class RequestBodyTest extends PHPUnit_Framework_TestCase
+class RequestBodyTest extends PHPUnit\Framework\TestCase
 {
     /** @var string */
     // @codingStandardsIgnoreStart
@@ -26,14 +26,14 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
      * Sets up the fixture, for example, open a network connection.
      * This method is called before a test is executed.
      */
-    protected function setUp()
+    protected function setUp(): void
     {
         $this->body = new RequestBody();
         $this->body->write($this->text);
         $this->body->rewind();
     }
 
-    protected function tearDown()
+    protected function tearDown(): void
     {
         if (is_resource($this->stream) === true) {
             fclose($this->stream);
@@ -147,7 +147,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($this->body->isWritable());
         $this->assertEquals('', (string)$this->body);
 
-        $this->setExpectedException('RuntimeException');
+        $this->expectException('RuntimeException');
         $this->body->tell();
     }
 
@@ -178,7 +178,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
         $bodyStream->setAccessible(true);
         $bodyStream->setValue($this->body, null);
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $this->body->tell();
     }
 
@@ -256,7 +256,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
     {
         $this->body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $this->body->seek(10);
     }
 
@@ -272,7 +272,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
     {
         $this->body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $this->body->rewind();
     }
 
@@ -285,7 +285,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
     {
         $this->body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $this->body->read(10);
     }
 
@@ -303,7 +303,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
     {
         $this->body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $this->body->write('foo');
     }
 
@@ -318,7 +318,7 @@ class RequestBodyTest extends PHPUnit_Framework_TestCase
     {
         $this->body->detach();
 
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
         $this->body->getContents();
     }
 }
diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php
index 2ec7429..e19ac41 100644
--- a/tests/Http/RequestTest.php
+++ b/tests/Http/RequestTest.php
@@ -8,7 +8,7 @@
 namespace Slim\Tests\Http;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Prophecy\Argument;
 use Prophecy\Prophecy\MethodProphecy;
 use Psr\Http\Message\UriInterface;
@@ -22,7 +22,7 @@ use Slim\Http\RequestBody;
 use Slim\Http\UploadedFile;
 use Slim\Http\Uri;
 
-class RequestTest extends PHPUnit_Framework_TestCase
+class RequestTest extends PHPUnit\Framework\TestCase
 {
     public function requestFactory($envData = [])
     {
diff --git a/tests/Http/ResponseTest.php b/tests/Http/ResponseTest.php
index faaaa3b..5e456aa 100755
--- a/tests/Http/ResponseTest.php
+++ b/tests/Http/ResponseTest.php
@@ -8,14 +8,14 @@
 namespace Slim\Tests\Http;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionProperty;
 use RuntimeException;
 use Slim\Http\Body;
 use Slim\Http\Headers;
 use Slim\Http\Response;
 
-class ResponseTest extends PHPUnit_Framework_TestCase
+class ResponseTest extends PHPUnit\Framework\TestCase
 {
     public function testConstructorWithDefaultArgs()
     {
diff --git a/tests/Http/StreamTest.php b/tests/Http/StreamTest.php
index 1c5bbbe..6d0f030 100644
--- a/tests/Http/StreamTest.php
+++ b/tests/Http/StreamTest.php
@@ -7,11 +7,11 @@
 
 namespace Slim\Tests\Http;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use RuntimeException;
 use Slim\Http\Stream;
 
-class StreamTest extends PHPUnit_Framework_TestCase
+class StreamTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var resource pipe stream file handle
@@ -23,7 +23,7 @@ class StreamTest extends PHPUnit_Framework_TestCase
      */
     private $pipeStream;
 
-    public function tearDown()
+    protected function tearDown(): void
     {
         if ($this->pipeFh != null) {
             stream_get_contents($this->pipeFh); // prevent broken pipe error message
diff --git a/tests/Http/UploadedFilesTest.php b/tests/Http/UploadedFilesTest.php
index 71246d1..7869335 100644
--- a/tests/Http/UploadedFilesTest.php
+++ b/tests/Http/UploadedFilesTest.php
@@ -7,7 +7,7 @@
 
 namespace Slim\Tests\Http;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use RuntimeException;
 use Slim\Http\Environment;
 use Slim\Http\Headers;
@@ -17,20 +17,20 @@ use Slim\Http\Stream;
 use Slim\Http\UploadedFile;
 use Slim\Http\Uri;
 
-class UploadedFilesTest extends PHPUnit_Framework_TestCase
+class UploadedFilesTest extends PHPUnit\Framework\TestCase
 {
     static private $filename = './phpUxcOty';
 
     static private $tmpFiles = ['./phpUxcOty'];
 
-    public static function setUpBeforeClass()
+    public static function setUpBeforeClass(): void
     {
         $fh = fopen(self::$filename, "w");
         fwrite($fh, "12345678");
         fclose($fh);
     }
 
-    public static function tearDownAfterClass()
+    public static function tearDownAfterClass(): void
     {
         foreach (self::$tmpFiles as $filename) {
             if (file_exists($filename)) {
@@ -147,7 +147,7 @@ class UploadedFilesTest extends PHPUnit_Framework_TestCase
     {
         $tempName = uniqid('file-');
         $path = 'some_random_dir' . DIRECTORY_SEPARATOR . $tempName;
-        $this->setExpectedException('\InvalidArgumentException');
+        $this->expectException('\InvalidArgumentException');
         $uploadedFile->moveTo($path);
     }
 
@@ -198,7 +198,7 @@ class UploadedFilesTest extends PHPUnit_Framework_TestCase
      */
     public function testMoveToAgain(UploadedFile $uploadedFile)
     {
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
 
         $tempName = uniqid('file-');
         $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName;
@@ -214,7 +214,7 @@ class UploadedFilesTest extends PHPUnit_Framework_TestCase
      */
     public function testMovedStream($uploadedFile)
     {
-        $this->setExpectedException('\RuntimeException');
+        $this->expectException('\RuntimeException');
 
         $uploadedFile->getStream();
     }
diff --git a/tests/Http/UriTest.php b/tests/Http/UriTest.php
index c8dd090..9198f3b 100644
--- a/tests/Http/UriTest.php
+++ b/tests/Http/UriTest.php
@@ -8,11 +8,11 @@
 namespace Slim\Tests\Http;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Http\Environment;
 use Slim\Http\Uri;
 
-class UriTest extends PHPUnit_Framework_TestCase
+class UriTest extends PHPUnit\Framework\TestCase
 {
     protected $uri;
 
diff --git a/tests/MiddlewareAwareTest.php b/tests/MiddlewareAwareTest.php
index b206f0f..70721ce 100644
--- a/tests/MiddlewareAwareTest.php
+++ b/tests/MiddlewareAwareTest.php
@@ -7,7 +7,7 @@
 
 namespace Slim\Tests;
 
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use RuntimeException;
 use Slim\Http\Body;
 use Slim\Http\Headers;
@@ -16,7 +16,7 @@ use Slim\Http\Response;
 use Slim\Http\Uri;
 use Slim\Tests\Mocks\Stackable;
 
-class MiddlewareAwareTest extends PHPUnit_Framework_TestCase
+class MiddlewareAwareTest extends PHPUnit\Framework\TestCase
 {
     public function testSeedsMiddlewareStack()
     {
@@ -160,7 +160,7 @@ class MiddlewareAwareTest extends PHPUnit_Framework_TestCase
             });
             return $resp;
         });
-        $this->setExpectedException('RuntimeException');
+        $this->expectException('RuntimeException');
         $stack->callMiddlewareStack(
             $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->disableOriginalConstructor()->getMock(),
             $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->disableOriginalConstructor()->getMock()
@@ -171,7 +171,7 @@ class MiddlewareAwareTest extends PHPUnit_Framework_TestCase
     {
         $stack = new Stackable;
         $stack->alternativeSeed();
-        $this->setExpectedException('RuntimeException');
+        $this->expectException('RuntimeException');
         $stack->alternativeSeed();
     }
 }
diff --git a/tests/RouteTest.php b/tests/RouteTest.php
index 5e2527d..c894b2a 100644
--- a/tests/RouteTest.php
+++ b/tests/RouteTest.php
@@ -8,7 +8,7 @@
 namespace Slim\Tests;
 
 use Exception;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use Slim\Container;
 use Slim\DeferredCallable;
 use Slim\Http\Body;
@@ -22,7 +22,7 @@ use Slim\Tests\Mocks\CallableTest;
 use Slim\Tests\Mocks\InvocationStrategyTest;
 use Slim\Tests\Mocks\MiddlewareStub;
 
-class RouteTest extends PHPUnit_Framework_TestCase
+class RouteTest extends PHPUnit\Framework\TestCase
 {
     public function routeFactory()
     {
@@ -176,7 +176,7 @@ class RouteTest extends PHPUnit_Framework_TestCase
     {
         $route = $this->routeFactory();
 
-        $this->setExpectedException('InvalidArgumentException');
+        $this->expectException('InvalidArgumentException');
 
         $route->setName(false);
     }
@@ -201,7 +201,7 @@ class RouteTest extends PHPUnit_Framework_TestCase
     {
         $route = $this->routeFactory();
 
-        $this->setExpectedException('InvalidArgumentException');
+        $this->expectException('InvalidArgumentException');
 
         $route->setOutputBuffering('invalid');
     }
diff --git a/tests/RouterTest.php b/tests/RouterTest.php
index d825d5c..8234166 100644
--- a/tests/RouterTest.php
+++ b/tests/RouterTest.php
@@ -8,13 +8,13 @@
 namespace Slim\Tests;
 
 use InvalidArgumentException;
-use PHPUnit_Framework_TestCase;
+use PHPUnit;
 use ReflectionClass;
 use RuntimeException;
 use Slim\Http\Uri;
 use Slim\Router;
 
-class RouterTest extends PHPUnit_Framework_TestCase
+class RouterTest extends PHPUnit\Framework\TestCase
 {
     /**
      * @var Router
@@ -26,12 +26,12 @@ class RouterTest extends PHPUnit_Framework_TestCase
      */
     protected $cacheFile;
 
-    public function setUp()
+    protected function setUp(): void
     {
         $this->router = new Router;
     }
 
-    public function tearDown()
+    protected function tearDown(): void
     {
         if (file_exists($this->cacheFile)) {
             unlink($this->cacheFile);
@@ -354,8 +354,10 @@ class RouterTest extends PHPUnit_Framework_TestCase
 
     public function testSettingInvalidCacheFileValue()
     {
-        $this->setExpectedException(
+        $this->expectException(
             '\InvalidArgumentException',
+        );
+        $this->expectExceptionMessage(
             'Router cache file must be a string'
         );
         $this->router->setCacheFile(['invalid']);
@@ -366,8 +368,10 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $this->cacheFile = __DIR__ . '/non-readable.cache';
         file_put_contents($this->cacheFile, '<?php return []; ?>');
 
-        $this->setExpectedException(
+        $this->expectException(
             '\RuntimeException',
+        );
+        $this->expectExceptionMessage(
             sprintf('Router cache file `%s` is not readable', $this->cacheFile)
         );
 
@@ -378,8 +382,10 @@ class RouterTest extends PHPUnit_Framework_TestCase
     {
         $cacheFile = __DIR__ . '/non-writable-directory/router.cache';
 
-        $this->setExpectedException(
+        $this->expectException(
             '\RuntimeException',
+        );
+        $this->expectExceptionMessage(
             sprintf('Router cache file directory `%s` is not writable', dirname($cacheFile))
         );
 
