From fe870beae36a0696dde5683f5e07734d93c214b8 Mon Sep 17 00:00:00 2001 From: Drak Date: Sun, 12 Feb 2012 10:38:50 +0545 Subject: [PATCH] [HttpFoundation] Added tests for memcache/d storage drivers. --- .../Storage/MemcacheSessionStorage.php | 3 +- .../Storage/MemcacheSessionStorageTest.php | 87 +++++++++++++++++++ .../Storage/MemcachedSessionStorageTest.php | 85 ++++++++++++++++++ 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcacheSessionStorageTest.php create mode 100644 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcachedSessionStorageTest.php diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MemcacheSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MemcacheSessionStorage.php index f5d5910d86..6ce47952bd 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MemcacheSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MemcacheSessionStorage.php @@ -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; diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcacheSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcacheSessionStorageTest.php new file mode 100644 index 0000000000..f644b06c52 --- /dev/null +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcacheSessionStorageTest.php @@ -0,0 +1,87 @@ +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)); + } + +} diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcachedSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcachedSessionStorageTest.php new file mode 100644 index 0000000000..a4a23b1e51 --- /dev/null +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MemcachedSessionStorageTest.php @@ -0,0 +1,85 @@ +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)); + } + + +}