File: 0011-Modernize-PHPUnit-syntax.patch

package info (click to toggle)
php-slim 3.12.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: php: 11,581; makefile: 18; xml: 10; sh: 3
file content (457 lines) | stat: -rw-r--r-- 17,687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
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');