From ab87a9cae88cdee83d71242020036fab43cc7cf2 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 26 Jul 2024 20:39:52 +0800 Subject: [PATCH 1/2] Update phpunit to `^10.5.16 || ^11.2` --- admin/framework/composer.json | 2 +- composer.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/framework/composer.json b/admin/framework/composer.json index d46c7490ec56..79fc5c282e50 100644 --- a/admin/framework/composer.json +++ b/admin/framework/composer.json @@ -23,7 +23,7 @@ "kint-php/kint": "^5.0.4", "mikey179/vfsstream": "^1.6", "nexusphp/cs-config": "^3.6", - "phpunit/phpunit": "^10.5.16", + "phpunit/phpunit": "^10.5.16 || ^11.2", "predis/predis": "^1.1 || ^2.0" }, "suggest": { diff --git a/composer.json b/composer.json index 6915af74aa8f..ae8cd107d363 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,8 @@ "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^1.11", "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpcov": "^9.0.2", - "phpunit/phpunit": "^10.5.16", + "phpunit/phpcov": "^9.0.2 || ^10.0", + "phpunit/phpunit": "^10.5.16 || ^11.2", "predis/predis": "^1.1 || ^2.0", "rector/rector": "1.2.2" }, From e33e6f22d32f26acc184d6cdd45b0380910e110d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 26 Jul 2024 20:51:10 +0800 Subject: [PATCH 2/2] Fix phpunit errors --- tests/system/Autoloader/AutoloaderTest.php | 6 +-- tests/system/CodeIgniterTest.php | 6 +-- tests/system/Commands/GenerateKeyTest.php | 6 +-- tests/system/CommonFunctionsSendTest.php | 6 +-- tests/system/CommonFunctionsTest.php | 51 ++++--------------- tests/system/Config/BaseConfigTest.php | 6 +-- tests/system/Config/DotEnvTest.php | 6 +-- tests/system/Config/ServicesTest.php | 6 +-- tests/system/Events/EventsTest.php | 6 +-- tests/system/Filters/HoneypotTest.php | 6 +-- .../system/HTTP/ContentSecurityPolicyTest.php | 6 +-- tests/system/HTTP/DownloadResponseTest.php | 6 +-- tests/system/HTTP/IncomingRequestTest.php | 6 +-- tests/system/HTTP/RedirectResponseTest.php | 6 +-- tests/system/HTTP/ResponseSendTest.php | 16 ++---- tests/system/Helpers/FormHelperTest.php | 6 +-- .../system/Helpers/URLHelper/MiscUrlTest.php | 10 +--- .../system/RESTful/ResourceControllerTest.php | 6 +-- .../system/RESTful/ResourcePresenterTest.php | 6 +-- .../SecurityCSRFSessionRandomizeTokenTest.php | 5 +- .../Security/SecurityCSRFSessionTest.php | 6 +-- tests/system/Session/SessionTest.php | 6 +-- tests/system/Test/ControllerTestTraitTest.php | 6 +-- tests/system/Test/TestCaseEmissionsTest.php | 11 ++-- tests/system/View/ParserPluginTest.php | 6 +-- 25 files changed, 60 insertions(+), 153 deletions(-) diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index 04dfe04e991f..8529d79dc118 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -25,6 +25,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use RuntimeException; use UnnamespacedClass; @@ -394,12 +395,9 @@ public function testAutoloaderLoadsNonClassFiles(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testLoadHelpers(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $config = new Autoload(); $config->helpers[] = 'form'; diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index a550e098e9b0..d87d0d8661ba 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -34,6 +34,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use Tests\Support\Filters\Customfilter; use Tests\Support\Filters\RedirectFilter; @@ -48,15 +49,12 @@ final class CodeIgniterTest extends CIUnitTestCase private CodeIgniter $codeigniter; protected $routes; + #[WithoutErrorHandler] protected function setUp(): void { parent::setUp(); $this->resetServices(); - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $this->codeigniter = new MockCodeIgniter(new App()); diff --git a/tests/system/Commands/GenerateKeyTest.php b/tests/system/Commands/GenerateKeyTest.php index 289a294f5d0c..40df8d1477c3 100644 --- a/tests/system/Commands/GenerateKeyTest.php +++ b/tests/system/Commands/GenerateKeyTest.php @@ -19,6 +19,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; /** * @internal @@ -31,6 +32,7 @@ final class GenerateKeyTest extends CIUnitTestCase private string $envPath; private string $backupEnvPath; + #[WithoutErrorHandler] protected function setUp(): void { parent::setUp(); @@ -43,10 +45,6 @@ protected function setUp(): void } $this->resetEnvironment(); - - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); } protected function tearDown(): void diff --git a/tests/system/CommonFunctionsSendTest.php b/tests/system/CommonFunctionsSendTest.php index 46871c6284df..e1f3f9dff961 100644 --- a/tests/system/CommonFunctionsSendTest.php +++ b/tests/system/CommonFunctionsSendTest.php @@ -17,6 +17,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; /** * @internal @@ -24,15 +25,12 @@ #[Group('SeparateProcess')] final class CommonFunctionsSendTest extends CIUnitTestCase { + #[WithoutErrorHandler] protected function setUp(): void { parent::setUp(); unset($_ENV['foo'], $_SERVER['foo']); - - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); } /** diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index fbbece86ddd1..faa96e1fea4e 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -46,6 +46,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use RuntimeException; use stdClass; use Tests\Support\Models\JobModel; @@ -274,12 +275,9 @@ public function testEscapeRecursiveArrayRaw(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testSessionInstance(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->injectSessionMock(); $this->assertInstanceOf(Session::class, session()); @@ -287,12 +285,9 @@ public function testSessionInstance(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testSessionVariable(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->injectSessionMock(); $_SESSION['notbogus'] = 'Hi there'; @@ -302,12 +297,9 @@ public function testSessionVariable(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testSessionVariableNotThere(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->injectSessionMock(); $_SESSION['bogus'] = 'Hi there'; @@ -428,12 +420,9 @@ public function testModelExistsAbsoluteClassname(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testOldInput(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->injectSessionMock(); // setup from RedirectResponseTest... $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -465,12 +454,9 @@ public function testOldInput(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testOldInputSerializeData(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->injectSessionMock(); // setup from RedirectResponseTest... $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -503,12 +489,9 @@ public function testOldInputSerializeData(): void */ #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testOldInputArray(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->injectSessionMock(); // setup from RedirectResponseTest... $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -622,12 +605,9 @@ public function testRedirectResponseCookies1(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testTrace(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - ob_start(); trace(); $content = ob_get_clean(); @@ -647,12 +627,9 @@ public function testViewNotSaveData(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testForceHttpsNullRequestAndResponse(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->assertNull(Services::response()->header('Location')); Services::response()->setCookie('force', 'cookie'); @@ -763,12 +740,9 @@ public function testDWithCSP(): void #[PreserveGlobalState(false)] #[RunInSeparateProcess] + #[WithoutErrorHandler] public function testTraceWithCSP(): void { - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - restore_error_handler(); - $this->resetServices(); /** @var App $config */ @@ -780,11 +754,6 @@ public function testTraceWithCSP(): void Kint::$cli_detection = false; - // Workaround for errors on PHPUnit 10 and PHP 8.3. - // See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619 - // `$app->initialize()` sets error handler. - restore_error_handler(); - $this->expectOutputRegex('/