Skip to content

Commit

Permalink
Rename SessionStorageInterface methods.
Browse files Browse the repository at this point in the history
Makes them consistent with names used by Cache and Session classes.
  • Loading branch information
ADmad committed May 29, 2015
1 parent 933e2b7 commit 64ad006
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/Auth/Storage/MemoryStorage.php
Expand Up @@ -32,23 +32,23 @@ class MemoryStorage implements StorageInterface
/**
* {@inheritDoc}
*/
public function get()
public function read()
{
return $this->_user;
}

/**
* {@inheritDoc}
*/
public function set(array $user)
public function write(array $user)
{
$this->_user = $user;
}

/**
* {@inheritDoc}
*/
public function remove()
public function delete()
{
$this->_user = null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Auth/Storage/SessionStorage.php
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/Auth/Storage/StorageInterface.php
Expand Up @@ -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();
}
8 changes: 4 additions & 4 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -600,7 +600,7 @@ public function deny($actions = null)
*/
public function setUser(array $user)
{
$this->storage()->set($user);
$this->storage()->write($user);
}

/**
Expand All @@ -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']);
}

Expand All @@ -634,7 +634,7 @@ public function logout()
*/
public function user($key = null)
{
$user = $this->storage()->get();
$user = $this->storage()->read();
if (!$user) {
return;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
24 changes: 12 additions & 12 deletions tests/TestCase/Auth/Storage/SessionStorageTest.php
Expand Up @@ -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();
}
}
10 changes: 5 additions & 5 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -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'));
}
Expand All @@ -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);
Expand Down Expand Up @@ -1116,15 +1116,15 @@ public function testSetUser()
{
$storage = $this->getMock(
'Cake\Auth\Storage\SessionStorage',
['set'],
['write'],
[$this->Auth->request]
);
$this->Auth->storage($storage);

$user = ['username' => 'mark', 'role' => 'admin'];

$storage->expects($this->once())
->method('set')
->method('write')
->with($user);

$this->Auth->setUser($user);
Expand Down

0 comments on commit 64ad006

Please sign in to comment.