Skip to content
Snippets Groups Projects
Commit 0ffe55f2 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

tests: Rationalize stores

parent 7e1539aa
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ use SimpleSAML\Store; ...@@ -17,7 +17,7 @@ use SimpleSAML\Store;
* For the full copyright and license information, please view the LICENSE file that was distributed with this source * For the full copyright and license information, please view the LICENSE file that was distributed with this source
* code. * code.
* *
* @covers \SimpleSAML\Store\Redis * @covers \SimpleSAML\Store\RedisStore
* @package simplesamlphp/simplesamlphp * @package simplesamlphp/simplesamlphp
*/ */
class RedisTest extends TestCase class RedisTest extends TestCase
...@@ -25,8 +25,8 @@ class RedisTest extends TestCase ...@@ -25,8 +25,8 @@ class RedisTest extends TestCase
/** @var \PHPUnit\Framework\MockObject\MockObject */ /** @var \PHPUnit\Framework\MockObject\MockObject */
protected MockObject $mocked_redis; protected MockObject $mocked_redis;
/** @var \SimpleSAML\Store\Redis */ /** @var \SimpleSAML\Store\RedisStore */
protected Store\Redis $redis; protected Store\RedisStore $redis;
/** @var array */ /** @var array */
protected array $config; protected array $config;
...@@ -63,7 +63,7 @@ class RedisTest extends TestCase ...@@ -63,7 +63,7 @@ class RedisTest extends TestCase
->will($this->returnCallback($nop)); ->will($this->returnCallback($nop));
/** @var \Predis\Client $this->mocked_redis */ /** @var \Predis\Client $this->mocked_redis */
$this->redis = new Store\Redis($this->mocked_redis); $this->redis = new Store\RedisStore($this->mocked_redis);
} }
...@@ -118,13 +118,13 @@ class RedisTest extends TestCase ...@@ -118,13 +118,13 @@ class RedisTest extends TestCase
'store.redis.prefix' => 'phpunit_', 'store.redis.prefix' => 'phpunit_',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
/** @var \SimpleSAML\Store\Redis $store */ /** @var \SimpleSAML\Store\RedisStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\Redis::class, $store); $this->assertInstanceOf(Store\RedisStore::class, $store);
$this->clearInstance($config, Configuration::class); $this->clearInstance($config, Configuration::class);
$this->clearInstance($store, Store::class); // $this->clearInstance($store, Store::class);
} }
...@@ -139,13 +139,13 @@ class RedisTest extends TestCase ...@@ -139,13 +139,13 @@ class RedisTest extends TestCase
'store.redis.password' => 'password', 'store.redis.password' => 'password',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
/** @var \SimpleSAML\Store\Redis $store */ /** @var \SimpleSAML\Store\RedisStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\Redis::class, $store); $this->assertInstanceOf(Store\RedisStore::class, $store);
$this->clearInstance($config, Configuration::class); $this->clearInstance($config, Configuration::class);
$this->clearInstance($store, Store::class); // $this->clearInstance($store, Store::class);
} }
...@@ -221,7 +221,7 @@ class RedisTest extends TestCase ...@@ -221,7 +221,7 @@ class RedisTest extends TestCase
/** /**
* @param \SimpleSAML\Configuration|\SimpleSAML\Store $service * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
* @param class-string $className * @param class-string $className
*/ */
protected function clearInstance($service, string $className): void protected function clearInstance($service, string $className): void
......
...@@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase; ...@@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase;
use ReflectionClass; use ReflectionClass;
use SimpleSAML\Configuration; use SimpleSAML\Configuration;
use SimpleSAML\Store; use SimpleSAML\Store;
use SimpleSAML\Store\StoreFactory;
/** /**
* Tests for the SQL store. * Tests for the SQL store.
...@@ -15,7 +16,7 @@ use SimpleSAML\Store; ...@@ -15,7 +16,7 @@ use SimpleSAML\Store;
* For the full copyright and license information, please view the LICENSE file that was distributed with this source * For the full copyright and license information, please view the LICENSE file that was distributed with this source
* code. * code.
* *
* @covers \SimpleSAML\Store\SQL * @covers \SimpleSAML\Store\SQLStore
* *
* @package simplesamlphp/simplesamlphp * @package simplesamlphp/simplesamlphp
*/ */
...@@ -38,7 +39,7 @@ class SQLTest extends TestCase ...@@ -38,7 +39,7 @@ class SQLTest extends TestCase
*/ */
public function SQLInstance(): void public function SQLInstance(): void
{ {
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\SQL::class, $store); $this->assertInstanceOf(Store\SQL::class, $store);
} }
...@@ -49,8 +50,8 @@ class SQLTest extends TestCase ...@@ -49,8 +50,8 @@ class SQLTest extends TestCase
*/ */
public function kvstoreTableVersion(): void public function kvstoreTableVersion(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$version = $store->getTableVersion('kvstore'); $version = $store->getTableVersion('kvstore');
...@@ -63,8 +64,8 @@ class SQLTest extends TestCase ...@@ -63,8 +64,8 @@ class SQLTest extends TestCase
*/ */
public function newTableVersion(): void public function newTableVersion(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$version = $store->getTableVersion('test'); $version = $store->getTableVersion('test');
...@@ -77,8 +78,8 @@ class SQLTest extends TestCase ...@@ -77,8 +78,8 @@ class SQLTest extends TestCase
*/ */
public function testSetTableVersion(): void public function testSetTableVersion(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$store->setTableVersion('kvstore', 2); $store->setTableVersion('kvstore', 2);
$version = $store->getTableVersion('kvstore'); $version = $store->getTableVersion('kvstore');
...@@ -92,8 +93,8 @@ class SQLTest extends TestCase ...@@ -92,8 +93,8 @@ class SQLTest extends TestCase
*/ */
public function testGetEmptyData(): void public function testGetEmptyData(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$value = $store->get('test', 'foo'); $value = $store->get('test', 'foo');
...@@ -106,8 +107,8 @@ class SQLTest extends TestCase ...@@ -106,8 +107,8 @@ class SQLTest extends TestCase
*/ */
public function testInsertData(): void public function testInsertData(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$store->set('test', 'foo', 'bar'); $store->set('test', 'foo', 'bar');
$value = $store->get('test', 'foo'); $value = $store->get('test', 'foo');
...@@ -121,8 +122,8 @@ class SQLTest extends TestCase ...@@ -121,8 +122,8 @@ class SQLTest extends TestCase
*/ */
public function testOverwriteData(): void public function testOverwriteData(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$store->set('test', 'foo', 'bar'); $store->set('test', 'foo', 'bar');
$store->set('test', 'foo', 'baz'); $store->set('test', 'foo', 'baz');
...@@ -137,8 +138,8 @@ class SQLTest extends TestCase ...@@ -137,8 +138,8 @@ class SQLTest extends TestCase
*/ */
public function testDeleteData(): void public function testDeleteData(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$store->set('test', 'foo', 'bar'); $store->set('test', 'foo', 'bar');
$store->delete('test', 'foo'); $store->delete('test', 'foo');
...@@ -153,8 +154,8 @@ class SQLTest extends TestCase ...@@ -153,8 +154,8 @@ class SQLTest extends TestCase
*/ */
public function testVeryLongKey(): void public function testVeryLongKey(): void
{ {
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$key = str_repeat('x', 100); $key = str_repeat('x', 100);
$store->set('test', $key, 'bar'); $store->set('test', $key, 'bar');
...@@ -171,16 +172,16 @@ class SQLTest extends TestCase ...@@ -171,16 +172,16 @@ class SQLTest extends TestCase
{ {
$config = Configuration::getInstance(); $config = Configuration::getInstance();
/** @var \SimpleSAML\Store\SQL $store */ /** @var \SimpleSAML\Store\SQLStore $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->clearInstance($config, Configuration::class); $this->clearInstance($config, Configuration::class);
$this->clearInstance($store, Store::class); // $this->clearInstance($store, Store\SQL::class);
} }
/** /**
* @param \SimpleSAML\Configuration|\SimpleSAML\Store $service * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
* @param class-string $className * @param class-string $className
*/ */
protected function clearInstance($service, string $className): void protected function clearInstance($service, string $className): void
......
...@@ -9,15 +9,15 @@ use ReflectionClass; ...@@ -9,15 +9,15 @@ use ReflectionClass;
use SimpleSAML\Configuration; use SimpleSAML\Configuration;
use SimpleSAML\Error\CriticalConfigurationError; use SimpleSAML\Error\CriticalConfigurationError;
use SimpleSAML\Store; use SimpleSAML\Store;
use SimpleSAML\Store\StoreFactory;
/** /**
* Tests for the Store abstract class. * Tests for the StoreFactory class.
* *
* For the full copyright and license information, please view the LICENSE file that was * For the full copyright and license information, please view the LICENSE file that was
* distributed with this source code. * distributed with this source code.
* *
* @covers \SimpleSAML\Store * @covers \SimpleSAML\Store\StoreFactory
*
* @package simplesamlphp/simplesamlphp * @package simplesamlphp/simplesamlphp
*/ */
class StoreTest extends TestCase class StoreTest extends TestCase
...@@ -30,7 +30,7 @@ class StoreTest extends TestCase ...@@ -30,7 +30,7 @@ class StoreTest extends TestCase
Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); Configuration::loadFromArray([], '[ARRAY]', 'simplesaml');
/** @var false $store */ /** @var false $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertFalse($store); $this->assertFalse($store);
} }
...@@ -44,7 +44,7 @@ class StoreTest extends TestCase ...@@ -44,7 +44,7 @@ class StoreTest extends TestCase
Configuration::loadFromArray([], '[ARRAY]', 'simplesaml'); Configuration::loadFromArray([], '[ARRAY]', 'simplesaml');
/** @var false $store */ /** @var false $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertFalse($store); $this->assertFalse($store);
} }
...@@ -59,9 +59,9 @@ class StoreTest extends TestCase ...@@ -59,9 +59,9 @@ class StoreTest extends TestCase
'store.type' => 'memcache', 'store.type' => 'memcache',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\Memcache::class, $store); $this->assertInstanceOf(Store\MemcacheStore::class, $store);
} }
...@@ -76,9 +76,9 @@ class StoreTest extends TestCase ...@@ -76,9 +76,9 @@ class StoreTest extends TestCase
'store.sql.prefix' => 'phpunit_', 'store.sql.prefix' => 'phpunit_',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\SQL::class, $store); $this->assertInstanceOf(Store\SQLStore::class, $store);
} }
...@@ -88,14 +88,14 @@ class StoreTest extends TestCase ...@@ -88,14 +88,14 @@ class StoreTest extends TestCase
public function pathStore(): void public function pathStore(): void
{ {
Configuration::loadFromArray([ Configuration::loadFromArray([
'store.type' => '\SimpleSAML\Store\SQL', 'store.type' => '\SimpleSAML\Store\SQLStore',
'store.sql.dsn' => 'sqlite::memory:', 'store.sql.dsn' => 'sqlite::memory:',
'store.sql.prefix' => 'phpunit_', 'store.sql.prefix' => 'phpunit_',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\SQL::class, $store); $this->assertInstanceOf(Store\SQLStore::class, $store);
} }
...@@ -111,7 +111,7 @@ class StoreTest extends TestCase ...@@ -111,7 +111,7 @@ class StoreTest extends TestCase
'store.sql.prefix' => 'phpunit_', 'store.sql.prefix' => 'phpunit_',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
Store::getInstance(); StoreFactory::getInstance();
} }
...@@ -120,16 +120,15 @@ class StoreTest extends TestCase ...@@ -120,16 +120,15 @@ class StoreTest extends TestCase
protected function tearDown(): void protected function tearDown(): void
{ {
$config = Configuration::getInstance(); $config = Configuration::getInstance();
/** @var \SimpleSAML\Store $store */ /** @var \SimpleSAML\Store\StoreInterface $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->clearInstance($config, Configuration::class); $this->clearInstance($config, Configuration::class);
$this->clearInstance($store, Store::class);
} }
/** /**
* @param \SimpleSAML\Configuration|\SimpleSAML\Store $service * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
* @param class-string $className * @param class-string $className
*/ */
protected function clearInstance($service, string $className): void protected function clearInstance($service, string $className): void
......
...@@ -10,6 +10,7 @@ use SimpleSAML\Configuration; ...@@ -10,6 +10,7 @@ use SimpleSAML\Configuration;
use SimpleSAML\Error; use SimpleSAML\Error;
use SimpleSAML\Module\saml\IdP\SQLNameID; use SimpleSAML\Module\saml\IdP\SQLNameID;
use SimpleSAML\Store; use SimpleSAML\Store;
use SimpleSAML\Store\StoreFactory;
/** /**
* Test for the SQLNameID helper class. * Test for the SQLNameID helper class.
...@@ -45,10 +46,10 @@ class SQLNameIDTest extends TestCase ...@@ -45,10 +46,10 @@ class SQLNameIDTest extends TestCase
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
$this->addGetDelete(); $this->addGetDelete();
$config = Configuration::getInstance(); $config = Configuration::getInstance();
/** @var \SimpleSAML\Store $store */ /** @var \SimpleSAML\Store\StoreInterface $store */
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->clearInstance($config, Configuration::class); $this->clearInstance($config, Configuration::class);
$this->clearInstance($store, Store::class); $this->clearInstance($store, Store\SQLStore::class);
} }
...@@ -61,15 +62,15 @@ class SQLNameIDTest extends TestCase ...@@ -61,15 +62,15 @@ class SQLNameIDTest extends TestCase
Configuration::loadFromArray([ Configuration::loadFromArray([
'store.type' => 'memcache', 'store.type' => 'memcache',
], '[ARRAY]', 'simplesaml'); ], '[ARRAY]', 'simplesaml');
$store = Store::getInstance(); $store = StoreFactory::getInstance();
$this->assertInstanceOf(Store\Memcache::class, $store); $this->assertInstanceOf(Store\MemcacheStote::class, $store);
$this->expectException(Error\Exception::class); $this->expectException(Error\Exception::class);
$this->addGetDelete(); $this->addGetDelete();
$config = Configuration::getInstance(); $config = Configuration::getInstance();
/** @var \SimpleSAML\Store $store */ /** @var \SimpleSAML\Store\StoreInterface $store */
$store = Store::getInstance(); $store = Store::getInstance();
$this->clearInstance($config, Configuration::class); $this->clearInstance($config, Configuration::class);
$this->clearInstance($store, Store::class); $this->clearInstance($store, Store\MemcacheStore::class);
} }
...@@ -98,7 +99,7 @@ class SQLNameIDTest extends TestCase ...@@ -98,7 +99,7 @@ class SQLNameIDTest extends TestCase
/** /**
* @param \SimpleSAML\Configuration|\SimpleSAML\Store $service * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
* @param class-string $className * @param class-string $className
*/ */
protected function clearInstance($service, string $className): void protected function clearInstance($service, string $className): void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment