diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php
index cfd8307605accaf6146bdb146f6f8a4ffeaa2627..f6c4300c3ee7ac3daad53b4e574594bf7195fada 100644
--- a/lib/SimpleSAML/SessionHandler.php
+++ b/lib/SimpleSAML/SessionHandler.php
@@ -118,11 +118,11 @@ abstract class SimpleSAML_SessionHandler
     private static function createSessionHandler()
     {
 
-        $store = SimpleSAML_Store::getInstance();
+        $store = \SimpleSAML\Store::getInstance();
         if ($store === false) {
             self::$sessionHandler = new SimpleSAML_SessionHandlerPHP();
         } else {
-            /** @var SimpleSAML_Store $store At this point, $store can only be an object */
+            /** @var \SimpleSAML\Store $store At this point, $store can only be an object */
             self::$sessionHandler = new SimpleSAML_SessionHandlerStore($store);
         }
     }
diff --git a/lib/SimpleSAML/SessionHandlerStore.php b/lib/SimpleSAML/SessionHandlerStore.php
index 90068808ce305d782fbdfcd6ac4cc4f6269148e3..002e7ffc189648d2a53fb3454fc7b601a3536eae 100644
--- a/lib/SimpleSAML/SessionHandlerStore.php
+++ b/lib/SimpleSAML/SessionHandlerStore.php
@@ -12,7 +12,7 @@ class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie
     /**
      * The data store we save the session to.
      *
-     * @var SimpleSAML_Store
+     * @var \SimpleSAML\Store
      */
     private $store;
 
@@ -20,9 +20,9 @@ class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie
     /**
      * Initialize the session.
      *
-     * @param SimpleSAML_Store $store The store to use.
+     * @param \SimpleSAML\Store $store The store to use.
      */
-    protected function __construct(SimpleSAML_Store $store)
+    protected function __construct(\SimpleSAML\Store $store)
     {
         parent::__construct();
 
diff --git a/lib/SimpleSAML/Store.php b/lib/SimpleSAML/Store.php
index 6a51c1e6c904f65cb6324e7cfa009270c3d63ee1..1aa1d1167616fbcabebe1bce66800a9519aa7f66 100644
--- a/lib/SimpleSAML/Store.php
+++ b/lib/SimpleSAML/Store.php
@@ -1,12 +1,16 @@
 <?php
 
+namespace SimpleSAML;
+
+
+use SimpleSAML\Error\CriticalConfigurationError;
 
 /**
  * Base class for data stores.
  *
  * @package SimpleSAMLphp
  */
-abstract class SimpleSAML_Store
+abstract class Store
 {
 
     /**
@@ -14,7 +18,7 @@ abstract class SimpleSAML_Store
      *
      * This is false if the data store isn't enabled, and null if we haven't attempted to initialize it.
      *
-     * @var SimpleSAML_Store|false|null
+     * @var Store|false|null
      */
     private static $instance;
 
@@ -22,7 +26,9 @@ abstract class SimpleSAML_Store
     /**
      * Retrieve our singleton instance.
      *
-     * @return SimpleSAML_Store|false  The data store, or false if it isn't enabled.
+     * @return false|Store The data store, or false if it isn't enabled.
+     *
+     * @throws CriticalConfigurationError
      */
     public static function getInstance()
     {
@@ -31,7 +37,7 @@ abstract class SimpleSAML_Store
             return self::$instance;
         }
 
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
         $storeType = $config->getString('store.type', null);
         if ($storeType === null) {
             $storeType = $config->getString('session.handler', 'phpsession');
@@ -43,19 +49,19 @@ abstract class SimpleSAML_Store
                 self::$instance = false;
                 break;
             case 'memcache':
-                self::$instance = new SimpleSAML_Store_Memcache();
+                self::$instance = new Store\Memcache();
                 break;
             case 'sql':
-                self::$instance = new SimpleSAML_Store_SQL();
+                self::$instance = new Store\SQL();
                 break;
             default:
                 // datastore from module
                 try {
-                    $className = SimpleSAML\Module::resolveClass($storeType, 'Store', 'SimpleSAML_Store');
-                } catch (Exception $e) {
+                    $className = Module::resolveClass($storeType, 'Store', '\SimpleSAML\Store');
+                } catch (\Exception $e) {
                     $c = $config->toArray();
                     $c['store.type'] = 'phpsession';
-                    throw new SimpleSAML\Error\CriticalConfigurationError(
+                    throw new CriticalConfigurationError(
                         "Invalid 'store.type' configuration option. Cannot find store '$storeType'.",
                         null,
                         $c
diff --git a/lib/SimpleSAML/Store/Memcache.php b/lib/SimpleSAML/Store/Memcache.php
index ea5187ad130d2852bccfa45a9072c9042470d028..c4bdd02e8a3096dde067288202d8e323601bf1bd 100644
--- a/lib/SimpleSAML/Store/Memcache.php
+++ b/lib/SimpleSAML/Store/Memcache.php
@@ -1,11 +1,15 @@
 <?php
 
+namespace SimpleSAML\Store;
+
+use SimpleSAML\Store;
+
 /**
  * A memcache based datastore.
  *
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Store_Memcache extends SimpleSAML_Store
+class Memcache extends Store
 {
     /**
      * Initialize the memcache datastore.
@@ -22,7 +26,7 @@ class SimpleSAML_Store_Memcache extends SimpleSAML_Store
      * This function implements the constructor for this class. It loads the Memcache configuration.
      */
     protected function __construct() {
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
         $this->prefix = $config->getString('memcache_store.prefix', 'simpleSAMLphp');
     }
 
@@ -39,7 +43,7 @@ class SimpleSAML_Store_Memcache extends SimpleSAML_Store
         assert('is_string($type)');
         assert('is_string($key)');
 
-        return SimpleSAML_Memcache::get($this->prefix . '.' . $type . '.' . $key);
+        return \SimpleSAML_Memcache::get($this->prefix . '.' . $type . '.' . $key);
     }
 
 
@@ -61,7 +65,7 @@ class SimpleSAML_Store_Memcache extends SimpleSAML_Store
             $expire = 0;
         }
 
-        SimpleSAML_Memcache::set($this->prefix . '.' . $type . '.' . $key, $value, $expire);
+        \SimpleSAML_Memcache::set($this->prefix . '.' . $type . '.' . $key, $value, $expire);
     }
 
 
@@ -76,6 +80,6 @@ class SimpleSAML_Store_Memcache extends SimpleSAML_Store
         assert('is_string($type)');
         assert('is_string($key)');
 
-        SimpleSAML_Memcache::delete($this->prefix . '.' . $type . '.' . $key);
+        \SimpleSAML_Memcache::delete($this->prefix . '.' . $type . '.' . $key);
     }
 }
diff --git a/lib/SimpleSAML/Store/SQL.php b/lib/SimpleSAML/Store/SQL.php
index 41ed260fa34ab70d700556852d8c1e2cf873bc7c..b6cf384f8732706e10d709218b0e5d05a66905b6 100644
--- a/lib/SimpleSAML/Store/SQL.php
+++ b/lib/SimpleSAML/Store/SQL.php
@@ -1,18 +1,23 @@
 <?php
 
+namespace SimpleSAML\Store;
+
+use SimpleSAML\Logger;
+use SimpleSAML\Store;
+
 
 /**
  * A data store using a RDBMS to keep the data.
  *
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Store_SQL extends SimpleSAML_Store
+class SQL extends Store
 {
 
     /**
      * The PDO object for our database.
      *
-     * @var PDO
+     * @var \PDO
      */
     public $pdo;
 
@@ -46,17 +51,17 @@ class SimpleSAML_Store_SQL extends SimpleSAML_Store
      */
     protected function __construct()
     {
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
 
         $dsn = $config->getString('store.sql.dsn');
         $username = $config->getString('store.sql.username', null);
         $password = $config->getString('store.sql.password', null);
         $this->prefix = $config->getString('store.sql.prefix', 'simpleSAMLphp');
 
-        $this->pdo = new PDO($dsn, $username, $password);
-        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+        $this->pdo = new \PDO($dsn, $username, $password);
+        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
 
-        $this->driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
+        $this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
 
         if ($this->driver === 'mysql') {
             $this->pdo->exec('SET time_zone = "+00:00"');
@@ -76,7 +81,7 @@ class SimpleSAML_Store_SQL extends SimpleSAML_Store
 
         try {
             $fetchTableVersion = $this->pdo->query('SELECT _name, _version FROM '.$this->prefix.'_tableVersion');
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             $this->pdo->exec(
                 'CREATE TABLE '.$this->prefix.
                 '_tableVersion (_name VARCHAR(30) NOT NULL UNIQUE, _version INTEGER NOT NULL)'
@@ -84,7 +89,7 @@ class SimpleSAML_Store_SQL extends SimpleSAML_Store
             return;
         }
 
-        while (($row = $fetchTableVersion->fetch(PDO::FETCH_ASSOC)) !== false) {
+        while (($row = $fetchTableVersion->fetch(\PDO::FETCH_ASSOC)) !== false) {
             $this->tableVersions[$row['_name']] = (int) $row['_version'];
         }
     }
@@ -193,13 +198,13 @@ class SimpleSAML_Store_SQL extends SimpleSAML_Store
         try {
             $insertQuery->execute($data);
             return;
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             $ecode = (string) $e->getCode();
             switch ($ecode) {
                 case '23505': // PostgreSQL
                     break;
                 default:
-                    SimpleSAML\Logger::error('Error while saving data: '.$e->getMessage());
+                    Logger::error('Error while saving data: '.$e->getMessage());
                     throw $e;
             }
         }
@@ -229,7 +234,7 @@ class SimpleSAML_Store_SQL extends SimpleSAML_Store
     private function cleanKVStore()
     {
 
-        SimpleSAML\Logger::debug('store.sql: Cleaning key-value store.');
+        Logger::debug('store.sql: Cleaning key-value store.');
 
         $query = 'DELETE FROM '.$this->prefix.'_kvstore WHERE _expire < :now';
         $params = array('now' => gmdate('Y-m-d H:i:s'));
@@ -263,7 +268,7 @@ class SimpleSAML_Store_SQL extends SimpleSAML_Store
         $query = $this->pdo->prepare($query);
         $query->execute($params);
 
-        $row = $query->fetch(PDO::FETCH_ASSOC);
+        $row = $query->fetch(\PDO::FETCH_ASSOC);
         if ($row === false) {
             return null;
         }
diff --git a/modules/riak/lib/Store/Store.php b/modules/riak/lib/Store/Store.php
index 2127ffc50a8e34fbc3c210631f6872d1fea8fc07..fae12f46deb4a1b2b01e4fe52daf903c368e3b3e 100644
--- a/modules/riak/lib/Store/Store.php
+++ b/modules/riak/lib/Store/Store.php
@@ -22,7 +22,7 @@
  * and Information Technology.
  */
 
-class sspmod_riak_Store_Store extends SimpleSAML_Store {
+class sspmod_riak_Store_Store extends SimpleSAML\Store {
 	protected function __construct() {
 		$config = SimpleSAML_Configuration::getConfig('module_riak.php');
 
@@ -32,7 +32,7 @@ class sspmod_riak_Store_Store extends SimpleSAML_Store {
 		$bucket = $config->getString('bucket', 'simpleSAMLphp');
 
 		require_once($path);
-		$this->client = new RiakClient($host, $port);
+		$this->client = new \RiakClient($host, $port);
 		$this->bucket = $this->client->bucket($bucket);
 	}
 
diff --git a/modules/saml/lib/IdP/SQLNameID.php b/modules/saml/lib/IdP/SQLNameID.php
index 641cece938b18e917e5eb623452ce2e38ca14d13..7b8a06a4e338691773debff6d9d7ad684702a678 100644
--- a/modules/saml/lib/IdP/SQLNameID.php
+++ b/modules/saml/lib/IdP/SQLNameID.php
@@ -10,9 +10,9 @@ class sspmod_saml_IdP_SQLNameID  {
 	/**
 	 * Create NameID table in SQL, if it is missing.
 	 *
-	 * @param SimpleSAML_Store_SQL $store  The datastore.
+	 * @param \SimpleSAML\Store\SQL $store  The datastore.
 	 */
-	private static function createTable(SimpleSAML_Store_SQL $store) {
+	private static function createTable(\SimpleSAML\Store\SQL $store) {
 
 		if ($store->getTableVersion('saml_PersistentNameID') === 1) {
 			return;
@@ -39,12 +39,12 @@ class sspmod_saml_IdP_SQLNameID  {
 	 *
 	 * Will also ensure that the NameID table is present.
 	 *
-	 * @return SimpleSAML_Store_SQL  SQL datastore.
+	 * @return \SimpleSAML\Store\SQL  SQL datastore.
 	 */
 	private static function getStore() {
 
-		$store = SimpleSAML_Store::getInstance();
-		if (!($store instanceof SimpleSAML_Store_SQL)) {
+		$store = \SimpleSAML\Store::getInstance();
+		if (!($store instanceof \SimpleSAML\Store\SQL)) {
 			throw new SimpleSAML_Error_Exception('SQL NameID store requires SimpleSAMLphp to be configured with a SQL datastore.');
 		}
 
@@ -57,7 +57,7 @@ class sspmod_saml_IdP_SQLNameID  {
 	/**
 	 * Add a NameID into the database.
 	 *
-	 * @param SimpleSAML_Store_SQL $store  The data store.
+	 * @param \SimpleSAML\Store\SQL $store  The data store.
 	 * @param string $idpEntityId  The IdP entityID.
 	 * @param string $spEntityId  The SP entityID.
 	 * @param string $user  The user's unique identificator (e.g. username).
diff --git a/modules/saml/lib/SP/LogoutStore.php b/modules/saml/lib/SP/LogoutStore.php
index f56b2bedb44e765afb6a021bdda43c8ddaf8fcf1..73746c2777600327740ab03c2056d2b3d3be6f8f 100644
--- a/modules/saml/lib/SP/LogoutStore.php
+++ b/modules/saml/lib/SP/LogoutStore.php
@@ -10,9 +10,9 @@ class sspmod_saml_SP_LogoutStore {
 	/**
 	 * Create logout table in SQL, if it is missing.
 	 *
-	 * @param SimpleSAML_Store_SQL $store  The datastore.
+	 * @param \SimpleSAML\Store\SQL $store  The datastore.
 	 */
-	private static function createLogoutTable(SimpleSAML_Store_SQL $store) {
+	private static function createLogoutTable(\SimpleSAML\Store\SQL $store) {
 
 		if ($store->getTableVersion('saml_LogoutStore') === 1) {
 			return;
@@ -41,9 +41,9 @@ class sspmod_saml_SP_LogoutStore {
 	/**
 	 * Clean the logout table of expired entries.
 	 *
-	 * @param SimpleSAML_Store_SQL $store  The datastore.
+	 * @param \SimpleSAML\Store\SQL $store  The datastore.
 	 */
-	private static function cleanLogoutStore(SimpleSAML_Store_SQL $store) {
+	private static function cleanLogoutStore(\SimpleSAML\Store\SQL $store) {
 
 		SimpleSAML\Logger::debug('saml.LogoutStore: Cleaning logout store.');
 
@@ -58,12 +58,12 @@ class sspmod_saml_SP_LogoutStore {
 	/**
 	 * Register a session in the SQL datastore.
 	 *
-	 * @param SimpleSAML_Store_SQL $store  The datastore.
+	 * @param \SimpleSAML\Store\SQL $store  The datastore.
 	 * @param string $authId  The authsource ID.
 	 * @param string $nameId  The hash of the users NameID.
 	 * @param string $sessionIndex  The SessionIndex of the user.
 	 */
-	private static function addSessionSQL(SimpleSAML_Store_SQL $store, $authId, $nameId, $sessionIndex, $expire, $sessionId) {
+	private static function addSessionSQL(\SimpleSAML\Store\SQL $store, $authId, $nameId, $sessionIndex, $expire, $sessionId) {
 		assert('is_string($authId)');
 		assert('is_string($nameId)');
 		assert('is_string($sessionIndex)');
@@ -90,12 +90,12 @@ class sspmod_saml_SP_LogoutStore {
 	/**
 	 * Retrieve sessions from the SQL datastore.
 	 *
-	 * @param SimpleSAML_Store_SQL $store  The datastore.
+	 * @param \SimpleSAML\Store\SQL $store  The datastore.
 	 * @param string $authId  The authsource ID.
 	 * @param string $nameId  The hash of the users NameID.
 	 * @return array  Associative array of SessionIndex =>  SessionId.
 	 */
-	private static function getSessionsSQL(SimpleSAML_Store_SQL $store, $authId, $nameId) {
+	private static function getSessionsSQL(\SimpleSAML\Store\SQL $store, $authId, $nameId) {
 		assert('is_string($authId)');
 		assert('is_string($nameId)');
 
@@ -125,13 +125,13 @@ class sspmod_saml_SP_LogoutStore {
 	/**
 	 * Retrieve all session IDs from a key-value store.
 	 *
-	 * @param SimpleSAML_Store $store  The datastore.
+	 * @param \SimpleSAML\Store $store  The datastore.
 	 * @param string $authId  The authsource ID.
 	 * @param string $nameId  The hash of the users NameID.
 	 * @param array $sessionIndexes  The session indexes.
 	 * @return array  Associative array of SessionIndex =>  SessionId.
 	 */
-	private static function getSessionsStore(SimpleSAML_Store $store, $authId, $nameId, array $sessionIndexes) {
+	private static function getSessionsStore(\SimpleSAML\Store $store, $authId, $nameId, array $sessionIndexes) {
 		assert('is_string($authId)');
 		assert('is_string($nameId)');
 
@@ -170,7 +170,7 @@ class sspmod_saml_SP_LogoutStore {
 			$sessionIndex = SimpleSAML\Utils\Random::generateID();
 		}
 
-		$store = SimpleSAML_Store::getInstance();
+		$store = \SimpleSAML\Store::getInstance();
 		if ($store === FALSE) {
 			// We don't have a datastore.
 			return;
@@ -189,7 +189,7 @@ class sspmod_saml_SP_LogoutStore {
 		$session = SimpleSAML_Session::getSessionFromRequest();
 		$sessionId = $session->getSessionId();
 
-		if ($store instanceof SimpleSAML_Store_SQL) {
+		if ($store instanceof \SimpleSAML\Store\SQL) {
 			self::addSessionSQL($store, $authId, $strNameId, $sessionIndex, $expire, $sessionId);
 		} else {
 			$store->set('saml.LogoutStore', $strNameId . ':' . $sessionIndex, $sessionId, $expire);
@@ -208,7 +208,7 @@ class sspmod_saml_SP_LogoutStore {
 	public static function logoutSessions($authId, array $nameId, array $sessionIndexes) {
 		assert('is_string($authId)');
 
-		$store = SimpleSAML_Store::getInstance();
+		$store = \SimpleSAML\Store::getInstance();
 		if ($store === FALSE) {
 			/* We don't have a datastore. */
 			return FALSE;
@@ -228,13 +228,13 @@ class sspmod_saml_SP_LogoutStore {
 		}
 		unset($sessionIndex); // Remove reference
 
-		if ($store instanceof SimpleSAML_Store_SQL) {
+		if ($store instanceof \SimpleSAML\Store\SQL) {
 			$sessions = self::getSessionsSQL($store, $authId, $strNameId);
 		} elseif (empty($sessionIndexes)) {
 			/* We cannot fetch all sessions without a SQL store. */
 			return FALSE;
 		} else {
-			/** @var SimpleSAML_Store $sessions At this point the store cannot be false */
+			/** @var \SimpleSAML\Store $sessions At this point the store cannot be false */
 			$sessions = self::getSessionsStore($store, $authId, $strNameId, $sessionIndexes);
 
 		}
diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index 781d00703198f21c5b0811ef76d2fc1e38cf3bca..9aa17835e25aaa0361f5275b5f17079af62d7d7d 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -21,7 +21,7 @@ if (!($source instanceof sspmod_saml_Auth_Source_SP)) {
 
 $entityId = $source->getEntityId();
 $spconfig = $source->getMetadata();
-$store = SimpleSAML_Store::getInstance();
+$store = \SimpleSAML\Store::getInstance();
 
 $metaArray20 = array();
 
@@ -34,7 +34,7 @@ $slob = $spconfig->getArray('SingleLogoutServiceBinding', $slosvcdefault);
 $slol = SimpleSAML\Module::getModuleURL('saml/sp/saml2-logout.php/'.$sourceId);
 
 foreach ($slob as $binding) {
-    if ($binding == \SAML2\Constants::BINDING_SOAP && !($store instanceof SimpleSAML_Store_SQL)) {
+    if ($binding == \SAML2\Constants::BINDING_SOAP && !($store instanceof \SimpleSAML\Store\SQL)) {
         // we cannot properly support SOAP logout
         continue;
     }
diff --git a/modules/saml/www/sp/saml2-acs.php b/modules/saml/www/sp/saml2-acs.php
index 264a5445ff182cbfb6b8942725efb23c8029ede1..e98f60b4232eb203b6e3e9199c94c6db9bbec2c4 100644
--- a/modules/saml/www/sp/saml2-acs.php
+++ b/modules/saml/www/sp/saml2-acs.php
@@ -134,7 +134,7 @@ $foundAuthnStatement = false;
 foreach ($assertions as $assertion) {
 
     // check for duplicate assertion (replay attack)
-    $store = SimpleSAML_Store::getInstance();
+    $store = \SimpleSAML\Store::getInstance();
     if ($store !== false) {
         $aID = $assertion->getId();
         if ($store->get('saml.AssertionReceived', $aID) !== null) {
diff --git a/tests/lib/SimpleSAML/Store/SQLTest.php b/tests/lib/SimpleSAML/Store/SQLTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..33187547c0a6ef2a7ff8c99df5f530c06fd48cb6
--- /dev/null
+++ b/tests/lib/SimpleSAML/Store/SQLTest.php
@@ -0,0 +1,185 @@
+<?php
+/*
+ * This file is part of the sgomezsimplesamlphp.
+ *
+ * (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.
+ */
+
+
+class SQLTest extends \PHPUnit_Framework_TestCase
+{
+    protected function setUp()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+            'store.type'                    => 'sql',
+            'store.sql.dsn'                 => 'sqlite::memory:',
+            'store.sql.prefix'              => 'phpunit_',
+        ), '[ARRAY]', 'simplesaml');
+    }
+
+    /**
+     * @covers SimpleSAML\Store::getInstance
+     * @covers SimpleSAML\Store\SQL::__construct
+     * @test
+     */
+    public function SQLInstance()
+    {
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->assertInstanceOf('SimpleSAML\Store\SQL', $store);
+    }
+
+    /**
+     * @covers SimpleSAML\Store\SQL::initTableVersionTable
+     * @covers SimpleSAML\Store\SQL::initKVTable
+     * @test
+     */
+    public function kvstoreTableVersion()
+    {
+        /** @var \SimpleSAML\Store\SQL $store */
+        $store = \SimpleSAML\Store::getInstance();
+
+        $version = $store->getTableVersion('kvstore');
+
+        $this->assertEquals(1, $version);
+    }
+
+    /**
+     * @covers SimpleSAML\Store\SQL::getTableVersion
+     * @test
+     */
+    public function newTableVersion()
+    {
+        /** @var \SimpleSAML\Store\SQL $store */
+        $store = \SimpleSAML\Store::getInstance();
+
+        $version = $store->getTableVersion('test');
+
+        $this->assertEquals(0, $version);
+    }
+
+    /**
+     * @covers SimpleSAML\Store\SQL::setTableVersion
+     * @covers SimpleSAML\Store\SQL::insertOrUpdate
+     * @test
+     */
+    public function testSetTableVersion()
+    {
+        /** @var \SimpleSAML\Store\SQL $store */
+        $store = \SimpleSAML\Store::getInstance();
+
+        $store->setTableVersion('kvstore', 2);
+        $version = $store->getTableVersion('kvstore');
+
+        $this->assertEquals(2, $version);
+    }
+
+    /**
+     * @covers SimpleSAML\Store\SQL::get
+     * @test
+     */
+    public function testGetEmptyData()
+    {
+        /** @var \SimpleSAML\Store\SQL $store */
+        $store = \SimpleSAML\Store::getInstance();
+
+        $value = $store->get('test', 'foo');
+
+        $this->assertEquals(null, $value);
+    }
+
+    /**
+     * @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->set('test', 'foo', 'bar');
+        $value = $store->get('test', 'foo');
+        
+        $this->assertEquals('bar', $value);
+    }
+
+    /**
+     * @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->set('test', 'foo', 'bar');
+        $store->set('test', 'foo', 'baz');
+        $value = $store->get('test', 'foo');
+
+        $this->assertEquals('baz', $value);
+    }
+
+    /**
+     * @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->set('test', 'foo', 'bar');
+        $store->delete('test', 'foo');
+        $value = $store->get('test', 'foo');
+
+        $this->assertEquals(null, $value);
+    }
+
+    /**
+     * @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();
+
+        $key = str_repeat('x', 100);
+        $store->set('test', $key, 'bar');
+        $store->delete('test', $key);
+        $value = $store->get('test', $key);
+
+        $this->assertEquals(null, $value);
+    }
+
+    protected function tearDown()
+    {
+        $config = SimpleSAML_Configuration::getInstance();
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->clearInstance($config, '\SimpleSAML_Configuration');
+        $this->clearInstance($store, '\SimpleSAML\Store');
+    }
+
+    protected function clearInstance($service, $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
new file mode 100644
index 0000000000000000000000000000000000000000..2165bb4e79eea62727345189128c33f377538c4d
--- /dev/null
+++ b/tests/lib/SimpleSAML/StoreTest.php
@@ -0,0 +1,124 @@
+<?php
+/*
+ * This file is part of the sgomezsimplesamlphp.
+ *
+ * (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.
+ */
+
+
+class StoreTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @covers \SimpleSAML\Store::getInstance
+     * @test
+     */
+    public function defaultStore()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+        ), '[ARRAY]', 'simplesaml');
+
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->assertEquals(false, $store);
+    }
+
+    /**
+     * @covers \SimpleSAML\Store::getInstance
+     * @test
+     */
+    public function phpSessionStore()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+        ), '[ARRAY]', 'simplesaml');
+
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->assertEquals(false, $store);
+    }
+
+    /**
+     * @covers \SimpleSAML\Store::getInstance
+     * @test
+     */
+    public function memcacheStore()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+            'store.type'                    => 'memcache',
+        ), '[ARRAY]', 'simplesaml');
+
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->assertInstanceOf('\SimpleSAML\Store\Memcache', $store);
+    }
+
+    /**
+     * @covers SimpleSAML\Store::getInstance
+     * @test
+     */
+    public function sqlStore()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+            'store.type'                    => 'sql',
+            'store.sql.dsn'                 => 'sqlite::memory:',
+            'store.sql.prefix'              => 'phpunit_',
+        ), '[ARRAY]', 'simplesaml');
+
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->assertInstanceOf('SimpleSAML\Store\SQL', $store);
+    }
+
+    /**
+     * @covers SimpleSAML\Store::getInstance
+     * @test
+     */
+    public function pathStore()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+            'store.type'                    => '\SimpleSAML\Store\SQL',
+            'store.sql.dsn'                 => 'sqlite::memory:',
+            'store.sql.prefix'              => 'phpunit_',
+        ), '[ARRAY]', 'simplesaml');
+
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->assertInstanceOf('SimpleSAML\Store\SQL', $store);
+    }
+
+    /**
+     * @covers SimpleSAML\Store::getInstance
+     * @expectedException SimpleSAML\Error\CriticalConfigurationError
+     * @test
+     */
+    public function notFoundStoreException()
+    {
+        \SimpleSAML_Configuration::loadFromArray(array(
+            'store.type'                    => '\Test\SimpleSAML\Store\Dummy',
+            'store.sql.dsn'                 => 'sqlite::memory:',
+            'store.sql.prefix'              => 'phpunit_',
+        ), '[ARRAY]', 'simplesaml');
+
+        $store = \SimpleSAML\Store::getInstance();
+    }
+    
+    protected function tearDown()
+    {
+        $config = SimpleSAML_Configuration::getInstance();
+        $store = \SimpleSAML\Store::getInstance();
+
+        $this->clearInstance($config, '\SimpleSAML_Configuration');
+        $this->clearInstance($store, '\SimpleSAML\Store');
+    }
+
+    protected function clearInstance($service, $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/www/saml2/idp/ArtifactResolutionService.php b/www/saml2/idp/ArtifactResolutionService.php
index 1bdf8110dd1d3d51599231af5ccc2b4cf217e94c..39f705e657f8b01d3f54dc5768460655ddea78c0 100644
--- a/www/saml2/idp/ArtifactResolutionService.php
+++ b/www/saml2/idp/ArtifactResolutionService.php
@@ -23,7 +23,7 @@ if (!$idpMetadata->getBoolean('saml20.sendartifact', false)) {
     throw new SimpleSAML_Error_Error('NOACCESS');
 }
 
-$store = SimpleSAML_Store::getInstance();
+$store = \SimpleSAML\Store::getInstance();
 if ($store === false) {
     throw new Exception('Unable to send artifact without a datastore configured.');
 }