From 64ad006efa4b54dfb7b8d986387425f960ff6eb9 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 29 May 2015 20:28:11 +0530 Subject: [PATCH] Rename SessionStorageInterface methods. Makes them consistent with names used by Cache and Session classes. --- src/Auth/Storage/MemoryStorage.php | 6 ++--- src/Auth/Storage/SessionStorage.php | 12 +++++----- src/Auth/Storage/StorageInterface.php | 12 +++++----- src/Controller/Component/AuthComponent.php | 8 +++---- .../Auth/Storage/SessionStorageTest.php | 24 +++++++++---------- .../Component/AuthComponentTest.php | 10 ++++---- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/Auth/Storage/MemoryStorage.php b/src/Auth/Storage/MemoryStorage.php index 3bd3f4b8fb0..3c4a81c71ac 100644 --- a/src/Auth/Storage/MemoryStorage.php +++ b/src/Auth/Storage/MemoryStorage.php @@ -32,7 +32,7 @@ class MemoryStorage implements StorageInterface /** * {@inheritDoc} */ - public function get() + public function read() { return $this->_user; } @@ -40,7 +40,7 @@ public function get() /** * {@inheritDoc} */ - public function set(array $user) + public function write(array $user) { $this->_user = $user; } @@ -48,7 +48,7 @@ public function set(array $user) /** * {@inheritDoc} */ - public function remove() + public function delete() { $this->_user = null; } diff --git a/src/Auth/Storage/SessionStorage.php b/src/Auth/Storage/SessionStorage.php index 87d4e5fd779..a4aaed3de1e 100644 --- a/src/Auth/Storage/SessionStorage.php +++ b/src/Auth/Storage/SessionStorage.php @@ -64,11 +64,11 @@ public function __construct(Request $request, array $config = []) } /** - * Get user record from session. + * Read user record from session. * * @return array|null User record if available else null. */ - public function get() + public function read() { if ($this->_user !== null) { return $this->_user ?: null; @@ -79,14 +79,14 @@ public function get() } /** - * Set user record to session. + * Write user record to session. * * The session id is also renewed to help mitigate issues with session replays. * * @param array $user User record. * @return void */ - public function set(array $user) + public function write(array $user) { $this->_user = $user; @@ -95,13 +95,13 @@ public function set(array $user) } /** - * Remove user record from session. + * Delete user record from session. * * The session id is also renewed to help mitigate issues with session replays. * * @return void */ - public function remove() + public function delete() { $this->_user = false; diff --git a/src/Auth/Storage/StorageInterface.php b/src/Auth/Storage/StorageInterface.php index 469698eb1cc..8a199b26f91 100644 --- a/src/Auth/Storage/StorageInterface.php +++ b/src/Auth/Storage/StorageInterface.php @@ -21,24 +21,24 @@ interface StorageInterface { /** - * Get user record. + * Read user record. * * @return array|null */ - public function get(); + public function read(); /** - * Set user record. + * Write user record. * * @param array $user User record. * @return void */ - public function set(array $user); + public function write(array $user); /** - * Remove user record. + * Delete user record. * * @return void */ - public function remove(); + public function delete(); } diff --git a/src/Controller/Component/AuthComponent.php b/src/Controller/Component/AuthComponent.php index 7781c0482bb..7f72ffd1632 100644 --- a/src/Controller/Component/AuthComponent.php +++ b/src/Controller/Component/AuthComponent.php @@ -600,7 +600,7 @@ public function deny($actions = null) */ public function setUser(array $user) { - $this->storage()->set($user); + $this->storage()->write($user); } /** @@ -621,7 +621,7 @@ public function logout() $user = (array)$this->user(); $this->dispatchEvent('Auth.logout', [$user]); $this->session->delete('Auth.redirect'); - $this->storage()->remove(); + $this->storage()->delete(); return Router::normalize($this->_config['logoutRedirect']); } @@ -634,7 +634,7 @@ public function logout() */ public function user($key = null) { - $user = $this->storage()->get(); + $user = $this->storage()->read(); if (!$user) { return; } @@ -668,7 +668,7 @@ protected function _getUser() foreach ($this->_authenticateObjects as $auth) { $result = $auth->getUser($this->request); if (!empty($result) && is_array($result)) { - $this->storage()->set($result); + $this->storage()->write($result); return true; } } diff --git a/tests/TestCase/Auth/Storage/SessionStorageTest.php b/tests/TestCase/Auth/Storage/SessionStorageTest.php index e90b50f75ba..bcb001e79c1 100644 --- a/tests/TestCase/Auth/Storage/SessionStorageTest.php +++ b/tests/TestCase/Auth/Storage/SessionStorageTest.php @@ -41,63 +41,63 @@ public function setUp() } /** - * Test set + * Test write * * @return void */ - public function testSet() + public function testWrite() { $this->session->expects($this->once()) ->method('write') ->with('Auth.AuthUser', $this->user) ->will($this->returnValue(true)); - $this->storage->set($this->user); + $this->storage->write($this->user); } /** - * Test get + * Test read * * @return void */ - public function testGet() + public function testRead() { $this->session->expects($this->once()) ->method('read') ->with('Auth.AuthUser') ->will($this->returnValue($this->user)); - $result = $this->storage->get(); + $result = $this->storage->read(); $this->assertSame($this->user, $result); } /** - * Test get from local var + * Test read from local var * * @return void */ public function testGetFromLocalVar() { - $this->storage->set($this->user); + $this->storage->write($this->user); $this->session->expects($this->never()) ->method('read'); - $result = $this->storage->get(); + $result = $this->storage->read(); $this->assertSame($this->user, $result); } /** - * Test remove + * Test delete * * @return void */ - public function testRemove() + public function testDelete() { $this->session->expects($this->once()) ->method('delete') ->with('Auth.AuthUser'); - $this->storage->remove(); + $this->storage->delete(); } } diff --git a/tests/TestCase/Controller/Component/AuthComponentTest.php b/tests/TestCase/Controller/Component/AuthComponentTest.php index 5d1b270459b..ca43926e2da 100644 --- a/tests/TestCase/Controller/Component/AuthComponentTest.php +++ b/tests/TestCase/Controller/Component/AuthComponentTest.php @@ -183,7 +183,7 @@ public function testRedirectVarClearing() $this->Auth->startup($event); $this->assertEquals('/auth_test/add', $this->Auth->session->read('Auth.redirect')); - $this->Auth->storage()->set(['username' => 'admad']); + $this->Auth->storage()->write(['username' => 'admad']); $this->Auth->startup($event, $this->Controller); $this->assertNull($this->Auth->session->read('Auth.redirect')); } @@ -199,14 +199,14 @@ public function testAuthorizeFalse() $event = new Event('Controller.startup', $this->Controller); $Users = TableRegistry::get('Users'); $user = $Users->find('all')->hydrate(false)->first(); - $this->Controller->Auth->storage()->set($user); + $this->Controller->Auth->storage()->write($user); $this->Controller->Auth->config('userModel', 'Users'); $this->Controller->Auth->config('authorize', false); $this->Controller->request->addParams(Router::parse('auth_test/add')); $result = $this->Controller->Auth->startup($event); $this->assertNull($result); - $this->Controller->Auth->storage()->remove(); + $this->Controller->Auth->storage()->delete(); $result = $this->Controller->Auth->startup($event); $this->assertTrue($event->isStopped()); $this->assertInstanceOf('Cake\Network\Response', $result); @@ -1116,7 +1116,7 @@ public function testSetUser() { $storage = $this->getMock( 'Cake\Auth\Storage\SessionStorage', - ['set'], + ['write'], [$this->Auth->request] ); $this->Auth->storage($storage); @@ -1124,7 +1124,7 @@ public function testSetUser() $user = ['username' => 'mark', 'role' => 'admin']; $storage->expects($this->once()) - ->method('set') + ->method('write') ->with($user); $this->Auth->setUser($user);