From c3675b7512fe1f857b9a685826b6d1a96d4278a2 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 26 Jul 2024 20:51:10 +0800 Subject: [PATCH] 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 +-- .../system/Helpers/URLHelper/MiscUrlTest.php | 10 +--- tests/system/View/ParserPluginTest.php | 6 +-- 10 files changed, 28 insertions(+), 81 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('/