From a42569531c71105fef1b847736db44cb291e7a86 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 12 Dec 2018 22:36:12 -0800 Subject: [PATCH] Get tests passing against 4.x --- src/Cache/Engine/DebugEngine.php | 62 +++++++++---------- src/Controller/ToolbarController.php | 2 +- .../TestCase/Cache/Engine/DebugEngineTest.php | 32 +++++----- .../Controller/MailPreviewControllerTest.php | 14 ++--- .../Controller/PanelsControllerTest.php | 6 +- .../Controller/RequestsControllerTest.php | 4 +- .../Controller/ToolbarControllerTest.php | 4 +- tests/test_app/Form/TestForm.php | 4 +- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/Cache/Engine/DebugEngine.php b/src/Cache/Engine/DebugEngine.php index cf68c2d30..03fe9cd3c 100644 --- a/src/Cache/Engine/DebugEngine.php +++ b/src/Cache/Engine/DebugEngine.php @@ -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, ]; @@ -116,12 +116,12 @@ 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; } @@ -129,12 +129,12 @@ public function write(string $key, $value): bool /** * {@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; } @@ -142,12 +142,12 @@ public function writeMany(array $data): array /** * {@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'; @@ -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; } @@ -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); @@ -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); @@ -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); @@ -212,12 +212,12 @@ 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; } @@ -225,11 +225,11 @@ public function deleteMany(array $data): array /** * {@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; diff --git a/src/Controller/ToolbarController.php b/src/Controller/ToolbarController.php index bb6fb09a8..4daf141a1 100644 --- a/src/Controller/ToolbarController.php +++ b/src/Controller/ToolbarController.php @@ -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, diff --git a/tests/TestCase/Cache/Engine/DebugEngineTest.php b/tests/TestCase/Cache/Engine/DebugEngineTest.php index 6bf5a04ca..08f15143a 100644 --- a/tests/TestCase/Cache/Engine/DebugEngineTest.php +++ b/tests/TestCase/Cache/Engine/DebugEngineTest.php @@ -87,9 +87,9 @@ 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)) @@ -97,16 +97,16 @@ public function testProxyMethodsTracksMetrics() $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']); } /** @@ -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); } diff --git a/tests/TestCase/Controller/MailPreviewControllerTest.php b/tests/TestCase/Controller/MailPreviewControllerTest.php index 75f84a5bf..c79022d1f 100644 --- a/tests/TestCase/Controller/MailPreviewControllerTest.php +++ b/tests/TestCase/Controller/MailPreviewControllerTest.php @@ -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']); @@ -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'); @@ -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.'); @@ -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');"); } @@ -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); } @@ -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('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('

Hi

'); } diff --git a/tests/TestCase/Controller/PanelsControllerTest.php b/tests/TestCase/Controller/PanelsControllerTest.php index 5f7af278e..6d6b794c9 100644 --- a/tests/TestCase/Controller/PanelsControllerTest.php +++ b/tests/TestCase/Controller/PanelsControllerTest.php @@ -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'); @@ -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'); @@ -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'); } diff --git a/tests/TestCase/Controller/RequestsControllerTest.php b/tests/TestCase/Controller/RequestsControllerTest.php index 07041dbe4..a7b53c9e4 100644 --- a/tests/TestCase/Controller/RequestsControllerTest.php +++ b/tests/TestCase/Controller/RequestsControllerTest.php @@ -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'); @@ -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(); } diff --git a/tests/TestCase/Controller/ToolbarControllerTest.php b/tests/TestCase/Controller/ToolbarControllerTest.php index 5ad6a3f4d..c2b2bbe2a 100644 --- a/tests/TestCase/Controller/ToolbarControllerTest.php +++ b/tests/TestCase/Controller/ToolbarControllerTest.php @@ -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()); } @@ -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'); } diff --git a/tests/test_app/Form/TestForm.php b/tests/test_app/Form/TestForm.php index 718d05633..146461ff4 100644 --- a/tests/test_app/Form/TestForm.php +++ b/tests/test_app/Form/TestForm.php @@ -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'); } @@ -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; }