summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaime Pérez Crespo <jaime.perez@uninett.no>2017-01-12 11:19:29 +0100
committerJaime Pérez Crespo <jaime.perez@uninett.no>2017-01-12 11:19:29 +0100
commitef5677fb113673a84afb458ab35df6a01736433f (patch)
treeaa791b2372498188131524973355752b60abd1eb
parent98da26e110b7adbb9b819b90d946a776fb1b7ab7 (diff)
downloadsimplesamlphp-ef5677fb113673a84afb458ab35df6a01736433f.zip
simplesamlphp-ef5677fb113673a84afb458ab35df6a01736433f.tar.gz
simplesamlphp-ef5677fb113673a84afb458ab35df6a01736433f.tar.bz2
Minor fixes.
Formatting, namespaces, phpdoc.
-rw-r--r--lib/SimpleSAML/Store.php10
-rw-r--r--lib/SimpleSAML/Store/Memcache.php37
-rw-r--r--lib/SimpleSAML/Store/SQL.php16
-rw-r--r--tests/lib/SimpleSAML/Store/SQLTest.php89
-rw-r--r--tests/lib/SimpleSAML/StoreTest.php68
5 files changed, 113 insertions, 107 deletions
diff --git a/lib/SimpleSAML/Store.php b/lib/SimpleSAML/Store.php
index 1aa1d11..5ee6e43 100644
--- a/lib/SimpleSAML/Store.php
+++ b/lib/SimpleSAML/Store.php
@@ -2,7 +2,6 @@
namespace SimpleSAML;
-
use SimpleSAML\Error\CriticalConfigurationError;
/**
@@ -12,13 +11,12 @@ use SimpleSAML\Error\CriticalConfigurationError;
*/
abstract class Store
{
-
/**
* Our singleton instance.
*
* This is false if the data store isn't enabled, and null if we haven't attempted to initialize it.
*
- * @var Store|false|null
+ * @var \SimpleSAML\Store|false|null
*/
private static $instance;
@@ -26,13 +24,12 @@ abstract class Store
/**
* Retrieve our singleton instance.
*
- * @return false|Store The data store, or false if it isn't enabled.
+ * @return false|\SimpleSAML\Store The data store, or false if it isn't enabled.
*
- * @throws CriticalConfigurationError
+ * @throws \SimpleSAML\Error\CriticalConfigurationError
*/
public static function getInstance()
{
-
if (self::$instance !== null) {
return self::$instance;
}
@@ -103,5 +100,4 @@ abstract class Store
* @param string $key The key.
*/
abstract public function delete($type, $key);
-
}
diff --git a/lib/SimpleSAML/Store/Memcache.php b/lib/SimpleSAML/Store/Memcache.php
index c4bdd02..b835207 100644
--- a/lib/SimpleSAML/Store/Memcache.php
+++ b/lib/SimpleSAML/Store/Memcache.php
@@ -2,41 +2,40 @@
namespace SimpleSAML\Store;
-use SimpleSAML\Store;
+use \SimpleSAML_Configuration as Configuration;
+use \SimpleSAML\Store;
/**
- * A memcache based datastore.
+ * A memcache based data store.
*
* @package SimpleSAMLphp
*/
class Memcache extends Store
{
/**
- * Initialize the memcache datastore.
- */
-
- /**
* This variable contains the session name prefix.
*
* @var string
*/
private $prefix;
+
/**
* This function implements the constructor for this class. It loads the Memcache configuration.
*/
- protected function __construct() {
- $config = \SimpleSAML_Configuration::getInstance();
+ protected function __construct()
+ {
+ $config = Configuration::getInstance();
$this->prefix = $config->getString('memcache_store.prefix', 'simpleSAMLphp');
}
/**
- * Retrieve a value from the datastore.
+ * Retrieve a value from the data store.
*
- * @param string $type The datatype.
- * @param string $key The key.
- * @return mixed|NULL The value.
+ * @param string $type The data type.
+ * @param string $key The key.
+ * @return mixed|null The value.
*/
public function get($type, $key)
{
@@ -48,11 +47,11 @@ class Memcache extends Store
/**
- * Save a value to the datastore.
+ * Save a value to the data store.
*
- * @param string $type The datatype.
- * @param string $key The key.
- * @param mixed $value The value.
+ * @param string $type The data type.
+ * @param string $key The key.
+ * @param mixed $value The value.
* @param int|NULL $expire The expiration time (unix timestamp), or NULL if it never expires.
*/
public function set($type, $key, $value, $expire = null)
@@ -70,10 +69,10 @@ class Memcache extends Store
/**
- * Delete a value from the datastore.
+ * Delete a value from the data store.
*
- * @param string $type The datatype.
- * @param string $key The key.
+ * @param string $type The data type.
+ * @param string $key The key.
*/
public function delete($type, $key)
{
diff --git a/lib/SimpleSAML/Store/SQL.php b/lib/SimpleSAML/Store/SQL.php
index b6cf384..4152d7a 100644
--- a/lib/SimpleSAML/Store/SQL.php
+++ b/lib/SimpleSAML/Store/SQL.php
@@ -2,9 +2,9 @@
namespace SimpleSAML\Store;
-use SimpleSAML\Logger;
-use SimpleSAML\Store;
-
+use \SimpleSAML_Configuration as Configuration;
+use \SimpleSAML\Logger;
+use \SimpleSAML\Store;
/**
* A data store using a RDBMS to keep the data.
@@ -13,7 +13,6 @@ use SimpleSAML\Store;
*/
class SQL extends Store
{
-
/**
* The PDO object for our database.
*
@@ -51,7 +50,7 @@ class SQL extends Store
*/
protected function __construct()
{
- $config = \SimpleSAML_Configuration::getInstance();
+ $config = Configuration::getInstance();
$dsn = $config->getString('store.sql.dsn');
$username = $config->getString('store.sql.username', null);
@@ -100,7 +99,6 @@ class SQL extends Store
*/
private function initKVTable()
{
-
if ($this->getTableVersion('kvstore') === 1) {
// Table initialized
return;
@@ -191,8 +189,7 @@ class SQL extends Store
return;
}
- // Default implementation. Try INSERT, and UPDATE if that fails.
-
+ // default implementation, try INSERT, and UPDATE if that fails.
$insertQuery = 'INSERT INTO '.$table.' '.$colNames.' '.$values;
$insertQuery = $this->pdo->prepare($insertQuery);
try {
@@ -212,7 +209,6 @@ class SQL extends Store
$updateCols = array();
$condCols = array();
foreach ($data as $col => $value) {
-
$tmp = $col.' = :'.$col;
if (in_array($col, $keys, true)) {
@@ -233,7 +229,6 @@ class SQL extends Store
*/
private function cleanKVStore()
{
-
Logger::debug('store.sql: Cleaning key-value store.');
$query = 'DELETE FROM '.$this->prefix.'_kvstore WHERE _expire < :now';
@@ -323,7 +318,6 @@ class SQL extends Store
'_expire' => $expire,
);
-
$this->insertOrUpdate($this->prefix.'_kvstore', array('_type', '_key'), $data);
}
diff --git a/tests/lib/SimpleSAML/Store/SQLTest.php b/tests/lib/SimpleSAML/Store/SQLTest.php
index 3318754..09b4ddb 100644
--- a/tests/lib/SimpleSAML/Store/SQLTest.php
+++ b/tests/lib/SimpleSAML/Store/SQLTest.php
@@ -1,14 +1,19 @@
<?php
-/*
- * This file is part of the sgomezsimplesamlphp.
+
+namespace SimpleSAML\Test\Store;
+
+use \SimpleSAML_Configuration as Configuration;
+use \SimpleSAML\Store;
+
+/**
+ * Tests for the SQL store.
*
- * (c) Sergio Gómez <sergio@uco.es>
+ * For the full copyright and license information, please view the LICENSE file that was distributed with this source
+ * code.
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * @author Sergio Gómez <sergio@uco.es>
+ * @package simplesamlphp/simplesamlphp
*/
-
-
class SQLTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
@@ -21,26 +26,26 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store::getInstance
- * @covers SimpleSAML\Store\SQL::__construct
+ * @covers \SimpleSAML\Store::getInstance
+ * @covers \SimpleSAML\Store\SQL::__construct
* @test
*/
public function SQLInstance()
{
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$this->assertInstanceOf('SimpleSAML\Store\SQL', $store);
}
/**
- * @covers SimpleSAML\Store\SQL::initTableVersionTable
- * @covers SimpleSAML\Store\SQL::initKVTable
+ * @covers \SimpleSAML\Store\SQL::initTableVersionTable
+ * @covers \SimpleSAML\Store\SQL::initKVTable
* @test
*/
public function kvstoreTableVersion()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$version = $store->getTableVersion('kvstore');
@@ -48,13 +53,13 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::getTableVersion
+ * @covers \SimpleSAML\Store\SQL::getTableVersion
* @test
*/
public function newTableVersion()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$version = $store->getTableVersion('test');
@@ -62,14 +67,14 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::setTableVersion
- * @covers SimpleSAML\Store\SQL::insertOrUpdate
+ * @covers \SimpleSAML\Store\SQL::setTableVersion
+ * @covers \SimpleSAML\Store\SQL::insertOrUpdate
* @test
*/
public function testSetTableVersion()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$store->setTableVersion('kvstore', 2);
$version = $store->getTableVersion('kvstore');
@@ -78,13 +83,13 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::get
+ * @covers \SimpleSAML\Store\SQL::get
* @test
*/
public function testGetEmptyData()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$value = $store->get('test', 'foo');
@@ -92,15 +97,15 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::get
- * @covers SimpleSAML\Store\SQL::set
- * @covers SimpleSAML\Store\SQL::insertOrUpdate
+ * @covers \SimpleSAML\Store\SQL::get
+ * @covers \SimpleSAML\Store\SQL::set
+ * @covers \SimpleSAML\Store\SQL::insertOrUpdate
* @test
*/
public function testInsertData()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$store->set('test', 'foo', 'bar');
$value = $store->get('test', 'foo');
@@ -109,15 +114,15 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::get
- * @covers SimpleSAML\Store\SQL::set
- * @covers SimpleSAML\Store\SQL::insertOrUpdate
+ * @covers \SimpleSAML\Store\SQL::get
+ * @covers \SimpleSAML\Store\SQL::set
+ * @covers \SimpleSAML\Store\SQL::insertOrUpdate
* @test
*/
public function testOverwriteData()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$store->set('test', 'foo', 'bar');
$store->set('test', 'foo', 'baz');
@@ -127,16 +132,16 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::get
- * @covers SimpleSAML\Store\SQL::set
- * @covers SimpleSAML\Store\SQL::insertOrUpdate
- * @covers SimpleSAML\Store\SQL::delete
+ * @covers \SimpleSAML\Store\SQL::get
+ * @covers \SimpleSAML\Store\SQL::set
+ * @covers \SimpleSAML\Store\SQL::insertOrUpdate
+ * @covers \SimpleSAML\Store\SQL::delete
* @test
*/
public function testDeleteData()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$store->set('test', 'foo', 'bar');
$store->delete('test', 'foo');
@@ -146,16 +151,16 @@ class SQLTest extends \PHPUnit_Framework_TestCase
}
/**
- * @covers SimpleSAML\Store\SQL::get
- * @covers SimpleSAML\Store\SQL::set
- * @covers SimpleSAML\Store\SQL::insertOrUpdate
- * @covers SimpleSAML\Store\SQL::delete
+ * @covers \SimpleSAML\Store\SQL::get
+ * @covers \SimpleSAML\Store\SQL::set
+ * @covers \SimpleSAML\Store\SQL::insertOrUpdate
+ * @covers \SimpleSAML\Store\SQL::delete
* @test
*/
public function testVeryLongKey()
{
/** @var \SimpleSAML\Store\SQL $store */
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$key = str_repeat('x', 100);
$store->set('test', $key, 'bar');
@@ -167,8 +172,8 @@ class SQLTest extends \PHPUnit_Framework_TestCase
protected function tearDown()
{
- $config = SimpleSAML_Configuration::getInstance();
- $store = \SimpleSAML\Store::getInstance();
+ $config = Configuration::getInstance();
+ $store = Store::getInstance();
$this->clearInstance($config, '\SimpleSAML_Configuration');
$this->clearInstance($store, '\SimpleSAML\Store');
@@ -176,10 +181,10 @@ class SQLTest extends \PHPUnit_Framework_TestCase
protected function clearInstance($service, $className)
{
- $reflectedClass = new ReflectionClass($className);
+ $reflectedClass = new \ReflectionClass($className);
$reflectedInstance = $reflectedClass->getProperty('instance');
$reflectedInstance->setAccessible(true);
$reflectedInstance->setValue($service, null);
$reflectedInstance->setAccessible(false);
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/SimpleSAML/StoreTest.php b/tests/lib/SimpleSAML/StoreTest.php
index 2165bb4..6fd9650 100644
--- a/tests/lib/SimpleSAML/StoreTest.php
+++ b/tests/lib/SimpleSAML/StoreTest.php
@@ -1,14 +1,19 @@
<?php
-/*
- * This file is part of the sgomezsimplesamlphp.
+
+namespace SimpleSAML\Test;
+
+use \SimpleSAML_Configuration as Configuration;
+use \SimpleSAML\Store;
+
+/**
+ * Tests for the Store abstract class.
*
- * (c) Sergio Gómez <sergio@uco.es>
+ * For the full copyright and license information, please view the LICENSE file that was distributed with this source
+ * code.
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * @author Sergio Gómez <sergio@uco.es>
+ * @package simplesamlphp/simplesamlphp
*/
-
-
class StoreTest extends \PHPUnit_Framework_TestCase
{
/**
@@ -17,108 +22,115 @@ class StoreTest extends \PHPUnit_Framework_TestCase
*/
public function defaultStore()
{
- \SimpleSAML_Configuration::loadFromArray(array(
+ Configuration::loadFromArray(array(
), '[ARRAY]', 'simplesaml');
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$this->assertEquals(false, $store);
}
+
/**
* @covers \SimpleSAML\Store::getInstance
* @test
*/
public function phpSessionStore()
{
- \SimpleSAML_Configuration::loadFromArray(array(
+ Configuration::loadFromArray(array(
), '[ARRAY]', 'simplesaml');
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$this->assertEquals(false, $store);
}
+
/**
* @covers \SimpleSAML\Store::getInstance
* @test
*/
public function memcacheStore()
{
- \SimpleSAML_Configuration::loadFromArray(array(
+ Configuration::loadFromArray(array(
'store.type' => 'memcache',
), '[ARRAY]', 'simplesaml');
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$this->assertInstanceOf('\SimpleSAML\Store\Memcache', $store);
}
+
/**
- * @covers SimpleSAML\Store::getInstance
+ * @covers \SimpleSAML\Store::getInstance
* @test
*/
public function sqlStore()
{
- \SimpleSAML_Configuration::loadFromArray(array(
+ Configuration::loadFromArray(array(
'store.type' => 'sql',
'store.sql.dsn' => 'sqlite::memory:',
'store.sql.prefix' => 'phpunit_',
), '[ARRAY]', 'simplesaml');
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$this->assertInstanceOf('SimpleSAML\Store\SQL', $store);
}
+
/**
- * @covers SimpleSAML\Store::getInstance
+ * @covers \SimpleSAML\Store::getInstance
* @test
*/
public function pathStore()
{
- \SimpleSAML_Configuration::loadFromArray(array(
+ Configuration::loadFromArray(array(
'store.type' => '\SimpleSAML\Store\SQL',
'store.sql.dsn' => 'sqlite::memory:',
'store.sql.prefix' => 'phpunit_',
), '[ARRAY]', 'simplesaml');
- $store = \SimpleSAML\Store::getInstance();
+ $store = Store::getInstance();
$this->assertInstanceOf('SimpleSAML\Store\SQL', $store);
}
+
/**
- * @covers SimpleSAML\Store::getInstance
- * @expectedException SimpleSAML\Error\CriticalConfigurationError
+ * @covers \SimpleSAML\Store::getInstance
+ * @expectedException \SimpleSAML\Error\CriticalConfigurationError
* @test
*/
public function notFoundStoreException()
{
- \SimpleSAML_Configuration::loadFromArray(array(
+ Configuration::loadFromArray(array(
'store.type' => '\Test\SimpleSAML\Store\Dummy',
'store.sql.dsn' => 'sqlite::memory:',
'store.sql.prefix' => 'phpunit_',
), '[ARRAY]', 'simplesaml');
- $store = \SimpleSAML\Store::getInstance();
+ Store::getInstance();
}
-
+
+
protected function tearDown()
{
- $config = SimpleSAML_Configuration::getInstance();
- $store = \SimpleSAML\Store::getInstance();
+ $config = Configuration::getInstance();
+ $store = Store::getInstance();
$this->clearInstance($config, '\SimpleSAML_Configuration');
$this->clearInstance($store, '\SimpleSAML\Store');
}
+
protected function clearInstance($service, $className)
{
- $reflectedClass = new ReflectionClass($className);
+ $reflectedClass = new \ReflectionClass($className);
$reflectedInstance = $reflectedClass->getProperty('instance');
$reflectedInstance->setAccessible(true);
$reflectedInstance->setValue($service, null);
$reflectedInstance->setAccessible(false);
}
-} \ No newline at end of file
+}