Skip to content

Commit

Permalink
Merge pull request #996 from cakephp/fix-build
Browse files Browse the repository at this point in the history
Fix build
  • Loading branch information
markstory committed Apr 5, 2024
2 parents 253ae96 + cedbd66 commit 5c4f60a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
7 changes: 7 additions & 0 deletions tests/TestCase/FixtureFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ protected function makePanel($request, $name = 'DebugKit.Request', $title = 'Req
'cookie' => Debugger::exportVarAsNodes([
'toolbarDisplay' => 'show',
]),
'params' => [
'plugin' => null,
'controller' => 'Tasks',
'action' => 'add',
'_ext' => null,
'pass' => [],
],
];
}
$panels = $this->getTableLocator()->get('DebugKit.Panels');
Expand Down
11 changes: 8 additions & 3 deletions tests/TestCase/Middleware/DebugKitMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ class DebugKitMiddlewareTest extends TestCase
'plugin.DebugKit.Panels',
];

protected $oldConfig;
protected ?array $oldConfig;

/**
* @var bool
*/
protected bool $restore = false;

/**
* setup
Expand All @@ -56,7 +61,7 @@ public function setUp(): void
$connection = ConnectionManager::get('test');
$this->skipIf($connection->getDriver() instanceof Sqlite, 'This test fails in CI with sqlite');
$this->oldConfig = Configure::read('DebugKit');
$this->restore = $GLOBALS['FORCE_DEBUGKIT_TOOLBAR'];
$this->restore = $GLOBALS['FORCE_DEBUGKIT_TOOLBAR'] ?? false;
$GLOBALS['FORCE_DEBUGKIT_TOOLBAR'] = true;
}

Expand Down Expand Up @@ -126,7 +131,7 @@ public function testInvokeSaveData()
$this->assertNotNull($result->panels[11]->summary);
$this->assertSame('Sql Log', $result->panels[11]->title);

$timeStamp = filectime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'main.js');
$timeStamp = filectime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'inject-iframe.js');

$expected = '<html><title>test</title><body><p>some text</p>' .
'<script id="__debug_kit_script" data-id="' . $result->id . '" ' .
Expand Down
26 changes: 18 additions & 8 deletions tests/TestCase/ToolbarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use DebugKit\Model\Entity\Request as RequestEntity;
use DebugKit\Panel\SqlLogPanel;
use DebugKit\ToolbarService;

/**
Expand All @@ -42,6 +43,11 @@ class ToolbarServiceTest extends TestCase
'plugin.DebugKit.Panels',
];

/**
* @var bool
*/
protected bool $restore = false;

/**
* @var EventManager
*/
Expand All @@ -59,7 +65,7 @@ public function setUp(): void

$connection = ConnectionManager::get('test');
$this->skipIf($connection->getDriver() instanceof Sqlite, 'Schema insertion/removal breaks SQLite');
$this->restore = $GLOBALS['FORCE_DEBUGKIT_TOOLBAR'];
$this->restore = $GLOBALS['FORCE_DEBUGKIT_TOOLBAR'] ?? false;
$GLOBALS['FORCE_DEBUGKIT_TOOLBAR'] = true;
}

Expand Down Expand Up @@ -87,7 +93,7 @@ public function testLoadPanels()

$this->assertContains('SqlLog', $bar->loadedPanels());
$this->assertGreaterThan(1, $this->events->listeners('Controller.shutdown'));
$this->assertInstanceOf('DebugKit\Panel\SqlLogPanel', $bar->panel('SqlLog'));
$this->assertInstanceOf(SqlLogPanel::class, $bar->panel('SqlLog'));
}

/**
Expand All @@ -100,7 +106,7 @@ public function testDisablePanels()
$bar = new ToolbarService($this->events, ['panels' => [
'DebugKit.SqlLog' => false,
'DebugKit.Cache' => true,
'DebugKit.Session',
'DebugKit.Session' => true,
]]);
$bar->loadPanels();

Expand Down Expand Up @@ -239,7 +245,7 @@ public function testSaveData()

$requests = $this->getTableLocator()->get('DebugKit.Requests');
$result = $requests->find()
->order(['Requests.requested_at' => 'DESC'])
->orderBy(['Requests.requested_at' => 'DESC'])
->contain('Panels')
->first();

Expand Down Expand Up @@ -305,6 +311,8 @@ public function testInjectScriptsLastBodyTag()
$bar = new ToolbarService($this->events, []);
$bar->loadPanels();
$row = $bar->saveData($request, $response);
$this->assertNotEmpty($row);
/** @var \DebugKit\Model\Entity\Request $row */
$response = $bar->injectScripts($row, $response);

$timeStamp = filemtime(Plugin::path('DebugKit') . 'webroot' . DS . 'js' . DS . 'inject-iframe.js');
Expand Down Expand Up @@ -334,7 +342,7 @@ public function testInjectScriptsFileBodies()
$row = new RequestEntity(['id' => 'abc123']);

$result = $bar->injectScripts($row, $response);
$this->assertInstanceOf('Cake\Http\Response', $result);
$this->assertInstanceOf(Response::class, $result);
$this->assertSame(file_get_contents(__FILE__), '' . $result->getBody());
$this->assertTrue($result->hasHeader('X-DEBUGKIT-ID'), 'Should have a tracking id');
}
Expand All @@ -356,7 +364,7 @@ public function testInjectScriptsStreamBodies()
$row = new RequestEntity(['id' => 'abc123']);

$result = $bar->injectScripts($row, $response);
$this->assertInstanceOf('Cake\Http\Response', $result);
$this->assertInstanceOf(Response::class, $result);
$this->assertSame('I am a teapot!', (string)$response->getBody());
}

Expand All @@ -381,6 +389,8 @@ public function testInjectScriptsNoModifyResponse()
$bar->loadPanels();

$row = $bar->saveData($request, $response);
$this->assertNotEmpty($row);
/** @var \DebugKit\Model\Entity\Request $row */
$response = $bar->injectScripts($row, $response);
$this->assertTextEquals('{"some":"json"}', (string)$response->getBody());
$this->assertTrue($response->hasHeader('X-DEBUGKIT-ID'), 'Should have a tracking id');
Expand Down Expand Up @@ -410,7 +420,7 @@ public function testIsEnabled()
* @dataProvider domainsProvider
* @return void
*/
public function testIsEnabledProductionEnv($domain, $isEnabled)
public function testIsEnabledProductionEnv(string $domain, bool $isEnabled)
{
Configure::write('debug', true);
putenv("HTTP_HOST=$domain");
Expand All @@ -421,7 +431,7 @@ public function testIsEnabledProductionEnv($domain, $isEnabled)
$this->assertTrue($bar->isEnabled(), 'When forced should always be on.');
}

public static function domainsProvider()
public static function domainsProvider(): array
{
return [
['localhost', true],
Expand Down

0 comments on commit 5c4f60a

Please sign in to comment.