Skip to content

Commit 792e921

Browse files
committed
refactor: update test and other
1 parent d744b4d commit 792e921

File tree

5 files changed

+24
-62
lines changed

5 files changed

+24
-62
lines changed

app/Config/Toolbar.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ class Toolbar extends BaseConfig
150150
*/
151151
public array $disableOnHeaders = [
152152
'HX-Request', // HTMX partial requests
153-
'X-Unpoly-Request', // Unpoly partial requests
154-
'Turbo-Frame', // Turbo Frames
155-
'Turbo-Visit', // Turbo Drive navigation
153+
'X-Up-Version', // Unpoly partial requests
156154
];
157155
}

system/Boot.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@ public static function bootTest(Paths $paths): void
144144
static::loadDotEnv($paths);
145145
static::loadEnvironmentBootstrap($paths, false);
146146

147+
static::loadCommonFunctionsMock();
148+
147149
static::loadCommonFunctions();
148150
static::loadAutoloader();
149151
static::setExceptionHandler();
150152
static::initializeKint();
151153
static::autoloadHelpers();
152-
153-
// Global test helpers and mocks for all tests
154-
require_once ROOTPATH . 'tests/_support/MockCommon.php';
155154
}
156155

157156
/**
@@ -392,4 +391,12 @@ protected static function runCommand(Console $console): int
392391

393392
return is_int($exit) ? $exit : EXIT_SUCCESS;
394393
}
394+
395+
protected static function loadCommonFunctionsMock(): void
396+
{
397+
// Require system/Test/Mock/MockCommon.php
398+
if (is_file(SYSTEMPATH . 'Test/Mock/MockCommon.php')) {
399+
require_once SYSTEMPATH . 'Test/Mock/MockCommon.php';
400+
}
401+
}
395402
}

system/Debug/Toolbar.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,6 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
391391

392392
$config = config(ToolbarConfig::class);
393393

394-
foreach ($config->disableOnHeaders as $header) {
395-
if ($request->hasHeader($header)) {
396-
$this->isCustomAjax = true;
397-
break;
398-
}
399-
}
400-
401394
$toolbar = service('toolbar', $config);
402395
$stats = $app->getPerformanceStats();
403396
$data = $toolbar->run(
@@ -420,6 +413,14 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
420413

421414
$format = $response->getHeaderLine('content-type');
422415

416+
foreach ($config->disableOnHeaders as $header) {
417+
if ($request->hasHeader($header)) {
418+
$this->isCustomAjax = true;
419+
420+
continue;
421+
}
422+
}
423+
423424
// Non-HTML formats should not include the debugbar
424425
// then we send headers saying where to find the debug data
425426
// for this response

tests/_support/MockCommon.php

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

tests/system/Debug/ToolbarTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ final class ToolbarTest extends CIUnitTestCase
3333
private ToolbarConfig $config;
3434
private ?IncomingRequest $request = null;
3535
private ?ResponseInterface $response = null;
36+
private bool $originalIsCli;
3637

3738
protected function setUp(): void
3839
{
3940
parent::setUp();
4041
Services::reset();
41-
is_cli();
42+
43+
$this->originalIsCli = is_cli();
44+
is_cli(false);
4245

4346
$this->config = new ToolbarConfig();
4447

@@ -54,7 +57,7 @@ protected function setUp(): void
5457
protected function tearDown(): void
5558
{
5659
// Restore original is_cli state
57-
is_cli();
60+
is_cli($this->originalIsCli);
5861

5962
parent::tearDown();
6063
}

0 commit comments

Comments
 (0)