Skip to content

Commit 130f47a

Browse files
committed
test: refactor existing tests to use NativeHeadersStack mocks
1 parent ffbb779 commit 130f47a

File tree

2 files changed

+8
-77
lines changed

2 files changed

+8
-77
lines changed

tests/_support/Debug/MockNativeHeaders.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

tests/system/Debug/ToolbarTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
use CodeIgniter\HTTP\IncomingRequest;
2020
use CodeIgniter\HTTP\ResponseInterface;
2121
use CodeIgniter\Test\CIUnitTestCase;
22+
use CodeIgniter\Test\Utilities\NativeHeadersStack;
2223
use Config\Toolbar as ToolbarConfig;
2324
use PHPUnit\Framework\Attributes\BackupGlobals;
2425
use PHPUnit\Framework\Attributes\Group;
2526

26-
require_once SUPPORTPATH . 'Debug/MockNativeHeaders.php';
27+
require_once SUPPORTPATH . 'Mock/MockNativeHeaders.php';
2728

2829
/**
2930
* @internal
@@ -40,7 +41,7 @@ protected function setUp(): void
4041
{
4142
parent::setUp();
4243

43-
MockNativeHeaders::reset();
44+
NativeHeadersStack::reset();
4445

4546
Services::reset();
4647

@@ -112,7 +113,7 @@ public function testPrepareInjectsNormallyWithoutIgnoredHeader(): void
112113
public function testPrepareAbortsIfHeadersAlreadySent(): void
113114
{
114115
// Headers explicitly sent (e.g., echo before execution)
115-
MockNativeHeaders::$headersSent = true;
116+
NativeHeadersStack::setHeadersSent(true);
116117

117118
$this->request = service('incomingrequest', null, false);
118119
$this->response = service('response', null, false);
@@ -128,7 +129,7 @@ public function testPrepareAbortsIfHeadersAlreadySent(): void
128129
public function testPrepareAbortsIfNativeContentTypeIsNotHtml(): void
129130
{
130131
// A library (like Dompdf) set a PDF header directly
131-
MockNativeHeaders::$headers = ['Content-Type: application/pdf'];
132+
NativeHeadersStack::set('Content-Type: application/pdf');
132133

133134
$this->request = service('incomingrequest', null, false);
134135
$this->response = service('response', null, false);
@@ -145,10 +146,10 @@ public function testPrepareAbortsIfNativeContentTypeIsNotHtml(): void
145146
public function testPrepareAbortsIfNativeContentDispositionIsAttachment(): void
146147
{
147148
// A file download (even if it is HTML)
148-
MockNativeHeaders::$headers = [
149+
NativeHeadersStack::pushMany([
149150
'Content-Type: text/html',
150151
'Content-Disposition: attachment; filename="report.html"',
151-
];
152+
]);
152153

153154
$this->request = service('incomingrequest', null, false);
154155
$this->response = service('response', null, false);
@@ -164,7 +165,7 @@ public function testPrepareAbortsIfNativeContentDispositionIsAttachment(): void
164165
public function testPrepareWorksWithNativeHtmlHeader(): void
165166
{
166167
// Standard scenario where PHP header is text/html
167-
MockNativeHeaders::$headers = ['Content-Type: text/html; charset=UTF-8'];
168+
NativeHeadersStack::set('Content-Type: text/html; charset=UTF-8');
168169

169170
$this->request = service('incomingrequest', null, false);
170171
$this->response = service('response', null, false);

0 commit comments

Comments
 (0)