summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/Store/SQLTest.php
diff options
context:
space:
mode:
authorJaime Pérez Crespo <jaime.perez@uninett.no>2017-01-12 10:19:06 +0100
committerJaime Pérez Crespo <jaime.perez@uninett.no>2017-01-12 10:19:06 +0100
commit98da26e110b7adbb9b819b90d946a776fb1b7ab7 (patch)
treeb45e12a9b4c6b7a881233ab95e9f56a86297aa20 /tests/lib/SimpleSAML/Store/SQLTest.php
parentff3df0733e7ca3e810c348e0fc2fb2ccf7a9ba66 (diff)
parente1d57b8374827be957c8265a6c76e0b4f54e7094 (diff)
downloadsimplesamlphp-98da26e110b7adbb9b819b90d946a776fb1b7ab7.zip
simplesamlphp-98da26e110b7adbb9b819b90d946a776fb1b7ab7.tar.gz
simplesamlphp-98da26e110b7adbb9b819b90d946a776fb1b7ab7.tar.bz2
Merge branch 'store-psr4' of https://github.com/sgomez/simplesamlphp into sgomez-store-psr4
Diffstat (limited to 'tests/lib/SimpleSAML/Store/SQLTest.php')
-rw-r--r--tests/lib/SimpleSAML/Store/SQLTest.php185
1 files changed, 185 insertions, 0 deletions
diff --git a/tests/lib/SimpleSAML/Store/SQLTest.php b/tests/lib/SimpleSAML/Store/SQLTest.php
new file mode 100644
index 0000000..3318754
--- /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