Skip to content

Commit

Permalink
Destroy should only return false when removal of session truely fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
zluiten committed Jun 20, 2016
1 parent ab4876e commit 88f93fa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/SaveHandler/DbTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ public function write($id, $data)
*/
public function destroy($id)
{
return (bool) $this->tableGateway->delete([
$exists = (bool) $this->read($id);

$deleted = (bool) $this->tableGateway->delete([
$this->options->getIdColumn() => $id,
$this->options->getNameColumn() => $this->sessionName,
]);
]);

return $exists ? $deleted : true;
}

/**
Expand Down
35 changes: 34 additions & 1 deletion test/SaveHandler/DbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
*/
protected $usedSaveHandlers = [];

/**
* Test data container.
*
* @var array
*/
private $testArray;

/**
* Setup performed prior to each test method
*
Expand Down Expand Up @@ -135,10 +142,36 @@ public function testReadShouldAlwaysReturnString()
$this->assertTrue(is_string($data));
}

public function testDestroyReturnsTrueEvenWhenSessionDoesNotExist()
{
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
$saveHandler->open('savepath', 'sessionname');

$id = '242';

$result = $saveHandler->destroy($id);

$this->assertTrue($result);
}

public function testDestroyReturnsTrueWhenSessionIsDeleted()
{
$this->usedSaveHandlers[] = $saveHandler = new DbTableGateway($this->tableGateway, $this->options);
$saveHandler->open('savepath', 'sessionname');

$id = '242';

$this->assertTrue($saveHandler->write($id, serialize($this->testArray)));

$result = $saveHandler->destroy($id);

$this->assertTrue($result);
}

/**
* Sets up the database connection and creates the table for session data
*
* @param Zend\Session\SaveHandler\DbTableGatewayOptions $options
* @param \Zend\Session\SaveHandler\DbTableGatewayOptions $options
* @return void
*/
protected function setupDb(DbTableGatewayOptions $options)
Expand Down

0 comments on commit 88f93fa

Please sign in to comment.