diff --git a/demos/_unit-test/fatal-error.php b/demos/_unit-test/fatal-error.php index e60d7214f4..cd157ed516 100644 --- a/demos/_unit-test/fatal-error.php +++ b/demos/_unit-test/fatal-error.php @@ -11,14 +11,10 @@ $runOnShutdownFx = static function (\Closure $fx) use ($app) { // relies on https://github.com/atk4/ui/blob/5.0.0/src/App.php#L1108 - $app->onHook(App::HOOK_BEFORE_RENDER, static function () use (&$fx) { - if ($fx !== null) { - try { - $fx(); - } finally { - $fx = null; - } - } + $hookIndex = $app->onHook(App::HOOK_BEFORE_RENDER, static function () use ($app, &$hookIndex, $fx) { + $app->removeHook(App::HOOK_BEFORE_RENDER, $hookIndex, true); + + $fx(); }); }; diff --git a/src/HtmlTemplate/Value.php b/src/HtmlTemplate/Value.php index 3404552fa8..b930952412 100644 --- a/src/HtmlTemplate/Value.php +++ b/src/HtmlTemplate/Value.php @@ -25,7 +25,7 @@ private function encodeValueToHtml(string $value): string */ public function set(string $value): self { - if (\PHP_MAJOR_VERSION === 7 || (\PHP_MAJOR_VERSION === 8 && \PHP_MAJOR_VERSION <= 1) // @phpstan-ignore-line + if (\PHP_VERSION_ID < 80200 ? !preg_match('~~u', $value) // much faster in PHP 8.1 and lower : !mb_check_encoding($value, 'UTF-8') ) { diff --git a/tests/AppTest.php b/tests/AppTest.php index b0912fb6de..ef29b10f6c 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -9,6 +9,7 @@ use Atk4\Ui\Exception\LateOutputError; use Atk4\Ui\HtmlTemplate; use Nyholm\Psr7\Factory\Psr17Factory; +use PHPUnit\Framework\Attributes\DataProvider; class AppTest extends TestCase { @@ -186,6 +187,7 @@ public static function provideUrlCases(): iterable * @param array<0|string, string|int|false> $page * @param array $extraRequestUrlArgs */ + #[DataProvider('provideUrlCases')] public function testUrl(string $requestUrl, array $appStickyGetArguments, array $page, array $extraRequestUrlArgs, string $expectedUrl): void { $request = (new Psr17Factory())->createServerRequest('GET', $requestUrl); diff --git a/tests/ButtonTest.php b/tests/ButtonTest.php index 3c4f3cffd4..0bf5cca488 100644 --- a/tests/ButtonTest.php +++ b/tests/ButtonTest.php @@ -6,6 +6,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Ui\Button; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; class ButtonTest extends TestCase { @@ -14,6 +15,7 @@ class ButtonTest extends TestCase /** * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testButtonIcon(): void { $button = new Button(['Load', 'icon' => 'pause']); diff --git a/tests/DemosHttpNoExitTest.php b/tests/DemosHttpNoExitTest.php index 5059d613a0..b569a8084e 100644 --- a/tests/DemosHttpNoExitTest.php +++ b/tests/DemosHttpNoExitTest.php @@ -4,11 +4,14 @@ namespace Atk4\Ui\Tests; +use PHPUnit\Framework\Attributes\Group; + /** * Same as DemosHttpTest, only App::callExit is set to false. * * @group demos_http */ +#[Group('demos_http')] class DemosHttpNoExitTest extends DemosHttpTest { /** @var bool set the app->callExit in demo */ diff --git a/tests/DemosHttpTest.php b/tests/DemosHttpTest.php index 738f07852d..9cb13dc52c 100644 --- a/tests/DemosHttpTest.php +++ b/tests/DemosHttpTest.php @@ -8,6 +8,8 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Psr7\LazyOpenStream; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use Symfony\Component\Process\Process; /** @@ -15,6 +17,7 @@ * * @group demos_http */ +#[Group('demos_http')] class DemosHttpTest extends DemosTest { /** @var Process|null */ @@ -158,6 +161,7 @@ public static function provideDemoCallbackErrorCases(): iterable /** * @dataProvider provideDemoLateOutputErrorCases */ + #[DataProvider('provideDemoLateOutputErrorCases')] public function testDemoLateOutputError(string $urlTrigger, string $expectedOutput): void { $path = '_unit-test/late-output-error.php?' . Callback::URL_QUERY_TRIGGER_PREFIX . $urlTrigger . '=ajax&' diff --git a/tests/DemosTest.php b/tests/DemosTest.php index 6e62b71e55..afdb282cbf 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -17,6 +17,7 @@ use GuzzleHttp\Exception\ServerException; use GuzzleHttp\Promise\FulfilledPromise; use GuzzleHttp\Psr7\Request; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -290,6 +291,7 @@ public static function provideDemosStatusAndHtmlResponseCases(): iterable /** * @dataProvider provideDemosStatusAndHtmlResponseCases */ + #[DataProvider('provideDemosStatusAndHtmlResponseCases')] public function testDemosStatusAndHtmlResponse(string $path): void { $response = $this->getResponseFromRequest($path); @@ -322,6 +324,7 @@ public static function provideDemoGetCases(): iterable /** * @dataProvider provideDemoGetCases */ + #[DataProvider('provideDemoGetCases')] public function testDemoGet(string $path): void { $response = $this->getResponseFromRequest($path); @@ -398,6 +401,7 @@ public static function provideDemoJsonResponseCases(): iterable * * @dataProvider provideDemoJsonResponseCases */ + #[DataProvider('provideDemoJsonResponseCases')] public function testDemoJsonResponse(string $path, ?string $expectedExceptionMessage = null): void { if (static::class === self::class) { @@ -436,6 +440,7 @@ public static function provideDemoSseResponseCases(): iterable * * @dataProvider provideDemoSseResponseCases */ + #[DataProvider('provideDemoSseResponseCases')] public function testDemoSseResponse(string $path): void { // 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 /** * @dataProvider provideDemoJsonResponsePostCases */ + #[DataProvider('provideDemoJsonResponsePostCases')] public function testDemoJsonResponsePost(string $path, array $postData): void { $response = $this->getResponseFromRequest($path, ['form_params' => $postData]); @@ -488,6 +494,7 @@ public function testDemoJsonResponsePost(string $path, array $postData): void * * @slowThreshold 1500 */ + #[DataProvider('provideDemoCallbackErrorCases')] public function testDemoCallbackError(string $path, string $expectedExceptionMessage, array $options = []): void { if (static::class === self::class) { diff --git a/tests/ListerTest.php b/tests/ListerTest.php index 554bcbb916..6d91156e9f 100644 --- a/tests/ListerTest.php +++ b/tests/ListerTest.php @@ -9,6 +9,7 @@ use Atk4\Ui\HtmlTemplate; use Atk4\Ui\Lister; use Atk4\Ui\View; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; class ListerTest extends TestCase { @@ -17,6 +18,7 @@ class ListerTest extends TestCase /** * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testListerRender(): void { $view = new View(); diff --git a/tests/PaginatorTest.php b/tests/PaginatorTest.php index 7ddb27369c..b596fc0e19 100644 --- a/tests/PaginatorTest.php +++ b/tests/PaginatorTest.php @@ -6,6 +6,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Ui\Paginator; +use PHPUnit\Framework\Attributes\DataProvider; class PaginatorTest extends TestCase { @@ -34,6 +35,7 @@ public static function providePaginatorCases(): iterable /** * @dataProvider providePaginatorCases */ + #[DataProvider('providePaginatorCases')] public function testPaginator(int $page, int $range, int $total, array $expected): void { $paginator = new Paginator(['page' => $page, 'range' => $range, 'total' => $total]); diff --git a/tests/PersistenceUiTest.php b/tests/PersistenceUiTest.php index 76a25f951d..8f4c10baab 100644 --- a/tests/PersistenceUiTest.php +++ b/tests/PersistenceUiTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Field; use Atk4\Ui\Persistence\Ui as UiPersistence; +use PHPUnit\Framework\Attributes\DataProvider; class PersistenceUiTest extends TestCase { @@ -16,6 +17,8 @@ class PersistenceUiTest extends TestCase * @dataProvider provideTypecastBidirectionalCases * @dataProvider provideTypecastLoadOnlyCases */ + #[DataProvider('provideTypecastBidirectionalCases')] + #[DataProvider('provideTypecastLoadOnlyCases')] public function testTypecast(array $persistenceSeed, array $fieldSeed, $phpValue, ?string $uiValue, bool $isUiValueNormalized = true): void { $p = (new UiPersistence())->setDefaults($persistenceSeed); @@ -203,6 +206,7 @@ public static function provideTypecastLoadOnlyCases(): iterable * * @dataProvider provideAttributeTypecastCases */ + #[DataProvider('provideAttributeTypecastCases')] public function testAttributeTypecast(array $fieldSeed, $phpValue, ?string $uiValue): void { $p = new UiPersistence(); diff --git a/tests/SessionTraitTest.php b/tests/SessionTraitTest.php index 0c3cc5aa78..688f7ebd25 100644 --- a/tests/SessionTraitTest.php +++ b/tests/SessionTraitTest.php @@ -10,12 +10,16 @@ use Atk4\Ui\App; use Atk4\Ui\Exception; use Atk4\Ui\SessionTrait; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; /** * @group require_session * * @runTestsInSeparateProcesses */ +#[Group('require_session')] +#[RunTestsInSeparateProcesses] class SessionTraitTest extends TestCase { use CreateAppTrait; diff --git a/tests/TableTest.php b/tests/TableTest.php index b10c0eb0db..c999061fce 100644 --- a/tests/TableTest.php +++ b/tests/TableTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Ui\Exception; use Atk4\Ui\Table; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; class TableTest extends TestCase { @@ -15,6 +16,7 @@ class TableTest extends TestCase /** * @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testAddColumnWithoutModel(): void { $table = new Table(); diff --git a/tests/ViewTest.php b/tests/ViewTest.php index a28b0e3e3d..5fc62b7476 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -18,6 +18,7 @@ use Atk4\Ui\Popup; use Atk4\Ui\View; use Atk4\Ui\VirtualPage; +use PHPUnit\Framework\Attributes\DataProvider; class ViewTest extends TestCase { @@ -146,6 +147,7 @@ public function testSetException(): void * * @dataProvider provideSetNotClosureErrorCases */ + #[DataProvider('provideSetNotClosureErrorCases')] public function testSetNotClosureError(string $class): void { $v = new $class();