merged branch drak/session_memcache_tests (PR #3335)
Commits
-------
fe870be
[HttpFoundation] Added tests for memcache/d storage drivers.
Discussion
----------
[WIP][2.1][HttpFoundation] Add tests for session memcache/d storage drivers.
__[WIP] pending merge of PR 3333, no review please.__
Bug fix: no
Feature addition: no
Backwards compatibility break: no
__Symfony2 tests pass: no__
Fixes the following tickets: -
Todo: -
This commit is contained in:
commit
1da8deee4e
@ -75,6 +75,7 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa
|
|||||||
if (array_key_exists('host', $server)) {
|
if (array_key_exists('host', $server)) {
|
||||||
throw new \InvalidArgumentException('host key must be set');
|
throw new \InvalidArgumentException('host key must be set');
|
||||||
}
|
}
|
||||||
|
|
||||||
$server['port'] = isset($server['port']) ? (int)$server['port'] : 11211;
|
$server['port'] = isset($server['port']) ? (int)$server['port'] : 11211;
|
||||||
$server['timeout'] = isset($server['timeout']) ? (int)$server['timeout'] : 1;
|
$server['timeout'] = isset($server['timeout']) ? (int)$server['timeout'] : 1;
|
||||||
$server['presistent'] = isset($server['presistent']) ? (bool)$server['presistent'] : false;
|
$server['presistent'] = isset($server['presistent']) ? (bool)$server['presistent'] : false;
|
||||||
@ -87,7 +88,7 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa
|
|||||||
public function openSession($savePath, $sessionName)
|
public function openSession($savePath, $sessionName)
|
||||||
{
|
{
|
||||||
foreach ($this->memcacheOptions['serverpool'] as $server) {
|
foreach ($this->memcacheOptions['serverpool'] as $server) {
|
||||||
$this->addServer($server);
|
$this->memcache->addServer($server);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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