[HttpFoundation] Refactor tests.
This commit is contained in:
parent
2257a3d4d6
commit
88b1170356
@ -2,46 +2,12 @@
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
|
||||
/**
|
||||
* Turn AbstractSessionStorage into something concrete because
|
||||
* certain mocking features are broken in PHPUnit-Mock-Objects < 1.1.2
|
||||
* @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73
|
||||
*/
|
||||
class ConcreteSessionStorage extends AbstractSessionStorage
|
||||
{
|
||||
}
|
||||
|
||||
class CustomHandlerSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
{
|
||||
public function open($path, $id)
|
||||
{
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($id, $data)
|
||||
{
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
}
|
||||
|
||||
public function gc($lifetime)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test class for AbstractSessionStorage.
|
||||
*
|
||||
@ -51,14 +17,14 @@ class CustomHandlerSessionStorage extends AbstractSessionStorage implements \Ses
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class SessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return AbstractSessionStorage
|
||||
*/
|
||||
protected function getStorage($options = array())
|
||||
protected function getStorage(array $options = array())
|
||||
{
|
||||
$storage = new CustomHandlerSessionStorage($options);
|
||||
$storage = new SessionStorage($options);
|
||||
$storage->registerBag(new AttributeBag);
|
||||
|
||||
return $storage;
|
||||
@ -112,23 +78,11 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
|
||||
}
|
||||
|
||||
public function testCustomSaveHandlers()
|
||||
{
|
||||
$storage = new CustomHandlerSessionStorage();
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
public function testNativeSaveHandlers()
|
||||
{
|
||||
$storage = new ConcreteSessionStorage();
|
||||
$this->assertNotEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
public function testDefaultSessionCacheLimiter()
|
||||
{
|
||||
ini_set('session.cache_limiter', 'nocache');
|
||||
|
||||
$storage = new ConcreteSessionStorage();
|
||||
$storage = new SessionStorage();
|
||||
$this->assertEquals('', ini_get('session.cache_limiter'));
|
||||
}
|
||||
|
||||
@ -136,7 +90,7 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
ini_set('session.cache_limiter', 'nocache');
|
||||
|
||||
$storage = new ConcreteSessionStorage(array('cache_limiter' => 'public'));
|
||||
$storage = new SessionStorage(array('cache_limiter' => 'public'));
|
||||
$this->assertEquals('public', ini_get('session.cache_limiter'));
|
||||
}
|
||||
|
||||
@ -160,4 +114,33 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals($options, $gco);
|
||||
}
|
||||
|
||||
public function testSetSaveHandler()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->setSaveHandler(new \StdClass());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
|
||||
}
|
||||
|
||||
public function testSetSaveHandlerPHP53()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4.0', '>=')) {
|
||||
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
|
||||
}
|
||||
|
||||
$storage = $this->getStorage();
|
||||
$storage->setSaveHandler(new NativeFileSessionHandler());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
|
||||
}
|
||||
|
||||
public function testSetSaveHandlerPHP54()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
$this->markTestSkipped('Test skipped, for PHP 5.4+ only.');
|
||||
}
|
||||
|
||||
$storage = $this->getStorage();
|
||||
$storage->setSaveHandler(new NullSessionHandler());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MemcacheSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler;
|
||||
|
||||
class MemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class MemcacheSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MemcacheSessionStorage
|
||||
@ -20,7 +20,7 @@ class MemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$this->memcache = $this->getMock('Memcache');
|
||||
$this->storage = new MemcacheSessionStorage($this->memcache);
|
||||
$this->storage = new MemcacheSessionHandler($this->memcache);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@ -42,7 +42,7 @@ class MemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$mock = $this->getMock('Memcache');
|
||||
|
||||
$storage = new MemcacheSessionStorage($mock, array(
|
||||
$storage = new MemcacheSessionHandler($mock, array(
|
||||
'serverpool' => array(
|
||||
array('host' => '127.0.0.2'),
|
||||
array('host' => '127.0.0.3',
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MemcachedSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler;
|
||||
|
||||
class MemcacheddSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class MemcacheddSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MemcachedSessionStorage
|
||||
* @var MemcachedSessionHandler
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
@ -20,7 +20,7 @@ class MemcacheddSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$this->memcached = $this->getMock('Memcached');
|
||||
$this->storage = new MemcachedSessionStorage($this->memcached);
|
||||
$this->storage = new MemcachedSessionHandler($this->memcached);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeFileSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NativeFileSessionStorage.
|
||||
@ -11,13 +12,29 @@ use Symfony\Component\HttpFoundation\Session\Storage\NativeFileSessionStorage;
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class NativeFileSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class NativeFileSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
public function testConstruct()
|
||||
{
|
||||
$storage = new NativeFileSessionStorage(sys_get_temp_dir(), array('name' => 'TESTING'));
|
||||
$this->assertEquals('files', ini_get('session.save_handler'));
|
||||
$storage = new SessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
|
||||
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('files', ini_get('session.save_handler'));
|
||||
} else {
|
||||
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
$this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
|
||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||
}
|
||||
|
||||
public function testConstructDefault()
|
||||
{
|
||||
$path = ini_get('session.save_path');
|
||||
$storage = new SessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
|
||||
|
||||
$this->assertEquals($path, ini_get('session.save_path'));
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeMemcacheSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeMemcacheSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NativeMemcacheSessionStorage.
|
||||
* Test class for NativeMemcacheSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class NativeMemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class NativeMemcacheSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
@ -19,8 +20,16 @@ class NativeMemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->markTestSkipped('Skipped tests SQLite extension is not present');
|
||||
}
|
||||
|
||||
$storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0', array('name' => 'TESTING'));
|
||||
$this->assertEquals('memcache', ini_get('session.save_handler'));
|
||||
$storage = new SessionStorage(array('name' => 'TESTING'), new NativeMemcacheSessionHandler('tcp://127.0.0.1:11211?persistent=0'));
|
||||
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
$this->assertEquals('memcache', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('memcache', ini_get('session.save_handler'));
|
||||
} else {
|
||||
$this->assertEquals('memcache', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
$this->assertEquals('tcp://127.0.0.1:11211?persistent=0', ini_get('session.save_path'));
|
||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeMemcachedSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeMemcachedSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NativeMemcachedSessionStorage.
|
||||
* Test class for NativeMemcachedSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class NativeMemcachedSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class NativeMemcachedSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
@ -22,9 +23,16 @@ class NativeMemcachedSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
// test takes too long if memcached server is not running
|
||||
ini_set('memcached.sess_locking', '0');
|
||||
|
||||
$storage = new NativeMemcachedSessionStorage('127.0.0.1:11211', array('name' => 'TESTING'));
|
||||
$storage = new SessionStorage(array('name' => 'TESTING'), new NativeMemcachedSessionHandler('127.0.0.1:11211'));
|
||||
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
$this->assertEquals('memcached', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('memcached', ini_get('session.save_handler'));
|
||||
} else {
|
||||
$this->assertEquals('memcached', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
$this->assertEquals('memcached', ini_get('session.save_handler'));
|
||||
$this->assertEquals('127.0.0.1:11211', ini_get('session.save_path'));
|
||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSqliteSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSqliteSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NativeSqliteSessionStorage.
|
||||
@ -11,7 +12,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\NativeSqliteSessionStorage;
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class NativeSqliteSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
class NativeSqliteSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
@ -19,8 +20,17 @@ class NativeSqliteSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->markTestSkipped('Skipped tests SQLite extension is not present');
|
||||
}
|
||||
|
||||
$storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db', array('name' => 'TESTING'));
|
||||
$this->assertEquals('sqlite', ini_get('session.save_handler'));
|
||||
$storage = new SessionStorage(array('name' => 'TESTING'), new NativeSqliteSessionHandler(sys_get_temp_dir().'/sqlite.db'));
|
||||
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
$this->assertEquals('sqlite', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('sqlite', ini_get('session.save_handler'));
|
||||
} else {
|
||||
$this->assertEquals('sqlite', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
|
||||
$this->assertEquals(sys_get_temp_dir().'/sqlite.db', ini_get('session.save_path'));
|
||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NullSessionStorage;
|
||||
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage\Handler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
/**
|
||||
* Test class for NullSessionStorage.
|
||||
* Test class for NullSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
@ -15,14 +16,14 @@ class NullSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
$storage = new NullSessionStorage();
|
||||
$storage = $this->getStorage();
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
public function testSession()
|
||||
{
|
||||
session_id('nullsessionstorage');
|
||||
$storage = new NullSessionStorage();
|
||||
$storage = $this->getStorage();
|
||||
$session = new Session($storage);
|
||||
$this->assertNull($session->get('something'));
|
||||
$session->set('something', 'unique');
|
||||
@ -32,11 +33,16 @@ class NullSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
public function testNothingIsPersisted()
|
||||
{
|
||||
session_id('nullsessionstorage');
|
||||
$storage = new NullSessionStorage();
|
||||
$storage = $this->getStorage();
|
||||
$session = new Session($storage);
|
||||
$session->start();
|
||||
$this->assertEquals('nullsessionstorage', $session->getId());
|
||||
$this->assertNull($session->get('something'));
|
||||
}
|
||||
|
||||
public function getStorage()
|
||||
{
|
||||
return new SessionStorage(array(), new NullSessionHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user