diff --git a/Tests/Security/Helpers/Auth0Psr16AdapterTest.php b/Tests/Security/Helpers/Auth0Psr16AdapterTest.php deleted file mode 100644 index 0a0548f..0000000 --- a/Tests/Security/Helpers/Auth0Psr16AdapterTest.php +++ /dev/null @@ -1,121 +0,0 @@ -mockPool = Mockery::mock(CacheItemPoolInterface::class, 'CacheItemPoolInterface'); - $this->mockItems = [ - Mockery::mock(CacheItemInterface::class, 'CacheItemInterface'), - Mockery::mock(CacheItemInterface::class, 'CacheItemInterface'), - ]; - - $this->adapter = new Auth0Psr16Adapter($this->mockPool); - } - - public function testConstructor() - { - $this->assertInstanceOf(Auth0Psr16Adapter::class, $this->adapter); - } - - public function testFetch() - { - $this->mockItems[0]->shouldReceive('isHit')->times(1)->andReturn(true); - $this->mockItems[0]->shouldReceive('get')->times(1)->andReturn('some_value'); - $this->mockPool->shouldReceive('getItem')->withArgs(['some_item'])->andReturn($this->mockItems[0]); - $this->assertEquals('some_value', $this->adapter->get('some_item')); - } - - public function testFetchMiss() - { - $this->mockItems[0]->shouldReceive('isHit')->times(1)->andReturn(false); - $this->mockPool->shouldReceive('getItem')->withArgs(['no_item'])->andReturn($this->mockItems[0]); - $this->assertFalse($this->adapter->get('no_item', false)); - } - - public function testFetchInvalid() - { - $invalidKeyString = '{}()/\@'; - - $this->mockPool->shouldReceive('getItem')->withArgs([$invalidKeyString])->andReturn(false); - $this->assertFalse($this->adapter->get($invalidKeyString, false)); - } - - public function testFetchMultiple() - { - $expectedResponse = [ - 'first_item' => 'first_value', - 'second_item' => 'second_value' - ]; - - $this->mockItems[0]->shouldReceive('isHit')->once()->andReturn(true); - $this->mockItems[0]->shouldReceive('get')->once()->andReturn(array_values($expectedResponse)[0]); - $this->mockItems[1]->shouldReceive('isHit')->once()->andReturn(true); - $this->mockItems[1]->shouldReceive('get')->once()->andReturn(array_values($expectedResponse)[1]); - - $this->mockPool->shouldReceive('getItems')->withArgs([array_keys($expectedResponse)])->andReturn([ $this->mockItems[0], $this->mockItems[1] ]); - - $this->assertEquals(array_values($expectedResponse), $this->adapter->getMultiple(array_keys($expectedResponse))); - } - - public function testContains() - { - $this->mockPool->shouldReceive('hasItem')->withArgs(['no_item'])->andReturn(false); - $this->mockPool->shouldReceive('hasItem')->withArgs(['some_item'])->andReturn(true); - $this->assertFalse($this->adapter->has('no_item')); - $this->assertTrue($this->adapter->has('some_item')); - } - - public function testSave() - { - $this->mockItems[0]->shouldReceive('set')->twice()->with('dummy_data'); - $this->mockItems[0]->shouldReceive('expiresAfter')->once()->with(null); - $this->mockItems[0]->shouldReceive('expiresAfter')->once()->with(2); - $this->mockPool->shouldReceive('getItem')->twice()->with('some_item')->andReturn($this->mockItems[0]); - $this->mockPool->shouldReceive('save')->twice()->with($this->mockItems[0])->andReturn(true); - $this->assertTrue($this->adapter->set('some_item', 'dummy_data')); - $this->assertTrue($this->adapter->set('some_item', 'dummy_data', 2)); - } - - public function testSaveInvalid() - { - $invalidKeyString = '{}()/\@'; - - $this->mockPool->shouldReceive('getItem')->once()->with($invalidKeyString); - $this->assertFalse($this->adapter->set($invalidKeyString, 'dummy_data')); - } - - public function testDelete() - { - $this->mockPool->shouldReceive('deleteItem')->once()->with('some_item')->andReturn(true); - $this->assertTrue($this->adapter->delete('some_item')); - } - - public function testDeleteInvalid() - { - $invalidKeyString = '{}()/\@'; - - $this->mockPool->shouldReceive('deleteItem')->once()->with($invalidKeyString)->andReturn(false); - $this->assertFalse($this->adapter->delete($invalidKeyString)); - } - - public function testClear() - { - $this->mockPool->shouldReceive('clear')->once()->andReturn(true); - $this->assertTrue($this->adapter->clear()); - } -} diff --git a/src/Security/Helpers/Auth0Psr16Adapter.php b/src/Security/Helpers/Auth0Psr16Adapter.php deleted file mode 100644 index a1dc284..0000000 --- a/src/Security/Helpers/Auth0Psr16Adapter.php +++ /dev/null @@ -1,209 +0,0 @@ -cache = $cache; - } - - /** - * {@inheritdoc} - * - * @param string $key The unique key of this item in the cache. - * @param mixed $default Default value to return if the key does not exist. - * - * @return mixed The value of the item from the cache, or $default in case of cache miss. - */ - public function get($key, $default = null) - { - $item = null; - - try { - $item = $this->cache->getItem($key); - } catch (\Throwable $th) { - $item = null; - } - - if ($item && $item->isHit()) { - return $item->get(); - } - - return $default; - } - - /** - * {@inheritdoc} - * - * @param string $key The key of the item to store. - * @param mixed $value The value of the item to store. Must be serializable. - * @param null|integer|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and - * the driver supports TTL then the library may set a default value - * for it or let the driver take care of that. - * - * @return boolean True on success and false on failure. - */ - public function set($key, $value, $ttl = null) - { - try { - $item = $this->cache->getItem($key); - } catch (\Throwable $th) { - $item = null; - } - - if ($item) { - $item->expiresAfter($ttl); - $item->set($value); - return $this->cache->save($item); - } - - return false; - } - - /** - * {@inheritdoc} - * - * @param string $key The unique cache key of the item to delete. - * - * @return boolean True if the item was successfully removed. False if there was an error. - */ - public function delete($key) - { - try { - return $this->cache->deleteItem($key); - } catch (\Exception $e) { - return false; - } - } - - /** - * {@inheritdoc} - * - * @return boolean True on success and false on failure. - */ - public function clear() - { - return $this->cache->clear(); - } - - /** - * {@inheritdoc} - * - * @param array $keys A list of keys that can obtained in a single operation. - * @param mixed $default Default value to return for keys that do not exist. - * - * @return array A list of key => value pairs. Missing cache keys will have $default as value. - */ - // phpcs:ignore - public function getMultiple($keys, $default = null) - { - $items = $this->cache->getItems($keys); - $response = []; - - foreach ($items as $key => $item) { - /* - * @type $item CacheItemInterface - */ - - if (! $item->isHit()) { - $response[$key] = $default; - } - - $response[$key] = $item->get(); - } - - return $response; - } - - /** - * {@inheritdoc} - * - * @param array $values A list of key => value pairs for a multiple-set operation. - * @param null|integer|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and - * the driver supports TTL then the library may set a default value - * for it or let the driver take care of that. - * - * @return boolean True on success and false on failure. - */ - // phpcs:ignore - public function setMultiple($values, $ttl = null) - { - $keys = []; - $arrayValues = []; - - foreach ($values as $key => $value) { - $keys[] = $key; - $arrayValues[$key] = $value; - } - - try { - $items = $this->cache->getItems($keys); - $success = true; - - foreach ($items as $key => $item) { - $item->set($arrayValues[$key]); - $item->expiresAfter($ttl); - - if ($success) { - $success = $this->cache->saveDeferred($item); - } - } - } catch (\Throwable $th) { - $success = false; - } - - if ($success) { - $success = $this->cache->commit(); - } - - return $success; - } - - /** - * {@inheritdoc} - * - * @param array $keys A list of string-based keys to be deleted. - * - * @return boolean True if the items were successfully removed. False if there was an error. - */ - // phpcs:ignore - public function deleteMultiple($keys) - { - return $this->cache->deleteItems($keys); - } - - /** - * {@inheritdoc} - * - * @param string $key The cache item key. - * - * @return boolean - */ - public function has($key) - { - return $this->cache->hasItem($key); - } -}