Browse Source

Rename SessionStorageInterface methods.

Makes them consistent with names used by Cache and Session classes.
ADmad 10 years ago
parent
commit
64ad006efa

+ 3 - 3
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 @@ class MemoryStorage implements StorageInterface
     /**
      * {@inheritDoc}
      */
-    public function set(array $user)
+    public function write(array $user)
     {
         $this->_user = $user;
     }
@@ -48,7 +48,7 @@ class MemoryStorage implements StorageInterface
     /**
      * {@inheritDoc}
      */
-    public function remove()
+    public function delete()
     {
         $this->_user = null;
     }

+ 6 - 6
src/Auth/Storage/SessionStorage.php

@@ -64,11 +64,11 @@ class SessionStorage implements StorageInterface
     }
 
     /**
-     * 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 @@ class SessionStorage implements StorageInterface
     }
 
     /**
-     * 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 @@ class SessionStorage implements StorageInterface
     }
 
     /**
-     * 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;
 

+ 6 - 6
src/Auth/Storage/StorageInterface.php

@@ -21,24 +21,24 @@ namespace Cake\Auth\Storage;
 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();
 }

+ 4 - 4
src/Controller/Component/AuthComponent.php

@@ -600,7 +600,7 @@ class AuthComponent extends Component
      */
     public function setUser(array $user)
     {
-        $this->storage()->set($user);
+        $this->storage()->write($user);
     }
 
     /**
@@ -621,7 +621,7 @@ class AuthComponent extends Component
         $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 @@ class AuthComponent extends Component
      */
     public function user($key = null)
     {
-        $user = $this->storage()->get();
+        $user = $this->storage()->read();
         if (!$user) {
             return;
         }
@@ -668,7 +668,7 @@ class AuthComponent extends Component
         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;
             }
         }

+ 12 - 12
tests/TestCase/Auth/Storage/SessionStorageTest.php

@@ -41,63 +41,63 @@ class SessionStorageTest extends TestCase
     }
 
     /**
-     * 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();
     }
 }

+ 5 - 5
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -183,7 +183,7 @@ class AuthComponentTest extends TestCase
         $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 @@ class AuthComponentTest extends TestCase
         $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 @@ class AuthComponentTest extends TestCase
     {
         $storage = $this->getMock(
             'Cake\Auth\Storage\SessionStorage',
-            ['set'],
+            ['write'],
             [$this->Auth->request]
         );
         $this->Auth->storage($storage);
@@ -1124,7 +1124,7 @@ class AuthComponentTest extends TestCase
         $user = ['username' => 'mark', 'role' => 'admin'];
 
         $storage->expects($this->once())
-            ->method('set')
+            ->method('write')
             ->with($user);
 
         $this->Auth->setUser($user);