Skip to content

Commit 3119820

Browse files
authored
Add phpunit v11 support (#2196)
1 parent 0d4dc18 commit 3119820

File tree

13 files changed

+39
-9
lines changed

13 files changed

+39
-9
lines changed

demos/_unit-test/fatal-error.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111

1212
$runOnShutdownFx = static function (\Closure $fx) use ($app) {
1313
// relies on https://github.com/atk4/ui/blob/5.0.0/src/App.php#L1108
14-
$app->onHook(App::HOOK_BEFORE_RENDER, static function () use (&$fx) {
15-
if ($fx !== null) {
16-
try {
17-
$fx();
18-
} finally {
19-
$fx = null;
20-
}
21-
}
14+
$hookIndex = $app->onHook(App::HOOK_BEFORE_RENDER, static function () use ($app, &$hookIndex, $fx) {
15+
$app->removeHook(App::HOOK_BEFORE_RENDER, $hookIndex, true);
16+
17+
$fx();
2218
});
2319
};
2420

src/HtmlTemplate/Value.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private function encodeValueToHtml(string $value): string
2525
*/
2626
public function set(string $value): self
2727
{
28-
if (\PHP_MAJOR_VERSION === 7 || (\PHP_MAJOR_VERSION === 8 && \PHP_MAJOR_VERSION <= 1) // @phpstan-ignore-line
28+
if (\PHP_VERSION_ID < 80200
2929
? !preg_match('~~u', $value) // much faster in PHP 8.1 and lower
3030
: !mb_check_encoding($value, 'UTF-8')
3131
) {

tests/AppTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Atk4\Ui\Exception\LateOutputError;
1010
use Atk4\Ui\HtmlTemplate;
1111
use Nyholm\Psr7\Factory\Psr17Factory;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213

1314
class AppTest extends TestCase
1415
{
@@ -186,6 +187,7 @@ public static function provideUrlCases(): iterable
186187
* @param array<0|string, string|int|false> $page
187188
* @param array<string, string> $extraRequestUrlArgs
188189
*/
190+
#[DataProvider('provideUrlCases')]
189191
public function testUrl(string $requestUrl, array $appStickyGetArguments, array $page, array $extraRequestUrlArgs, string $expectedUrl): void
190192
{
191193
$request = (new Psr17Factory())->createServerRequest('GET', $requestUrl);

tests/ButtonTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Button;
9+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
910

1011
class ButtonTest extends TestCase
1112
{
@@ -14,6 +15,7 @@ class ButtonTest extends TestCase
1415
/**
1516
* @doesNotPerformAssertions
1617
*/
18+
#[DoesNotPerformAssertions]
1719
public function testButtonIcon(): void
1820
{
1921
$button = new Button(['Load', 'icon' => 'pause']);

tests/DemosHttpNoExitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
namespace Atk4\Ui\Tests;
66

7+
use PHPUnit\Framework\Attributes\Group;
8+
79
/**
810
* Same as DemosHttpTest, only App::callExit is set to false.
911
*
1012
* @group demos_http
1113
*/
14+
#[Group('demos_http')]
1215
class DemosHttpNoExitTest extends DemosHttpTest
1316
{
1417
/** @var bool set the app->callExit in demo */

tests/DemosHttpTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
use GuzzleHttp\Client;
99
use GuzzleHttp\Exception\ConnectException;
1010
use GuzzleHttp\Psr7\LazyOpenStream;
11+
use PHPUnit\Framework\Attributes\DataProvider;
12+
use PHPUnit\Framework\Attributes\Group;
1113
use Symfony\Component\Process\Process;
1214

1315
/**
1416
* Same as DemosTest, but using native HTTP to check if output and shutdown handlers work correctly.
1517
*
1618
* @group demos_http
1719
*/
20+
#[Group('demos_http')]
1821
class DemosHttpTest extends DemosTest
1922
{
2023
/** @var Process|null */
@@ -158,6 +161,7 @@ public static function provideDemoCallbackErrorCases(): iterable
158161
/**
159162
* @dataProvider provideDemoLateOutputErrorCases
160163
*/
164+
#[DataProvider('provideDemoLateOutputErrorCases')]
161165
public function testDemoLateOutputError(string $urlTrigger, string $expectedOutput): void
162166
{
163167
$path = '_unit-test/late-output-error.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . $urlTrigger . '=ajax&'

tests/DemosTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use GuzzleHttp\Exception\ServerException;
1818
use GuzzleHttp\Promise\FulfilledPromise;
1919
use GuzzleHttp\Psr7\Request;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021
use Psr\Http\Message\RequestInterface;
2122
use Psr\Http\Message\ResponseInterface;
2223

@@ -290,6 +291,7 @@ public static function provideDemosStatusAndHtmlResponseCases(): iterable
290291
/**
291292
* @dataProvider provideDemosStatusAndHtmlResponseCases
292293
*/
294+
#[DataProvider('provideDemosStatusAndHtmlResponseCases')]
293295
public function testDemosStatusAndHtmlResponse(string $path): void
294296
{
295297
$response = $this->getResponseFromRequest($path);
@@ -322,6 +324,7 @@ public static function provideDemoGetCases(): iterable
322324
/**
323325
* @dataProvider provideDemoGetCases
324326
*/
327+
#[DataProvider('provideDemoGetCases')]
325328
public function testDemoGet(string $path): void
326329
{
327330
$response = $this->getResponseFromRequest($path);
@@ -398,6 +401,7 @@ public static function provideDemoJsonResponseCases(): iterable
398401
*
399402
* @dataProvider provideDemoJsonResponseCases
400403
*/
404+
#[DataProvider('provideDemoJsonResponseCases')]
401405
public function testDemoJsonResponse(string $path, ?string $expectedExceptionMessage = null): void
402406
{
403407
if (static::class === self::class) {
@@ -436,6 +440,7 @@ public static function provideDemoSseResponseCases(): iterable
436440
*
437441
* @dataProvider provideDemoSseResponseCases
438442
*/
443+
#[DataProvider('provideDemoSseResponseCases')]
439444
public function testDemoSseResponse(string $path): void
440445
{
441446
// this test requires SessionTrait, more precisely session_start() which we do not support in non-HTTP testing
@@ -476,6 +481,7 @@ public static function provideDemoJsonResponsePostCases(): iterable
476481
/**
477482
* @dataProvider provideDemoJsonResponsePostCases
478483
*/
484+
#[DataProvider('provideDemoJsonResponsePostCases')]
479485
public function testDemoJsonResponsePost(string $path, array $postData): void
480486
{
481487
$response = $this->getResponseFromRequest($path, ['form_params' => $postData]);
@@ -488,6 +494,7 @@ public function testDemoJsonResponsePost(string $path, array $postData): void
488494
*
489495
* @slowThreshold 1500
490496
*/
497+
#[DataProvider('provideDemoCallbackErrorCases')]
491498
public function testDemoCallbackError(string $path, string $expectedExceptionMessage, array $options = []): void
492499
{
493500
if (static::class === self::class) {

tests/ListerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Atk4\Ui\HtmlTemplate;
1010
use Atk4\Ui\Lister;
1111
use Atk4\Ui\View;
12+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
1213

1314
class ListerTest extends TestCase
1415
{
@@ -17,6 +18,7 @@ class ListerTest extends TestCase
1718
/**
1819
* @doesNotPerformAssertions
1920
*/
21+
#[DoesNotPerformAssertions]
2022
public function testListerRender(): void
2123
{
2224
$view = new View();

tests/PaginatorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Ui\Paginator;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910

1011
class PaginatorTest extends TestCase
1112
{
@@ -34,6 +35,7 @@ public static function providePaginatorCases(): iterable
3435
/**
3536
* @dataProvider providePaginatorCases
3637
*/
38+
#[DataProvider('providePaginatorCases')]
3739
public function testPaginator(int $page, int $range, int $total, array $expected): void
3840
{
3941
$paginator = new Paginator(['page' => $page, 'range' => $range, 'total' => $total]);

tests/PersistenceUiTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Atk4\Core\Phpunit\TestCase;
88
use Atk4\Data\Field;
99
use Atk4\Ui\Persistence\Ui as UiPersistence;
10+
use PHPUnit\Framework\Attributes\DataProvider;
1011

1112
class PersistenceUiTest extends TestCase
1213
{
@@ -16,6 +17,8 @@ class PersistenceUiTest extends TestCase
1617
* @dataProvider provideTypecastBidirectionalCases
1718
* @dataProvider provideTypecastLoadOnlyCases
1819
*/
20+
#[DataProvider('provideTypecastBidirectionalCases')]
21+
#[DataProvider('provideTypecastLoadOnlyCases')]
1922
public function testTypecast(array $persistenceSeed, array $fieldSeed, $phpValue, ?string $uiValue, bool $isUiValueNormalized = true): void
2023
{
2124
$p = (new UiPersistence())->setDefaults($persistenceSeed);
@@ -203,6 +206,7 @@ public static function provideTypecastLoadOnlyCases(): iterable
203206
*
204207
* @dataProvider provideAttributeTypecastCases
205208
*/
209+
#[DataProvider('provideAttributeTypecastCases')]
206210
public function testAttributeTypecast(array $fieldSeed, $phpValue, ?string $uiValue): void
207211
{
208212
$p = new UiPersistence();

0 commit comments

Comments
 (0)