diff --git a/library/Zend/Session/AbstractManager.php b/library/Zend/Session/AbstractManager.php index 815a0840c31..8e96477b6dd 100644 --- a/library/Zend/Session/AbstractManager.php +++ b/library/Zend/Session/AbstractManager.php @@ -69,82 +69,35 @@ abstract class AbstractManager implements Manager * Allow passing a configuration object or class name, a storage object or * class name, or an array of configuration. * - * @param null|string|Configuration|array $config - * @param null|string|Storage $storage - * @param null|string|SaveHandler $saveHandler + * @param Configuration $config + * @param Storage $storage + * @param SaveHandler $saveHandler * @return void */ - public function __construct($config = null, $storage = null, $saveHandler = null) + public function __construct(Configuration $config = null, Storage $storage = null, SaveHandler $saveHandler = null) { - if ($config instanceof \Zend\Config\Config) { - $config = $config->toArray(); - } - if (is_array($config)) { - foreach ($config as $key => $value) { - switch (strtolower($key)) { - case 'storage': - if (null === $storage) { - $storage = $value; - } - unset($config[$key]); - break; - case 'savehandler': - if (null === $saveHandler) { - $saveHandler = $value; - } - unset($config[$key]); - break; - } - } - } elseif (is_string($config)) { - if (!class_exists($config)) { - throw new Exception\InvalidArgumentException('Configuration class provided is invalid; not found'); - } - $config = new $config; - } - $this->setConfig($config); $this->setStorage($storage); - $this->setSaveHandler($saveHandler); + if ($saveHandler) { + $this->setSaveHandler($saveHandler); + } } /** * Set configuration object * - * Allows lazy-loading a class name, passing an array of configuration to - * the defined default configuration class, or passing in a Configuration - * object. If a null value is passed, an instance of the default - * configuration class is created. - * - * @param null|string|array|Configuration $config + * @param null|Configuration $config * @return void */ - public function setConfig($config) + public function setConfig(Configuration $config = null) { if (null === $config) { $config = new $this->configDefaultClass(); - } - - if (is_array($config)) { - $class = $this->configDefaultClass; - if (array_key_exists('class', $config)) { - $class = $config['class']; - unset($config['class']); - } - - if (!class_exists($class)) { - throw new Exception\InvalidArgumentException('Class provided for configuration is invalid; not found'); + if (!$config instanceof Configuration) { + throw new Exception\InvalidArgumentException('Default configuration type provided is invalid; must implement Zend\\Session\\Configuration'); } - - $options = $config; - $config = new $class(); - $config->setOptions($options); - unset($options); - } - - if (!$config instanceof Configuration) { - throw new Exception\InvalidArgumentException('Configuration type provided is invalid; must implement Zend\\Session\\Configuration'); } + $this->config = $config; } @@ -161,27 +114,16 @@ public function getConfig() /** * Set session storage object * - * Allows passing a null value, string class name, or Storage object. If a - * null value is passed, the default storage class will be used. - * - * @param null|string|Storage $storage + * @param null|Storage $storage * @return void */ - public function setStorage($storage) + public function setStorage(Storage $storage = null) { if (null === $storage) { $storage = new $this->storageDefaultClass(); - } - - if (is_string($storage)) { - if (!class_exists($storage)) { - throw new Exception\InvalidArgumentException('Class provided for Storage does not exist'); + if (!$storage instanceof Storage) { + throw new Exception\InvalidArgumentException('Default storage type provided is invalid; must implement Zend\\Session\\Storage'); } - $storage = new $storage(); - } - - if (!$storage instanceof Storage) { - throw new Exception\InvalidArgumentException('Storage type provided is invalid; must implement Zend\\Session\\Storage'); } $this->storage = $storage; @@ -200,29 +142,14 @@ public function getStorage() /** * Set session save handler object * - * Allows passing a null value, string class name, or SaveHandler object. If a - * null value is passed, no explicit save handler will be used. - * - * @param null|string|SaveHandler $saveHandler + * @param SaveHandler $saveHandler * @return void */ - public function setSaveHandler($saveHandler) + public function setSaveHandler(SaveHandler $saveHandler) { - if (null === $saveHandler) { + if ($saveHandler === null) { return ; } - - if (is_string($saveHandler)) { - if (!class_exists($saveHandler)) { - throw new Exception\InvalidArgumentException('Class provided for SaveHandler does not exist'); - } - $saveHandler = new $saveHandler(); - } - - if (!$saveHandler instanceof SaveHandler) { - throw new Exception\InvalidArgumentException('SaveHandler type provided is invalid; must implement Zend\\Session\\SaveHandler'); - } - $this->saveHandler = $saveHandler; } diff --git a/library/Zend/Session/Container.php b/library/Zend/Session/Container.php index 7540c8ba243..70c488a2d02 100644 --- a/library/Zend/Session/Container.php +++ b/library/Zend/Session/Container.php @@ -66,10 +66,10 @@ class Container extends ArrayObject * Provide a name ('Default' if none provided) and a Manager instance. * * @param null|string $name - * @param null|Manager $manager + * @param Manager $manager * @return void */ - public function __construct($name = 'Default', $manager = null) + public function __construct($name = 'Default', Manager $manager = null) { if (!preg_match('/^[a-z][a-z0-9_\\\]+$/i', $name)) { throw new Exception\InvalidArgumentException('Name passed to container is invalid; must consist of alphanumerics, backslashes and underscores only'); @@ -108,7 +108,7 @@ public static function getDefaultManager() if (null === self::$defaultManager) { $manager = new self::$managerDefaultClass(); if (!$manager instanceof Manager) { - throw new Exception\InvalidArgumentException('Invalid manager type provided; must implement Manager'); + throw new Exception\InvalidArgumentException('Invalid default manager type provided; must implement Manager'); } self::$defaultManager = $manager; } @@ -138,16 +138,16 @@ public function getManager() /** * Set session manager * - * @param null|string|Manager $manager + * @param null|Manager $manager * @return Container */ - protected function setManager($manager) + protected function setManager(Manager $manager = null) { if (null === $manager) { $manager = self::getDefaultManager(); - } - if (!$manager instanceof Manager) { - throw new Exception\InvalidArgumentException('Manager provided is invalid; must implement Manager interface'); + if (!$manager instanceof Manager) { + throw new Exception\InvalidArgumentException('Manager provided is invalid; must implement Manager interface'); + } } $this->manager = $manager; return $this; diff --git a/library/Zend/Session/Manager.php b/library/Zend/Session/Manager.php index b771841566f..41ed199a228 100644 --- a/library/Zend/Session/Manager.php +++ b/library/Zend/Session/Manager.php @@ -35,7 +35,7 @@ */ interface Manager { - public function __construct($config = null, $storage = null, $saveHandler = null); + public function __construct(Configuration $config = null, Storage $storage = null, SaveHandler $saveHandler = null); public function getConfig(); public function getStorage(); diff --git a/library/Zend/Session/SaveHandler/Cache.php b/library/Zend/Session/SaveHandler/Cache.php index 4278efda524..1a6c849186c 100644 --- a/library/Zend/Session/SaveHandler/Cache.php +++ b/library/Zend/Session/SaveHandler/Cache.php @@ -55,11 +55,11 @@ class Cache implements Savable /** * Constructor * - * @param Zend\Cache\Storage\Adapter|null $storageAdapter + * @param Zend\Cache\Storage\Adapter $storageAdapter * @return void * @throws Zend\Session\Exception */ - public function __construct($storageAdapter) + public function __construct(StorageAdapter $storageAdapter) { $this->setStorageAdapter($storageAdapter); } @@ -140,22 +140,11 @@ public function gc($maxlifetime) * * Allows passing a string class name or StorageAdapter object. * - * @param string|Zend\Cache\Storage\Adapter + * @param Zend\Cache\Storage\Adapter * @return void */ - public function setStorageAdapter($storageAdapter) + public function setStorageAdapter(StorageAdapter $storageAdapter) { - if (is_string($storageAdapter)) { - if (!class_exists($storageAdapter)) { - throw new Exception\InvalidArgumentException('Class provided for StorageAdapter does not exist'); - } - $storageAdapter = new $storageAdapter; - } - - if (!$storageAdapter instanceof StorageAdapter) { - throw new Exception\InvalidArgumentException('StorageAdapter type provided is invalid; must implement Zend\\Cache\\Storage\\Adapter'); - } - $this->storageAdapter = $storageAdapter; } diff --git a/library/Zend/Session/SaveHandler/DbTable.php b/library/Zend/Session/SaveHandler/DbTable.php index d40c368b89d..ff66b1efa6e 100644 --- a/library/Zend/Session/SaveHandler/DbTable.php +++ b/library/Zend/Session/SaveHandler/DbTable.php @@ -20,7 +20,8 @@ namespace Zend\Session\SaveHandler; -use Zend\Session\SaveHandler as Savable, +use Zend\Config\Config as Configuration, + Zend\Session\SaveHandler as Savable, Zend\Session\Container, Zend\Session\Exception, Zend\Db\Table\AbstractTable, @@ -29,10 +30,6 @@ /** * DB Table session save handler * - * @uses Zend\Config - * @uses Zend_Db_Table_Abstract - * @uses Zend_Db_Table_Row_Abstract - * @uses Zend\Session\SaveHandler\Exception * @category Zend * @package Zend_Session * @subpackage SaveHandler @@ -128,9 +125,8 @@ class DbTable /** * Constructor * - * $config is an instance of Zend_Config or an array of key/value pairs containing configuration options for - * Zend_Session_SaveHandler_DbTable and Zend_Db_Table_Abstract. These are the configuration options for - * Zend_Session_SaveHandler_DbTable: + * $config is an instance of Zend\Config\Config. These are the configuration options for + * Zend\Session\SaveHandler\DbTable: * * name => (string) Session table name * @@ -157,19 +153,13 @@ class DbTable * overrideLifetime => (boolean) Whether or not the lifetime of an existing session should be overridden * (optional; default: false) * - * @param Zend_Config|array $config User-provided configuration + * @param Configuration User-provided configuration * @return void * @throws Zend_Session_SaveHandler_Exception */ - public function __construct($config) + public function __construct(Configuration $config) { - if ($config instanceof \Zend\Config\Config) { - $config = $config->toArray(); - } else if (!is_array($config)) { - throw new Exception\InvalidArgumentException( - '$config must be an instance of Zend\\Config or array of key/value pairs containing ' - . 'configuration options for Zend\\Session\\SaveHandler\\DbTable and Zend\\Db\\Table\\Abstract.'); - } + $config = $config->toArray(); foreach ($config as $key => $value) { do { @@ -515,7 +505,7 @@ protected function _getPrimary($id, $type = null) /** * Retrieve session lifetime considering DbTable::OVERRIDE_LIFETIME * - * @param Zend_Db_Table_Row_Abstract $row + * @param Zend\Db\Table\Row\Abstract $row * @return int */ protected function _getLifetime(AbstractRow $row) @@ -532,7 +522,7 @@ protected function _getLifetime(AbstractRow $row) /** * Retrieve session expiration time * - * @param Zend_Db_Table_Row_Abstract $row + * @param Zend\Db\Table\Row\Abstract $row * @return int */ protected function _getExpirationTime(AbstractRow $row) diff --git a/library/Zend/Session/SessionManager.php b/library/Zend/Session/SessionManager.php index 0b14d15b7ee..08eb44f82fc 100644 --- a/library/Zend/Session/SessionManager.php +++ b/library/Zend/Session/SessionManager.php @@ -36,16 +36,6 @@ */ class SessionManager extends AbstractManager { - /** - * @var Configuration - */ - protected $config; - - /** - * @var Storage - */ - protected $storage; - /** * Default options when a call to {@link destroy()} is made * - send_expire_cookie: whether or not to send a cookie expiring the current session cookie diff --git a/library/Zend/Session/Storage/ArrayStorage.php b/library/Zend/Session/Storage/ArrayStorage.php index 711893b4713..9b527e7b3ea 100644 --- a/library/Zend/Session/Storage/ArrayStorage.php +++ b/library/Zend/Session/Storage/ArrayStorage.php @@ -149,6 +149,12 @@ public function isLocked($key = null) return array_key_exists($key, $locks); } + /** + * Unlock an object or key marked as locked + * + * @param null|int|string $key + * @return ArrayStorage + */ public function unlock($key = null) { if (null === $key) { diff --git a/tests/Zend/Session/ContainerTest.php b/tests/Zend/Session/ContainerTest.php index 7b32ad4761c..86f1f0fa2a0 100644 --- a/tests/Zend/Session/ContainerTest.php +++ b/tests/Zend/Session/ContainerTest.php @@ -23,6 +23,7 @@ namespace ZendTest\Session; use Zend\Session\Container, + Zend\Session\Configuration\StandardConfiguration, Zend\Session\Manager, Zend\Session; @@ -41,10 +42,12 @@ public function setUp() $this->forceAutoloader(); $_SESSION = array(); Container::setDefaultManager(null); - $this->manager = $manager = new TestAsset\TestManager(array( - 'class' => 'Zend\\Session\\Configuration\\StandardConfiguration', + + $config = new StandardConfiguration(array( 'storage' => 'Zend\\Session\\Storage\\ArrayStorage', )); + + $this->manager = $manager = new TestAsset\TestManager($config); $this->container = new Container('Default', $manager); } @@ -185,10 +188,10 @@ public function testContainerInstantiatesManagerWithDefaultsWhenNotInjected() public function testContainerAllowsInjectingManagerViaConstructor() { - $manager = new TestAsset\TestManager(array( - 'class' => 'Zend\\Session\\Configuration\\StandardConfiguration', + $config = new StandardConfiguration(array( 'storage' => 'Zend\\Session\\Storage\\ArrayStorage', )); + $manager = new TestAsset\TestManager($config); $container = new Container('Foo', $manager); $this->assertSame($manager, $container->getManager()); } diff --git a/tests/Zend/Session/SaveHandler/DbTableTest.php b/tests/Zend/Session/SaveHandler/DbTableTest.php index 1cb4bf48b49..f8e580ce5fc 100644 --- a/tests/Zend/Session/SaveHandler/DbTableTest.php +++ b/tests/Zend/Session/SaveHandler/DbTableTest.php @@ -27,6 +27,7 @@ Zend\Db\Db, Zend\Db\Adapter\AbstractAdapter, Zend\Db\Table\AbstractTable, + Zend\Config\Config, ZendTest\Session\TestAsset\TestManager; /** @@ -44,9 +45,9 @@ class DbTableTest extends \PHPUnit_Framework_TestCase { /** - * @var array + * @var Zend\Config\Config */ - protected $_saveHandlerTableConfig = array( + protected $saveHandlerTableConfig = array( 'name' => 'sessions', 'primary' => array( 'id', @@ -86,12 +87,29 @@ public function setUp() if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Zend\Session\SaveHandler\DbTable tests are not enabled due to missing PDO_Sqlite extension'); } + + $this->saveHandlerTableConfig = new Config(array( + 'name' => 'sessions', + 'primary' => array( + 'id', + 'save_path', + 'name', + ), + DbTable::MODIFIED_COLUMN => 'modified', + DbTable::LIFETIME_COLUMN => 'lifetime', + DbTable::DATA_COLUMN => 'data', + DbTable::PRIMARY_ASSIGNMENT => array( + DbTable::PRIMARY_ASSIGNMENT_SESSION_ID, + DbTable::PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH, + DbTable::PRIMARY_ASSIGNMENT_SESSION_NAME, + ), + ), true); // $this->markTestSkipped('Skipped until Zend\Db is refactored, this tests assumptions are generally bad, more assertions are needed'); $this->manager = $manager = new TestManager(); - $this->_saveHandlerTableConfig['manager'] = $this->manager; - $this->_setupDb($this->_saveHandlerTableConfig['primary']); + $this->saveHandlerTableConfig['manager'] = $this->manager; + $this->setupDb($this->saveHandlerTableConfig['primary']); } /** @@ -102,35 +120,26 @@ public function setUp() public function tearDown() { if ($this->_db instanceof AbstractAdapter) { - $this->_dropTable(); + $this->dropTable(); } } public function testConfigPrimaryAssignmentFullConfig() { - $sh = new DbTable($this->_saveHandlerTableConfig); + $sh = new DbTable($this->saveHandlerTableConfig); $this->assertInstanceOf('Zend\Db\Table\AbstractTable', $sh); } - public function testConstructorThrowsExceptionGivenConfigAsNull() - { - $this->setExpectedException( - 'Zend\Session\Exception\InvalidArgumentException', - '$config must be an instance of Zend\Config or array of key/value pairs containing configuration options for Zend\Session\SaveHandler\DbTable and Zend\Db\Table\Abstract' - ); - $saveHandler = new DbTable(null); - } - public function testTableNameSchema() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; $config['name'] = 'schema.session'; $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); } public function testPrimaryAssignmentIdNotSet() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; $config['primary'] = array('id'); $config[DbTable::PRIMARY_ASSIGNMENT] = DbTable::PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH; @@ -147,7 +156,7 @@ public function testPrimaryAssignmentIdNotSet() public function testPrimaryAssignmentNotArray() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; $config['primary'] = array('id'); $config[DbTable::PRIMARY_ASSIGNMENT] = DbTable::PRIMARY_ASSIGNMENT_SESSION_ID; @@ -159,7 +168,7 @@ public function testPrimaryAssignmentNotArray() public function testModifiedColumnNotSet() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::MODIFIED_COLUMN]); $this->setExpectedException( 'Zend\Session\Exception\RuntimeException', @@ -173,7 +182,7 @@ public function testModifiedColumnNotSet() public function testLifetimeColumnNotSet() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::LIFETIME_COLUMN]); $this->setExpectedException( @@ -185,7 +194,7 @@ public function testLifetimeColumnNotSet() public function testDataColumnNotSet() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::DATA_COLUMN]); $this->setExpectedException( @@ -198,9 +207,9 @@ public function testDataColumnNotSet() public function testDifferentArraySize() { //different number of args between primary and primaryAssignment - $config = $this->_saveHandlerTableConfig; - array_pop($config[DbTable::PRIMARY_ASSIGNMENT]); - + $config = $this->saveHandlerTableConfig; + unset($config[DbTable::PRIMARY_ASSIGNMENT]); + $this->setExpectedException( 'Zend\Session\Exception\RuntimeException' ); @@ -210,7 +219,7 @@ public function testDifferentArraySize() public function testEmptyPrimaryAssignment() { //test the default - no primaryAssignment - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = $config['primary'][0]; $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -220,7 +229,7 @@ public function testSessionIdPresent() { //test that the session Id must be in the primary assignment config try { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; $config[DbTable::PRIMARY_ASSIGNMENT] = array( DbTable::PRIMARY_ASSIGNMENT_SESSION_NAME, ); @@ -237,7 +246,7 @@ public function testModifiedColumnDefined() { //test the default - no primaryAssignment try { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); unset($config[DbTable::MODIFIED_COLUMN]); $this->_usedSaveHandlers[] = @@ -254,7 +263,7 @@ public function testLifetimeColumnDefined() { //test the default - no primaryAssignment try { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); unset($config[DbTable::LIFETIME_COLUMN]); $this->_usedSaveHandlers[] = @@ -271,7 +280,7 @@ public function testDataColumnDefined() { //test the default - no primaryAssignment try { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); unset($config[DbTable::DATA_COLUMN]); $this->_usedSaveHandlers[] = @@ -286,7 +295,7 @@ public function testDataColumnDefined() public function testLifetime() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config['lifetime']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -294,7 +303,7 @@ public function testLifetime() 'lifetime must default to session.gc_maxlifetime' ); - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; $lifetime = $config['lifetime'] = 1242; $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -304,7 +313,7 @@ public function testLifetime() public function testOverrideLifetime() { try { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; $config['overrideLifetime'] = true; $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -319,13 +328,13 @@ public function testOverrideLifetime() public function testSessionSaving() { - $this->_dropTable(); + $this->dropTable(); - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = array($config['primary'][0]); - $this->_setupDb($config['primary']); + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -337,9 +346,9 @@ public function testSessionSaving() */ $session = new \Zend\Session\Container('SaveHandler', $manager); - $session->testArray = $this->_saveHandlerTableConfig; + $session->testArray = $this->saveHandlerTableConfig; - $tmp = array('SaveHandler' => serialize(array('testArray' => $this->_saveHandlerTableConfig))); + $tmp = array('SaveHandler' => serialize(array('testArray' => $this->saveHandlerTableConfig))); $testAgainst = ''; foreach ($tmp as $key => $val) { $testAgainst .= $key . "|" . $val; @@ -356,10 +365,10 @@ public function testSessionSaving() public function testReadWrite() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = array($config['primary'][0]); - $this->_setupDb($config['primary']); + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -373,8 +382,8 @@ public function testReadWrite() public function testReadWriteComplex() { - $config = $this->_saveHandlerTableConfig; - $this->_setupDb($config['primary']); + $config = $this->saveHandlerTableConfig; + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); $saveHandler->open('savepath', 'sessionname'); @@ -388,10 +397,10 @@ public function testReadWriteComplex() public function testReadWriteTwice() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = array($config['primary'][0]); - $this->_setupDb($config['primary']); + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -408,12 +417,12 @@ public function testReadWriteTwice() public function testReadWriteTwiceAndExpire() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = array($config['primary'][0]); $config['lifetime'] = 1; - $this->_setupDb($config['primary']); + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -432,12 +441,12 @@ public function testReadWriteTwiceAndExpire() public function testReadWriteThreeTimesAndGc() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = array($config['primary'][0]); $config['lifetime'] = 1; - $this->_setupDb($config['primary']); + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); @@ -473,12 +482,12 @@ public function testReadWriteThreeTimesAndGc() public function testSetLifetime() { - $config = $this->_saveHandlerTableConfig; + $config = $this->saveHandlerTableConfig; unset($config[DbTable::PRIMARY_ASSIGNMENT]); $config['primary'] = array($config['primary'][0]); $config['lifetime'] = 1; - $this->_setupDb($config['primary']); + $this->setupDb($config['primary']); $this->_usedSaveHandlers[] = $saveHandler = new DbTable($config); $this->assertSame(1, $saveHandler->getLifetime()); @@ -491,7 +500,7 @@ public function testSetLifetime() public function testZendConfig() { $this->_usedSaveHandlers[] = - $saveHandler = new DbTable(new \Zend\Config\Config($this->_saveHandlerTableConfig)); + $saveHandler = new DbTable($this->saveHandlerTableConfig); /** * @todo Test something other than that an exception is not thrown */ @@ -500,11 +509,12 @@ public function testZendConfig() /** * Sets up the database connection and creates the table for session data * - * @param array $primary + * @param Zend\Config\Config $primary * @return void */ - protected function _setupDb(array $primary) + protected function setupDb(Config $primary) { + $primary = $primary->toArray(); if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('The pdo_sqlite extension must be available and enabled for this test'); } @@ -533,7 +543,7 @@ protected function _setupDb(array $primary) * * @return void */ - protected function _dropTable() + protected function dropTable() { if (!$this->_db instanceof AbstractAdapter) { return; diff --git a/tests/Zend/Session/SessionManagerTest.php b/tests/Zend/Session/SessionManagerTest.php index 92816094143..522408bca72 100644 --- a/tests/Zend/Session/SessionManagerTest.php +++ b/tests/Zend/Session/SessionManagerTest.php @@ -96,61 +96,6 @@ public function testCanPassConfigurationToConstructor() $this->assertSame($config, $manager->getConfig()); } - public function testPassingUnknownStringClassForConfigurationRaisesException() - { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Configuration class provided is invalid; not found'); - $manager = new SessionManager('foobarbazbat'); - } - - public function testPassingInvalidStringClassForConfigurationRaisesException() - { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Configuration type provided is invalid; must implement Zend\Session\Configuration'); - $manager = new SessionManager('Zend\Session\Storage\ArrayStorage'); - } - - public function testPassingValidStringClassForConfigurationInstantiatesThatConfiguration() - { - $manager = new SessionManager('Zend\\Session\\Configuration\\StandardConfiguration'); - $config = $manager->getConfig(); - $this->assertTrue($config instanceof Session\Configuration\StandardConfiguration); - } - - public function testPassingValidStringClassInClassKeyOfArrayConfigurationInstantiatesThatConfiguration() - { - $manager = new SessionManager(array('class' => 'Zend\\Session\\Configuration\\StandardConfiguration')); - $config = $manager->getConfig(); - $this->assertTrue($config instanceof Session\Configuration\StandardConfiguration); - } - - public function testPassingInvalidStringClassInClassKeyOfArrayConfigurationRaisesException() - { - $this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'Class provided for configuration is invalid; not found'); - $manager = new SessionManager(array('class' => 'foobarbaz')); - } - - public function testPassingValidStringClassInClassKeyOfArrayConfigurationInstantiatesThatConfigurationWithOptionsProvided() - { - $manager = new SessionManager(array( - 'class' => 'Zend\\Session\\Configuration\\StandardConfiguration', - 'save_path' => __DIR__, - )); - $config = $manager->getConfig(); - $this->assertTrue($config instanceof Session\Configuration\StandardConfiguration); - $this->assertEquals(__DIR__, $config->getSavePath()); - } - - public function testPassingZendConfigObjectForConfigurationInstantiatesThatConfiguration() - { - $config = new \Zend\Config\Config(array( - 'class' => 'Zend\\Session\\Configuration\\StandardConfiguration', - 'save_path' => __DIR__, - )); - $manager = new SessionManager($config); - $config = $manager->getConfig(); - $this->assertTrue($config instanceof Session\Configuration\StandardConfiguration); - $this->assertEquals(__DIR__, $config->getSavePath()); - } - public function testManagerUsesSessionStorageByDefault() { $storage = $this->manager->getStorage(); @@ -164,30 +109,6 @@ public function testCanPassStorageToConstructor() $this->assertSame($storage, $manager->getStorage()); } - public function testCanPassStringStorageNameToConstructor() - { - $manager = new SessionManager(null, 'Zend\\Session\\Storage\\ArrayStorage'); - $storage = $manager->getStorage(); - $this->assertTrue($storage instanceof Session\Storage\ArrayStorage); - } - - public function testCanPassStorageClassToConfigurationOptions() - { - $manager = new SessionManager(array('storage' => 'Zend\\Session\\Storage\\ArrayStorage')); - $storage = $manager->getStorage(); - $this->assertTrue($storage instanceof Session\Storage\ArrayStorage); - } - - public function testPassingStorageViaParamOverridesStorageInConfig() - { - $storage = new Session\Storage\ArrayStorage(); - $manager = new TestAsset\TestManager(array( - 'class' => 'Zend\\Session\\Configuration\\StandardConfiguration', - 'storage' => 'Zend\\Session\\Storage\\SessionStorage', - ), $storage); - $this->assertSame($storage, $manager->getStorage()); - } - public function testCanPassSaveHandlerToConstructor() { $saveHandler = new TestAsset\TestSaveHandler(); @@ -195,30 +116,6 @@ public function testCanPassSaveHandlerToConstructor() $this->assertSame($saveHandler, $manager->getSaveHandler()); } - public function testCanPassStringSessionHandlerNameToConstructor() - { - $manager = new SessionManager(null, null, 'ZendTest\\Session\\TestAsset\\TestSaveHandler'); - $sessionHandler = $manager->getSaveHandler(); - $this->assertTrue($sessionHandler instanceof TestAsset\TestSaveHandler); - } - - public function testCanPassSaveHandlerToConfigurationOptions() - { - $manager = new SessionManager(array('saveHandler' => 'ZendTest\\Session\\TestAsset\\TestSaveHandler')); - $saveHandler = $manager->getSaveHandler(); - $this->assertTrue($saveHandler instanceof TestAsset\TestSaveHandler); - } - - public function testPassingSaveHandlerViaParamOverridesSaveHandlerInConfig() - { - $saveHandler = new TestAsset\TestSaveHandler(); - $manager = new TestAsset\TestManager(array( - 'class' => 'Zend\\Session\\Configuration\\StandardConfiguration', - 'saveHandler' => 'ZendTest\\Session\\TestAsset\\TestSaveHandler', - ), null, $saveHandler); - $this->assertSame($saveHandler, $manager->getSaveHandler()); - } - // Session-related functionality /**