From: =?utf-8?q?David_Pr=C3=A9vot?= <taffit@debian.org>
Date: Sun, 2 Mar 2025 19:39:11 +0100
Subject: Modernize PHPUnit syntax

---
 tests/AppTest.php                      |  2 ++
 tests/ContainerTest.php                |  2 ++
 tests/DeferredCallableTest.php         |  2 ++
 tests/Handlers/AbstractHandlerTest.php |  5 ++++-
 tests/Handlers/ErrorTest.php           | 11 +++++------
 tests/Handlers/NotAllowedTest.php      | 10 +++++-----
 tests/Handlers/NotFoundTest.php        | 10 +++++-----
 tests/Handlers/PhpErrorTest.php        | 28 ++++++++++++++--------------
 tests/Http/UploadedFilesTest.php       | 26 ++++++++++----------------
 9 files changed, 49 insertions(+), 47 deletions(-)

diff --git a/tests/AppTest.php b/tests/AppTest.php
index 8a79cdb..e7957b2 100644
--- a/tests/AppTest.php
+++ b/tests/AppTest.php
@@ -10,6 +10,7 @@ namespace Slim\Tests;
 use BadMethodCallException;
 use Error;
 use Exception;
+use PHPUnit\Framework\Attributes\RequiresPhpunit;
 use PHPUnit;
 use Psr\Http\Message\RequestInterface;
 use Psr\Http\Message\ResponseInterface;
@@ -1598,6 +1599,7 @@ class AppTest extends PHPUnit\Framework\TestCase
         $app($req, $res);
     }
 
+    #[RequiresPhpunit('< 12')]
     public function testInvokeWithPimpleCallable()
     {
         // Prepare request and response objects
diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php
index d5d3c7b..502b7f1 100644
--- a/tests/ContainerTest.php
+++ b/tests/ContainerTest.php
@@ -8,6 +8,7 @@
 namespace Slim\Tests;
 
 use InvalidArgumentException;
+use PHPUnit\Framework\Attributes\RequiresPhpunit;
 use PHPUnit;
 use Psr\Container\ContainerInterface;
 use Slim\Container;
@@ -70,6 +71,7 @@ class ContainerTest extends PHPUnit\Framework\TestCase
     /**
      * Test `get()` does not recast exceptions which are thrown in a factory closure
      */
+    #[RequiresPhpunit('< 12')]
     public function testGetWithErrorThrownByFactoryClosure()
     {
         $this->expectException('InvalidArgumentException');
diff --git a/tests/DeferredCallableTest.php b/tests/DeferredCallableTest.php
index 4689fb4..7a0c2f3 100644
--- a/tests/DeferredCallableTest.php
+++ b/tests/DeferredCallableTest.php
@@ -7,6 +7,7 @@
 
 namespace Slim\Tests;
 
+use PHPUnit\Framework\Attributes\RequiresPhpunit;
 use PHPUnit;
 use Slim\Container;
 use Slim\DeferredCallable;
@@ -25,6 +26,7 @@ class DeferredCallableTest extends PHPUnit\Framework\TestCase
         $this->assertEquals(1, CallableTest::$CalledCount);
     }
 
+    #[RequiresPhpunit('< 12')]
     public function testItBindsClosuresToContainer()
     {
         $assertCalled = $this->getMockBuilder('StdClass')->addMethods(['foo'])->getMock();
diff --git a/tests/Handlers/AbstractHandlerTest.php b/tests/Handlers/AbstractHandlerTest.php
index 2e173e5..3d4484a 100644
--- a/tests/Handlers/AbstractHandlerTest.php
+++ b/tests/Handlers/AbstractHandlerTest.php
@@ -7,17 +7,19 @@
 
 namespace Slim\Tests\Handlers;
 
+use PHPUnit\Framework\Attributes\RequiresPhpunit;
 use PHPUnit;
 use ReflectionClass;
 use Slim\Handlers\AbstractHandler;
 
 class AbstractHandlerTest extends PHPUnit\Framework\TestCase
 {
+    #[RequiresPhpunit('< 12')]
     public function testHalfValidContentType()
     {
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
 
-        $req->expects($this->any())->method('getHeaderLine')->will($this->returnValue('unknown/+json'));
+        $req->expects($this->any())->method('getHeaderLine')->willReturn('unknown/+json');
 
         $abstractHandler = $this->getMockForAbstractClass(AbstractHandler::class);
 
@@ -45,6 +47,7 @@ class AbstractHandlerTest extends PHPUnit\Framework\TestCase
      * Ensure that an acceptable media-type is found in the Accept header even
      * if it's not the first in the list.
      */
+    #[RequiresPhpunit('< 12')]
     public function testAcceptableMediaTypeIsNotFirstInList()
     {
         $request = $this->getMockBuilder('Slim\Http\Request')
diff --git a/tests/Handlers/ErrorTest.php b/tests/Handlers/ErrorTest.php
index f9bbab2..2ac0a34 100644
--- a/tests/Handlers/ErrorTest.php
+++ b/tests/Handlers/ErrorTest.php
@@ -8,6 +8,7 @@
 namespace Slim\Tests\Handlers;
 
 use Exception;
+use PHPUnit\Framework\Attributes\DataProvider;
 use PHPUnit_Framework_MockObject_MockObject;
 use PHPUnit;
 use ReflectionClass;
@@ -33,9 +34,8 @@ class ErrorTest extends PHPUnit\Framework\TestCase
 
     /**
      * Test invalid method returns the correct code and content type
-     *
-     * @dataProvider errorProvider
      */
+    #[DataProvider('errorProvider')]
     public function testError($acceptHeader, $contentType, $startOfBody)
     {
         $error = new Error();
@@ -51,9 +51,8 @@ class ErrorTest extends PHPUnit\Framework\TestCase
 
     /**
      * Test invalid method returns the correct code and content type with details
-     *
-     * @dataProvider errorProvider
      */
+    #[DataProvider('errorProvider')]
     public function testErrorDisplayDetails($acceptHeader, $contentType, $startOfBody)
     {
         $error = new Error(true);
@@ -72,7 +71,7 @@ class ErrorTest extends PHPUnit\Framework\TestCase
         $this->expectException('UnexpectedValueException');
         $errorMock = $this->getMockBuilder(Error::class)->onlyMethods(['determineContentType'])->getMock();
         $errorMock->method('determineContentType')
-            ->will($this->returnValue('unknown/type'));
+            ->willReturn('unknown/type');
 
         $e = new Exception("Oops");
 
@@ -125,7 +124,7 @@ class ErrorTest extends PHPUnit\Framework\TestCase
     protected function getRequest($method, $acceptHeader)
     {
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
-        $req->expects($this->once())->method('getHeaderLine')->will($this->returnValue($acceptHeader));
+        $req->expects($this->once())->method('getHeaderLine')->willReturn($acceptHeader);
 
         return $req;
     }
diff --git a/tests/Handlers/NotAllowedTest.php b/tests/Handlers/NotAllowedTest.php
index 2dd7da1..84d8228 100644
--- a/tests/Handlers/NotAllowedTest.php
+++ b/tests/Handlers/NotAllowedTest.php
@@ -7,6 +7,7 @@
 
 namespace Slim\Tests\Handlers;
 
+use PHPUnit\Framework\Attributes\DataProvider;
 use PHPUnit_Framework_MockObject_MockObject;
 use PHPUnit;
 use Slim\Handlers\NotAllowed;
@@ -29,9 +30,8 @@ class NotAllowedTest extends PHPUnit\Framework\TestCase
 
     /**
      * Test invalid method returns the correct code and content type
-     *
-     * @dataProvider invalidMethodProvider
      */
+    #[DataProvider('invalidMethodProvider')]
     public function testInvalidMethod($acceptHeader, $contentType, $startOfBody)
     {
         $notAllowed = new NotAllowed();
@@ -62,7 +62,7 @@ class NotAllowedTest extends PHPUnit\Framework\TestCase
     {
         $errorMock = $this->getMockBuilder(NotAllowed::class)->onlyMethods(['determineContentType'])->getMock();
         $errorMock->method('determineContentType')
-            ->will($this->returnValue('unknown/type'));
+            ->willReturn('unknown/type');
 
         $this->expectException('\UnexpectedValueException');
         $errorMock->__invoke($this->getRequest('GET', 'unknown/type'), new Response(), ['POST']);
@@ -76,8 +76,8 @@ class NotAllowedTest extends PHPUnit\Framework\TestCase
     protected function getRequest($method, $contentType = 'text/html')
     {
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
-        $req->expects($this->once())->method('getMethod')->will($this->returnValue($method));
-        $req->expects($this->any())->method('getHeaderLine')->will($this->returnValue($contentType));
+        $req->expects($this->once())->method('getMethod')->willReturn($method);
+        $req->expects($this->any())->method('getHeaderLine')->willReturn($contentType);
 
         return $req;
     }
diff --git a/tests/Handlers/NotFoundTest.php b/tests/Handlers/NotFoundTest.php
index 4d57401..2c94803 100644
--- a/tests/Handlers/NotFoundTest.php
+++ b/tests/Handlers/NotFoundTest.php
@@ -7,6 +7,7 @@
 
 namespace Slim\Tests\Handlers;
 
+use PHPUnit\Framework\Attributes\DataProvider;
 use PHPUnit_Framework_MockObject_MockObject;
 use PHPUnit;
 use Slim\Handlers\NotFound;
@@ -30,9 +31,8 @@ class NotFoundTest extends PHPUnit\Framework\TestCase
 
     /**
      * Test invalid method returns the correct code and content type
-     *
-     * @dataProvider notFoundProvider
      */
+    #[DataProvider('notFoundProvider')]
     public function testNotFound($acceptHeader, $contentType, $startOfBody)
     {
         $notAllowed = new NotFound();
@@ -49,7 +49,7 @@ class NotFoundTest extends PHPUnit\Framework\TestCase
     {
         $errorMock = $this->getMockBuilder(NotFound::class)->onlyMethods(['determineContentType'])->getMock();
         $errorMock->method('determineContentType')
-            ->will($this->returnValue('unknown/type'));
+            ->willReturn('unknown/type');
 
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
 
@@ -67,8 +67,8 @@ class NotFoundTest extends PHPUnit\Framework\TestCase
         $uri = new Uri('http', 'example.com', 80, '/notfound');
 
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
-        $req->expects($this->once())->method('getHeaderLine')->will($this->returnValue($contentType));
-        $req->expects($this->any())->method('getUri')->will($this->returnValue($uri));
+        $req->expects($this->once())->method('getHeaderLine')->willReturn($contentType);
+        $req->expects($this->any())->method('getUri')->willReturn($uri);
 
         return $req;
     }
diff --git a/tests/Handlers/PhpErrorTest.php b/tests/Handlers/PhpErrorTest.php
index 5411cea..2c58c2b 100644
--- a/tests/Handlers/PhpErrorTest.php
+++ b/tests/Handlers/PhpErrorTest.php
@@ -8,6 +8,7 @@
 namespace Slim\Tests\Handlers;
 
 use Exception;
+use PHPUnit\Framework\Attributes\DataProvider;
 use PHPUnit_Framework_MockObject_MockObject;
 use PHPUnit;
 use Slim\Handlers\PhpError;
@@ -34,8 +35,8 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
      * Test invalid method returns the correct code and content type
      *
      * @requires PHP 7.0
-     * @dataProvider phpErrorProvider
      */
+    #[DataProvider('phpErrorProvider')]
     public function testPhpError($acceptHeader, $contentType, $startOfBody)
     {
         $error = new PhpError();
@@ -52,8 +53,8 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
      * Test invalid method returns the correct code and content type
      *
      * @requires PHP 7.0
-     * @dataProvider phpErrorProvider
      */
+    #[DataProvider('phpErrorProvider')]
     public function testPhpErrorDisplayDetails($acceptHeader, $contentType, $startOfBody)
     {
         $error = new PhpError(true);
@@ -75,7 +76,7 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
     {
         $errorMock = $this->getMockBuilder(PhpError::class)->onlyMethods(['determineContentType'])->getMock();
         $errorMock->method('determineContentType')
-            ->will($this->returnValue('unknown/type'));
+            ->willReturn('unknown/type');
 
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
 
@@ -87,8 +88,8 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
      * Test invalid method returns the correct code and content type
      *
      * @requires PHP 5.0
-     * @dataProvider phpErrorProvider
      */
+    #[DataProvider('phpErrorProvider')]
     public function testPhpError5($acceptHeader, $contentType, $startOfBody)
     {
         $this->skipIfPhp70();
@@ -109,9 +110,8 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
 
     /**
      * Test invalid method returns the correct code and content type
-     *
-     * @dataProvider phpErrorProvider
      */
+    #[DataProvider('phpErrorProvider')]
     public function testPhpErrorDisplayDetails5($acceptHeader, $contentType, $startOfBody)
     {
         $this->skipIfPhp70();
@@ -126,12 +126,12 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
 
         $throwablePrev = clone $throwable;
 
-        $throwable->method('getCode')->will($this->returnValue(1));
-        $throwable->method('getMessage')->will($this->returnValue('Oops'));
-        $throwable->method('getFile')->will($this->returnValue('test.php'));
-        $throwable->method('getLine')->will($this->returnValue('1'));
-        $throwable->method('getTraceAsString')->will($this->returnValue('This is error'));
-        $throwable->method('getPrevious')->will($this->returnValue($throwablePrev));
+        $throwable->method('getCode')->willReturn(1);
+        $throwable->method('getMessage')->willReturn('Oops');
+        $throwable->method('getFile')->willReturn('test.php');
+        $throwable->method('getLine')->willReturn('1');
+        $throwable->method('getTraceAsString')->willReturn('This is error');
+        $throwable->method('getPrevious')->willReturn($throwablePrev);
 
         $res = $error->__invoke($this->getRequest('GET', $acceptHeader), new Response(), $throwable);
 
@@ -149,7 +149,7 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
         $this->skipIfPhp70();
         $errorMock = $this->getMock(PhpError::class, ['determineContentType']);
         $errorMock->method('determineContentType')
-            ->will($this->returnValue('unknown/type'));
+            ->willReturn('unknown/type');
 
         $throwable = $this->getMockBuilder('Throwable')->getMock();
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
@@ -165,7 +165,7 @@ class PhpErrorTest extends PHPUnit\Framework\TestCase
     protected function getRequest($method, $acceptHeader)
     {
         $req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();
-        $req->expects($this->once())->method('getHeaderLine')->will($this->returnValue($acceptHeader));
+        $req->expects($this->once())->method('getHeaderLine')->willReturn($acceptHeader);
 
         return $req;
     }
diff --git a/tests/Http/UploadedFilesTest.php b/tests/Http/UploadedFilesTest.php
index 8f9a043..7a62980 100644
--- a/tests/Http/UploadedFilesTest.php
+++ b/tests/Http/UploadedFilesTest.php
@@ -7,6 +7,8 @@
 
 namespace Slim\Tests\Http;
 
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\Depends;
 use PHPUnit;
 use RuntimeException;
 use Slim\Http\Environment;
@@ -58,9 +60,8 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     /**
      * @param array $input    The input array to parse.
      * @param array $expected The expected normalized output.
-     *
-     * @dataProvider providerCreateFromEnvironment
      */
+    #[DataProvider('providerCreateFromEnvironment')]
     public function testCreateFromEnvironmentFromFilesSuperglobal(array $input, array $expected)
     {
         $_FILES = $input;
@@ -71,9 +72,8 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
 
     /**
      * @param array $input The input array to parse.
-     *
-     * @dataProvider providerCreateFromEnvironment
      */
+    #[DataProvider('providerCreateFromEnvironment')]
     public function testCreateFromEnvironmentFromUserData(array $input)
     {
         //If slim.files provided - it will return what was provided
@@ -123,12 +123,11 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     }
 
     /**
-     * @depends testConstructor
-     *
      * @param UploadedFile $uploadedFile
      *
      * @return UploadedFile
      */
+    #[Depends('testConstructor')]
     public function testGetStream(UploadedFile $uploadedFile)
     {
         $stream = $uploadedFile->getStream();
@@ -139,10 +138,9 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     }
 
     /**
-     * @depends testConstructor
-     *
      * @param UploadedFile $uploadedFile
      */
+    #[Depends('testConstructor')]
     public function testMoveToNotWritable(UploadedFile $uploadedFile)
     {
         $tempName = uniqid('file-');
@@ -152,12 +150,11 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     }
 
     /**
-     * @depends testConstructor
-     *
      * @param UploadedFile $uploadedFile
      *
      * @return UploadedFile
      */
+    #[Depends('testConstructor')]
     public function testMoveTo(UploadedFile $uploadedFile)
     {
         $tempName = uniqid('file-');
@@ -172,10 +169,9 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     }
 
     /**
-     * @depends testMoveTo
-     *
      * @param UploadedFile $uploadedFile
      */
+    #[Depends('testMoveTo')]
     public function testMoveToCannotBeDoneTwice(UploadedFile $uploadedFile)
     {
         $this->expectException('RuntimeException');
@@ -191,10 +187,9 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     /**
      * This test must run after testMoveTo
      *
-     * @depends testConstructor
-     *
      * @param UploadedFile $uploadedFile
      */
+    #[Depends('testConstructor')]
     public function testMoveToAgain(UploadedFile $uploadedFile)
     {
         $this->expectException('\RuntimeException');
@@ -207,10 +202,9 @@ class UploadedFilesTest extends PHPUnit\Framework\TestCase
     /**
      * This test must run after testMoveTo
      *
-     * @depends testConstructor
-     *
      * @param UploadedFile $uploadedFile
      */
+    #[Depends('testConstructor')]
     public function testMovedStream($uploadedFile)
     {
         $this->expectException('\RuntimeException');
