[HttpFoundation] Add tests for session memcache/d storage drivers.

This commit is contained in:
Drak 2012-02-12 20:05:27 +05:45
parent fc7d0110f7
commit cab1060a76
3 changed files with 7 additions and 27 deletions

View File

@ -47,11 +47,9 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS
// defaults // defaults
if (!isset($memcachedOptions['serverpool'])) { if (!isset($memcachedOptions['serverpool'])) {
$memcachedOptions['serverpool'] = array( $memcachedOptions['serverpool'][] = array(
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => 11211, 'port' => 11211,
'timeout' => 1,
'persistent' => false,
'weight' => 1); 'weight' => 1);
} }
@ -59,7 +57,7 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS
$this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, isset($memcachedOptions['prefix']) ? $memcachedOptions['prefix'] : 'sf2s'); $this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, isset($memcachedOptions['prefix']) ? $memcachedOptions['prefix'] : 'sf2s');
$this->memcacheOptions = $memcachedOptions; $this->memcachedOptions = $memcachedOptions;
parent::__construct($options); parent::__construct($options);
} }
@ -69,11 +67,7 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS
*/ */
public function openSession($savePath, $sessionName) public function openSession($savePath, $sessionName)
{ {
foreach ($this->memcachedOptions['serverpool'] as $server) { return $this->memcached->addServers($this->memcachedOptions['serverpool']);
$this->addServer($server);
}
return true;
} }
/** /**

View File

@ -29,14 +29,6 @@ class MemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
$this->storage = 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() public function testOpenSession()
{ {
$this->memcache->expects($this->atLeastOnce()) $this->memcache->expects($this->atLeastOnce())
@ -48,7 +40,8 @@ class MemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testCloseSession() public function testCloseSession()
{ {
$this->memcache->expects($this->once()) $this->memcache->expects($this->once())
->method('close'); ->method('close')
->will($this->returnValue(true));
$this->assertTrue($this->storage->closeSession()); $this->assertTrue($this->storage->closeSession());
} }

View File

@ -29,18 +29,11 @@ class MemcacheddSessionStorageTest extends \PHPUnit_Framework_TestCase
$this->storage = 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() public function testOpenSession()
{ {
$this->memcached->expects($this->atLeastOnce()) $this->memcached->expects($this->atLeastOnce())
->method('addServer'); ->method('addServers')
->will($this->returnValue(true));
$this->assertTrue($this->storage->openSession('', '')); $this->assertTrue($this->storage->openSession('', ''));
} }