[HttpFoundation] Added tests for memcache/d storage drivers.
This commit is contained in:
parent
7e4f4dcdf9
commit
fe870beae3
@ -75,6 +75,7 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa
|
||||
if (array_key_exists('host', $server)) {
|
||||
throw new \InvalidArgumentException('host key must be set');
|
||||
}
|
||||
|
||||
$server['port'] = isset($server['port']) ? (int)$server['port'] : 11211;
|
||||
$server['timeout'] = isset($server['timeout']) ? (int)$server['timeout'] : 1;
|
||||
$server['presistent'] = isset($server['presistent']) ? (bool)$server['presistent'] : false;
|
||||
@ -87,7 +88,7 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa
|
||||
public function openSession($savePath, $sessionName)
|
||||
{
|
||||
foreach ($this->memcacheOptions['serverpool'] as $server) {
|
||||
$this->addServer($server);
|
||||
$this->memcache->addServer($server);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MemcacheSessionStorage;
|
||||
|
||||
class MemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MemcacheSessionStorage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected $memcache;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Memcache')) {
|
||||
$this->markTestSkipped('Skipped tests Memcache class is not present');
|
||||
}
|
||||
|
||||
$this->memcache = $this->getMock('Memcache');
|
||||
$this->storage = new MemcacheSessionStorage($this->memcache);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->memcache = null;
|
||||
$this->storage = null;
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testOpenSession()
|
||||
{
|
||||
$this->memcache->expects($this->atLeastOnce())
|
||||
->method('addServer');
|
||||
|
||||
$this->assertTrue($this->storage->openSession('', ''));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->memcache->expects($this->once())
|
||||
->method('close');
|
||||
|
||||
$this->assertTrue($this->storage->closeSession());
|
||||
}
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->memcache->expects($this->once())
|
||||
->method('get');
|
||||
|
||||
$this->assertEquals('', $this->storage->readSession(''));
|
||||
}
|
||||
|
||||
public function testWriteSession()
|
||||
{
|
||||
$this->memcache->expects($this->once())
|
||||
->method('set')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->storage->writeSession('', ''));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcache->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->storage->destroySession(''));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->gcSession(123));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MemcachedSessionStorage;
|
||||
|
||||
class MemcacheddSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MemcachedSessionStorage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected $memcached;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Memcached')) {
|
||||
$this->markTestSkipped('Skipped tests Memcache class is not present');
|
||||
}
|
||||
|
||||
$this->memcached = $this->getMock('Memcached');
|
||||
$this->storage = new MemcachedSessionStorage($this->memcached);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->memcached = null;
|
||||
$this->storage = null;
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testOpenSession()
|
||||
{
|
||||
$this->memcached->expects($this->atLeastOnce())
|
||||
->method('addServer');
|
||||
|
||||
$this->assertTrue($this->storage->openSession('', ''));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->closeSession());
|
||||
}
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->memcached->expects($this->once())
|
||||
->method('get');
|
||||
|
||||
$this->assertEquals('', $this->storage->readSession(''));
|
||||
}
|
||||
|
||||
public function testWriteSession()
|
||||
{
|
||||
$this->memcached->expects($this->once())
|
||||
->method('set')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->storage->writeSession('', ''));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcached->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->storage->destroySession(''));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->gcSession(123));
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user