Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/Cache/Engine/DebugEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class DebugEngine extends CacheEngine
* @var mixed
*/
protected $_metrics = [
'write' => 0,
'set' => 0,
'delete' => 0,
'read' => 0,
'get' => 0,
'hit' => 0,
'miss' => 0,
];
Expand Down Expand Up @@ -116,38 +116,38 @@ protected function _track($metric)
/**
* {@inheritDoc}
*/
public function write(string $key, $value): bool
public function set($key, $value, $ttl = null)
{
$this->_track('write');
DebugTimer::start('Cache.write ' . $key);
$result = $this->_engine->write($key, $value);
DebugTimer::stop('Cache.write ' . $key);
$this->_track('set');
DebugTimer::start('Cache.set ' . $key);
$result = $this->_engine->set($key, $value, $ttl);
DebugTimer::stop('Cache.set ' . $key);

return $result;
}

/**
* {@inheritDoc}
*/
public function writeMany(array $data): array
public function setMultiple($data, $ttl = null): bool
{
$this->_track('write');
DebugTimer::start('Cache.writeMany');
$result = $this->_engine->writeMany($data);
DebugTimer::stop('Cache.writeMany');
$this->_track('set');
DebugTimer::start('Cache.setMultiple');
$result = $this->_engine->setMultiple($data);
DebugTimer::stop('Cache.setMultiple');

return $result;
}

/**
* {@inheritDoc}
*/
public function read(string $key)
public function get($key, $default = null)
{
$this->_track('read');
DebugTimer::start('Cache.read ' . $key);
$result = $this->_engine->read($key);
DebugTimer::stop('Cache.read ' . $key);
$this->_track('get');
DebugTimer::start('Cache.get ' . $key);
$result = $this->_engine->get($key, $default);
DebugTimer::stop('Cache.get ' . $key);
$metric = 'hit';
if ($result === false) {
$metric = 'miss';
Expand All @@ -160,12 +160,12 @@ public function read(string $key)
/**
* {@inheritDoc}
*/
public function readMany(array $data): array
public function getMultiple($keys, $default = null): array
{
$this->_track('read');
DebugTimer::start('Cache.readMany');
$result = $this->_engine->readMany($data);
DebugTimer::stop('Cache.readMany');
$this->_track('get');
DebugTimer::start('Cache.getMultiple');
$result = $this->_engine->getMultiple($keys);
DebugTimer::stop('Cache.getMultiple');

return $result;
}
Expand All @@ -175,7 +175,7 @@ public function readMany(array $data): array
*/
public function increment(string $key, int $offset = 1)
{
$this->_track('write');
$this->_track('set');
DebugTimer::start('Cache.increment ' . $key);
$result = $this->_engine->increment($key, $offset);
DebugTimer::stop('Cache.increment ' . $key);
Expand All @@ -188,7 +188,7 @@ public function increment(string $key, int $offset = 1)
*/
public function decrement(string $key, int $offset = 1)
{
$this->_track('write');
$this->_track('set');
DebugTimer::start('Cache.decrement ' . $key);
$result = $this->_engine->decrement($key, $offset);
DebugTimer::stop('Cache.decrement ' . $key);
Expand All @@ -199,7 +199,7 @@ public function decrement(string $key, int $offset = 1)
/**
* {@inheritDoc}
*/
public function delete(string $key): bool
public function delete($key)
{
$this->_track('delete');
DebugTimer::start('Cache.delete ' . $key);
Expand All @@ -212,24 +212,24 @@ public function delete(string $key): bool
/**
* {@inheritDoc}
*/
public function deleteMany(array $data): array
public function deleteMultiple($data): bool
{
$this->_track('delete');
DebugTimer::start('Cache.deleteMany');
$result = $this->_engine->deleteMany($data);
DebugTimer::stop('Cache.deleteMany');
DebugTimer::start('Cache.deleteMultiple');
$result = $this->_engine->deleteMultiple($data);
DebugTimer::stop('Cache.deleteMultiple');

return $result;
}

/**
* {@inheritDoc}
*/
public function clear(bool $check): bool
public function clear()
{
$this->_track('delete');
DebugTimer::start('Cache.clear');
$result = $this->_engine->clear($check);
$result = $this->_engine->clear();
DebugTimer::stop('Cache.clear');

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ToolbarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function clearCache()
if (!$this->request->getData('name')) {
throw new NotFoundException(__d('debug_kit', 'Invalid cache engine name.'));
}
$result = Cache::clear(false, $this->request->getData('name'));
$result = Cache::clear($this->request->getData('name'));
$this->set([
'_serialize' => ['success'],
'success' => $result,
Expand Down
32 changes: 16 additions & 16 deletions tests/TestCase/Cache/Engine/DebugEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,26 @@ public function testInitErrorOnInvalidConfig()
public function testProxyMethodsTracksMetrics()
{
$this->mock->expects($this->at(0))
->method('read');
->method('get');
$this->mock->expects($this->at(1))
->method('write');
->method('set');
$this->mock->expects($this->at(2))
->method('delete');
$this->mock->expects($this->at(3))
->method('increment');
$this->mock->expects($this->at(4))
->method('decrement');

$this->engine->read('key');
$this->engine->write('key', 'value');
$this->engine->get('key');
$this->engine->set('key', 'value');
$this->engine->delete('key');
$this->engine->increment('key');
$this->engine->decrement('key');

$result = $this->engine->metrics();
$this->assertEquals(3, $result['write']);
$this->assertEquals(3, $result['set']);
$this->assertEquals(1, $result['delete']);
$this->assertEquals(1, $result['read']);
$this->assertEquals(1, $result['get']);
}

/**
Expand All @@ -116,26 +116,26 @@ public function testProxyMethodsTracksMetrics()
*/
public function testProxyMethodsTimers()
{
$this->engine->read('key');
$this->engine->write('key', 'value');
$this->engine->get('key');
$this->engine->set('key', 'value');
$this->engine->delete('key');
$this->engine->increment('key');
$this->engine->decrement('key');
$this->engine->writeMany(['key' => 'value']);
$this->engine->readMany(['key']);
$this->engine->deleteMany(['key']);
$this->engine->setMultiple(['key' => 'value']);
$this->engine->getMultiple(['key']);
$this->engine->deleteMultiple(['key']);
$this->engine->clearGroup('group');

$result = DebugTimer::getAll();
$this->assertCount(10, $result);
$this->assertArrayHasKey('Cache.read key', $result);
$this->assertArrayHasKey('Cache.write key', $result);
$this->assertArrayHasKey('Cache.get key', $result);
$this->assertArrayHasKey('Cache.set key', $result);
$this->assertArrayHasKey('Cache.delete key', $result);
$this->assertArrayHasKey('Cache.increment key', $result);
$this->assertArrayHasKey('Cache.decrement key', $result);
$this->assertArrayHasKey('Cache.readMany', $result);
$this->assertArrayHasKey('Cache.writeMany', $result);
$this->assertArrayHasKey('Cache.deleteMany', $result);
$this->assertArrayHasKey('Cache.getMultiple', $result);
$this->assertArrayHasKey('Cache.setMultiple', $result);
$this->assertArrayHasKey('Cache.deleteMultiple', $result);
$this->assertArrayHasKey('Cache.clearGroup group', $result);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Controller/MailPreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setUp()

Router::plugin('DebugKit', function (RouteBuilder $routes) {
$routes->scope(
'/mail_preview',
'/mail-preview',
['controller' => 'MailPreview'],
function ($routes) {
$routes->connect('/sent/*', ['action' => 'sent']);
Expand All @@ -69,7 +69,7 @@ function ($routes) {
*/
public function testEmailPluginPassedToView()
{
$this->get('/debug_kit/mail_preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');
$this->get('/debug-kit/mail-preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');

$this->assertResponseOk();
$this->assertResponseContains('src="?part=text&plugin=DebugkitTestPlugin');
Expand All @@ -81,7 +81,7 @@ public function testEmailPluginPassedToView()
*/
public function testEmailPartTextContent()
{
$this->get('/debug_kit/mail_preview/preview/TestMailerPreview/test_email?part=text&plugin=DebugkitTestPlugin');
$this->get('/debug-kit/mail-preview/preview/TestMailerPreview/test_email?part=text&plugin=DebugkitTestPlugin');

$this->assertResponseOk();
$this->assertResponseContains('Testing email action.');
Expand All @@ -95,7 +95,7 @@ public function testEmailPartTextContent()
*/
public function testOnChangeJsPluginPassedToview()
{
$this->get('/debug_kit/mail_preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');
$this->get('/debug-kit/mail-preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');

$this->assertResponseContains("iframe.contentWindow.location.replace('?part=' + part_name + '&plugin=DebugkitTestPlugin');");
}
Expand All @@ -107,7 +107,7 @@ public function testOnChangeJsPluginPassedToview()
*/
public function testSentInvalidData()
{
$this->get('/debug_kit/mail_preview/sent/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/0');
$this->get('/debug-kit/mail-preview/sent/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/0');
$this->assertResponseCode(404);
}

Expand All @@ -131,7 +131,7 @@ public function testSentValidData()
$panel->content = serialize($data);
$panels->save($panel);

$this->get("/debug_kit/mail_preview/sent/{$panel->id}/0");
$this->get("/debug-kit/mail-preview/sent/{$panel->id}/0");
$this->assertResponseCode(200);
$this->assertResponseContains('test@example.com');
$this->assertResponseContains('<iframe');
Expand All @@ -157,7 +157,7 @@ public function testSentValidDataRenderPart()
$panel->content = serialize($data);
$panels->save($panel);

$this->get("/debug_kit/mail_preview/sent/{$panel->id}/0?part=html");
$this->get("/debug-kit/mail-preview/sent/{$panel->id}/0?part=html");
$this->assertResponseCode(200);
$this->assertResponseContains('<h1>Hi</h1>');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Controller/PanelsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testIndex()
]
]);

$this->get('/debug_kit/panels/index/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
$this->get('/debug-kit/panels/index/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');

$this->assertResponseOk();
$this->assertContentType('application/json');
Expand All @@ -75,7 +75,7 @@ public function testIndex()
*/
public function testView()
{
$this->get('/debug_kit/panels/view/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
$this->get('/debug-kit/panels/view/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');

$this->assertResponseOk();
$this->assertResponseContains('Request</h2>');
Expand All @@ -89,7 +89,7 @@ public function testView()
*/
public function testViewNotExists()
{
$this->get('/debug_kit/panels/view/aaaaaaaa-ffff-ffff-ffff-aaaaaaaaaaaa');
$this->get('/debug-kit/panels/view/aaaaaaaa-ffff-ffff-ffff-aaaaaaaaaaaa');
$this->assertResponseError();
$this->assertResponseContains('Error page');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Controller/RequestsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function setUp()
public function testView()
{
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
$this->get('/debug_kit/toolbar/view/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
$this->get('/debug-kit/toolbar/view/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');

$this->assertResponseOk();
$this->assertResponseContains('Request', 'Has a panel button');
Expand All @@ -70,7 +70,7 @@ public function testView()
public function testViewNotExists()
{
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
$this->get('/debug_kit/toolbar/view/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb');
$this->get('/debug-kit/toolbar/view/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb');

$this->assertResponseError();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Controller/ToolbarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setUp()
*/
public function testClearCacheNoGet()
{
$this->get('/debug_kit/toolbar/clear_cache?name=testing');
$this->get('/debug-kit/toolbar/clear_cache?name=testing');

$this->assertEquals(405, $this->_response->getStatusCode());
}
Expand All @@ -80,7 +80,7 @@ public function testClearCache()
Cache::setConfig('testing', $mock);

$this->configRequest(['headers' => ['Accept' => 'application/json']]);
$this->post('/debug_kit/toolbar/clear_cache', ['name' => 'testing']);
$this->post('/debug-kit/toolbar/clear-cache', ['name' => 'testing']);
$this->assertResponseOk();
$this->assertResponseContains('success');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app/Form/TestForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestForm extends Form
* @param \Cake\Form\Schema $schema From schema
* @return \Cake\Form\Schema
*/
protected function _buildSchema(Schema $schema)
protected function _buildSchema(Schema $schema): Schema
{
return $schema->addField('accept', 'boolean');
}
Expand Down Expand Up @@ -45,7 +45,7 @@ protected function _buildValidator(Validator $validator)
* @param array $data Form data.
* @return bool
*/
protected function _execute(array $data)
protected function _execute(array $data): bool
{
return true;
}
Expand Down