diff --git a/.github/scripts/random-tests-config.txt b/.github/scripts/random-tests-config.txt index 2435f6ea7a17..413fe10c8d89 100644 --- a/.github/scripts/random-tests-config.txt +++ b/.github/scripts/random-tests-config.txt @@ -27,7 +27,7 @@ Events Files # Filters Format -# HTTP +HTTP # Helpers Honeypot HotReloader diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 9fac71493b39..76444fbc0db5 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -39,9 +39,9 @@ class CURLRequestTest extends CIUnitTestCase protected function setUp(): void { + $this->resetServices(); parent::setUp(); - $this->resetServices(); Services::injectMock('superglobals', new Superglobals()); $this->request = $this->getRequest(); } diff --git a/tests/system/HTTP/CorsTest.php b/tests/system/HTTP/CorsTest.php index 5373959746ac..0da2bdcee55b 100644 --- a/tests/system/HTTP/CorsTest.php +++ b/tests/system/HTTP/CorsTest.php @@ -14,14 +14,22 @@ namespace CodeIgniter\HTTP; use CodeIgniter\Test\CIUnitTestCase; +use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\Group; /** * @internal */ +#[BackupGlobals(true)] #[Group('Others')] final class CorsTest extends CIUnitTestCase { + protected function setUp(): void + { + $this->resetServices(); + parent::setUp(); + } + /** * @param array{ * allowedOrigins?: list, diff --git a/tests/system/HTTP/DownloadResponseTest.php b/tests/system/HTTP/DownloadResponseTest.php index d7cfcf937612..d5fea35e380c 100644 --- a/tests/system/HTTP/DownloadResponseTest.php +++ b/tests/system/HTTP/DownloadResponseTest.php @@ -20,6 +20,7 @@ use CodeIgniter\Test\CIUnitTestCase; use DateTime; use DateTimeZone; +use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; @@ -28,6 +29,7 @@ /** * @internal */ +#[BackupGlobals(true)] #[Group('SeparateProcess')] final class DownloadResponseTest extends CIUnitTestCase { diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 2634e31a4b84..fe478105d43b 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -43,6 +43,7 @@ final class IncomingRequestTest extends CIUnitTestCase #[WithoutErrorHandler] protected function setUp(): void { + $this->resetServices(); parent::setUp(); $_ENV = $_SESSION = []; @@ -280,7 +281,7 @@ public function testSetValidLocales(): void */ public function testNegotiatesLocale(): void { - service('superglobals')->setServer('HTTP_ACCEPT_LANGUAGE', 'fr-FR); q=1.0, en; q=0.5'); + service('superglobals')->setServer('HTTP_ACCEPT_LANGUAGE', 'fr-FR; q=1.0, en; q=0.5'); $config = new App(); $config->negotiateLocale = true; @@ -295,7 +296,7 @@ public function testNegotiatesLocale(): void public function testNegotiatesLocaleOnlyBroad(): void { - service('superglobals')->setServer('HTTP_ACCEPT_LANGUAGE', 'fr); q=1.0, en; q=0.5'); + service('superglobals')->setServer('HTTP_ACCEPT_LANGUAGE', 'fr; q=1.0, en; q=0.5'); $config = new App(); $config->negotiateLocale = true; @@ -349,7 +350,7 @@ public function testNegotiatesEncoding(): void public function testNegotiatesLanguage(): void { $this->request->setHeader('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7'); - $this->assertSame('en', $this->request->negotiate('language', ['en', 'da'])); + $this->assertSame('da', $this->request->negotiate('language', ['en', 'da'])); } public function testCanGrabGetRawJSON(): void diff --git a/tests/system/HTTP/MessageTest.php b/tests/system/HTTP/MessageTest.php index 7a691af39c08..9307c3eef999 100644 --- a/tests/system/HTTP/MessageTest.php +++ b/tests/system/HTTP/MessageTest.php @@ -259,7 +259,11 @@ public function testPopulateHeadersWithoutContentType(): void $this->assertNull($this->message->header('content-type')); - putenv("CONTENT_TYPE={$originalEnv}"); + if ($originalEnv !== false) { + putenv("CONTENT_TYPE={$originalEnv}"); + } else { + putenv('CONTENT_TYPE'); + } } public function testPopulateHeadersWithoutHTTP(): void diff --git a/tests/system/HTTP/NegotiateTest.php b/tests/system/HTTP/NegotiateTest.php index e52f6f7a3201..083846c8a1a8 100644 --- a/tests/system/HTTP/NegotiateTest.php +++ b/tests/system/HTTP/NegotiateTest.php @@ -17,11 +17,13 @@ use CodeIgniter\Test\CIUnitTestCase; use Config\App; use Config\Feature; +use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\Group; /** * @internal */ +#[BackupGlobals(true)] #[Group('Others')] final class NegotiateTest extends CIUnitTestCase { @@ -30,6 +32,7 @@ final class NegotiateTest extends CIUnitTestCase protected function setUp(): void { + $this->resetServices(); parent::setUp(); $config = new App(); diff --git a/tests/system/HTTP/RedirectResponseTest.php b/tests/system/HTTP/RedirectResponseTest.php index 2ea700c03d88..b06e437fcffe 100644 --- a/tests/system/HTTP/RedirectResponseTest.php +++ b/tests/system/HTTP/RedirectResponseTest.php @@ -24,6 +24,7 @@ use Config\Modules; use Config\Routing; use Config\Services; +use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; @@ -32,6 +33,7 @@ /** * @internal */ +#[BackupGlobals(true)] #[Group('SeparateProcess')] final class RedirectResponseTest extends CIUnitTestCase { @@ -46,9 +48,8 @@ final class RedirectResponseTest extends CIUnitTestCase #[WithoutErrorHandler] protected function setUp(): void { - parent::setUp(); - $this->resetServices(); + parent::setUp(); Services::injectMock('superglobals', new Superglobals()); service('superglobals')->setServer('REQUEST_METHOD', 'GET'); diff --git a/tests/system/HTTP/ResponseTest.php b/tests/system/HTTP/ResponseTest.php index 17d1b4191134..97ab68be36c8 100644 --- a/tests/system/HTTP/ResponseTest.php +++ b/tests/system/HTTP/ResponseTest.php @@ -22,12 +22,14 @@ use Config\App; use DateTime; use DateTimeZone; +use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; /** * @internal */ +#[BackupGlobals(true)] #[Group('Others')] final class ResponseTest extends CIUnitTestCase { @@ -35,12 +37,11 @@ final class ResponseTest extends CIUnitTestCase protected function setUp(): void { - Services::injectMock('superglobals', new Superglobals()); - $this->server = service('superglobals')->getServerArray(); - + $this->resetServices(); parent::setUp(); - $this->resetServices(); + Services::injectMock('superglobals', new Superglobals()); + $this->server = service('superglobals')->getServerArray(); } protected function tearDown(): void @@ -169,6 +170,7 @@ public function testSetLink(): void Factories::injectMock('config', 'App', $config); $this->resetServices(); + Services::injectMock('superglobals', new Superglobals([], [])); $response = new Response($config); $pager = service('pager'); diff --git a/tests/system/HTTP/UserAgentTest.php b/tests/system/HTTP/UserAgentTest.php index b19e0c62dee5..cc6947d1dd50 100644 --- a/tests/system/HTTP/UserAgentTest.php +++ b/tests/system/HTTP/UserAgentTest.php @@ -14,11 +14,13 @@ namespace CodeIgniter\HTTP; use CodeIgniter\Test\CIUnitTestCase; +use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\Group; /** * @internal */ +#[BackupGlobals(true)] #[Group('Others')] final class UserAgentTest extends CIUnitTestCase { @@ -28,6 +30,7 @@ final class UserAgentTest extends CIUnitTestCase protected function setUp(): void { + $this->resetServices(); parent::setUp(); // set a baseline user agent