From 8104fdd67d2bd4569d897d55ff8b5b4273137b84 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 2 Aug 2015 21:34:14 -0700 Subject: [PATCH 01/92] getExpiration returns CurrentTime for empty record --- src/Stash/Item.php | 6 +++--- tests/Stash/Test/AbstractItemTest.php | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 8b1d25d6..8a3131ad 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -580,13 +580,13 @@ public function getCreation() public function getExpiration() { $record = $this->getRecord(); + $dateTime = new \DateTime(); + if (!isset($record['expiration'])) { - return false; + return $dateTime; } - $dateTime = new \DateTime(); $dateTime->setTimestamp($record['expiration']); - return $dateTime; } diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 5c07ed03..7858befc 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -303,7 +303,14 @@ public function testGetExpiration() $key = array('getExpiration', 'test'); $stash = $this->testConstruct($key); - $this->assertFalse($stash->getExpiration(), 'no record exists yet, return null'); + + $currentDate = new \DateTime(); + $returnedDate = $stash->getExpiration(); + + $this->assertLessThanOrEqual(2, $currentDate->getTimestamp() - $returnedDate->getTimestamp(), 'No record set, return as expired.'); + $this->assertLessThanOrEqual(2, $returnedDate->getTimestamp() - $currentDate->getTimestamp(), 'No record set, return as expired.'); + + #$this->assertFalse($stash->getExpiration(), 'no record exists yet, return null'); $stash->set(array('stuff'), $expiration); From 3b169d15550b2b73cf7af7f3665ebc427a56c0f6 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 2 Aug 2015 22:23:02 -0700 Subject: [PATCH 02/92] Created stand alone "save" function that uses the data and ttl properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is because in PSR6 the “set” and new expiration functions are no longer persistent to the driver but instead save data in the object until it is saved. This change provides backwards compatibility (for now) to make testing easier, while providing the foundation of the future changes to this class. --- src/Stash/Item.php | 63 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 8a3131ad..f5734814 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -85,6 +85,9 @@ class Item implements ItemInterface 'stampede_ttl' => 30, // How long a stampede flag will be acknowledged ); + protected $data; + protected $expiration; + /** * The identifier for the item being cached. It is set through the setupKey function. * @@ -209,6 +212,9 @@ public function clear() private function executeClear() { + unset($this->data); + unset($this->expiration); + if ($this->isDisabled()) { return false; } @@ -222,7 +228,11 @@ private function executeClear() public function get($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) { try { - return $this->executeGet($invalidation, $arg, $arg2); + if(!isset($this->data)) { + $this->data = $this->executeGet($invalidation, $arg, $arg2); + } + + return $this->data; } catch (Exception $e) { $this->logException('Retrieving from cache caused exception.', $e); $this->disable(); @@ -313,14 +323,38 @@ public function lock($ttl = null) */ public function set($data, $ttl = null) { - try { - return $this->executeSet($data, $ttl); - } catch (Exception $e) { - $this->logException('Setting value in cache caused exception.', $e); - $this->disable(); + if ($this->isDisabled()) { + return false; + } - return false; + $this->data = $data; + + if(is_numeric($ttl)) { + $dateInterval = \DateInterval::createFromDateString(abs($ttl) . ' seconds'); + $date = new \DateTime(); + if($ttl > 0) { + $date->add($dateInterval); + } else { + $date->sub($dateInterval); } + $this->expiration = $date; + } elseif ($ttl instanceof \DateTime) { + $this->expiration = $ttl; + } + + return $this->save(); + } + + public function save() + { + try { + return $this->executeSet($this->data, $this->expiration); + } catch (Exception $e) { + $this->logException('Setting value in cache caused exception.', $e); + $this->disable(); + + return false; + } } private function executeSet($data, $time) @@ -579,15 +613,18 @@ public function getCreation() */ public function getExpiration() { - $record = $this->getRecord(); - $dateTime = new \DateTime(); + if(!isset($this->expiration)) { + $record = $this->getRecord(); + $dateTime = new \DateTime(); - if (!isset($record['expiration'])) { - return $dateTime; + if (!isset($record['expiration'])) { + return $dateTime; + } + + $this->expiration = $dateTime->setTimestamp($record['expiration']); } - $dateTime->setTimestamp($record['expiration']); - return $dateTime; + return $this->expiration; } /** From d7be6c860ca27ccc5e0519114e9d6e90411b386a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 2 Aug 2015 22:58:21 -0700 Subject: [PATCH 03/92] Formatting --- src/Stash/Item.php | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index f5734814..11bae9f6 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -228,7 +228,7 @@ private function executeClear() public function get($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) { try { - if(!isset($this->data)) { + if (!isset($this->data)) { $this->data = $this->executeGet($invalidation, $arg, $arg2); } @@ -323,38 +323,38 @@ public function lock($ttl = null) */ public function set($data, $ttl = null) { - if ($this->isDisabled()) { - return false; - } + if ($this->isDisabled()) { + return false; + } - $this->data = $data; + $this->data = $data; - if(is_numeric($ttl)) { - $dateInterval = \DateInterval::createFromDateString(abs($ttl) . ' seconds'); - $date = new \DateTime(); - if($ttl > 0) { - $date->add($dateInterval); - } else { - $date->sub($dateInterval); + if (is_numeric($ttl)) { + $dateInterval = \DateInterval::createFromDateString(abs($ttl) . ' seconds'); + $date = new \DateTime(); + if ($ttl > 0) { + $date->add($dateInterval); + } else { + $date->sub($dateInterval); + } + $this->expiration = $date; + } elseif ($ttl instanceof \DateTime) { + $this->expiration = $ttl; } - $this->expiration = $date; - } elseif ($ttl instanceof \DateTime) { - $this->expiration = $ttl; - } - return $this->save(); + return $this->save(); } public function save() { - try { - return $this->executeSet($this->data, $this->expiration); - } catch (Exception $e) { - $this->logException('Setting value in cache caused exception.', $e); - $this->disable(); - - return false; - } + try { + return $this->executeSet($this->data, $this->expiration); + } catch (Exception $e) { + $this->logException('Setting value in cache caused exception.', $e); + $this->disable(); + + return false; + } } private function executeSet($data, $time) @@ -613,15 +613,15 @@ public function getCreation() */ public function getExpiration() { - if(!isset($this->expiration)) { - $record = $this->getRecord(); - $dateTime = new \DateTime(); + if (!isset($this->expiration)) { + $record = $this->getRecord(); + $dateTime = new \DateTime(); - if (!isset($record['expiration'])) { - return $dateTime; - } + if (!isset($record['expiration'])) { + return $dateTime; + } - $this->expiration = $dateTime->setTimestamp($record['expiration']); + $this->expiration = $dateTime->setTimestamp($record['expiration']); } return $this->expiration; From fc5950790be52e75b9e98749e36910d7a1918388 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 2 Aug 2015 23:47:51 -0700 Subject: [PATCH 04/92] Decoupled "set" function from persisting values --- src/Stash/Interfaces/ItemInterface.php | 5 +++ src/Stash/Item.php | 42 ++++++++++++++++++---- src/Stash/Session.php | 2 +- tests/Stash/Test/AbstractItemTest.php | 29 +++++++-------- tests/Stash/Test/AbstractPoolTest.php | 8 ++--- tests/Stash/Test/CacheExceptionTest.php | 2 +- tests/Stash/Test/Driver/FileSystemTest.php | 2 +- tests/Stash/Test/Driver/SqliteAnyTest.php | 2 +- tests/Stash/Test/ItemLoggerTest.php | 2 +- tests/Stash/Test/PoolNamespaceTest.php | 6 ++-- 10 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 4a3f8c49..0ae2bcdc 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -134,4 +134,9 @@ public function getCreation(); * @return \DateTime */ public function getExpiration(); + + + + public function expiresAfter($time); + public function expiresAt($expiration); } diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 11bae9f6..e3fea1a2 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -323,26 +323,54 @@ public function lock($ttl = null) */ public function set($data, $ttl = null) { + if (!isset($this->key)) { + return false; + } + if ($this->isDisabled()) { return false; } $this->data = $data; + $this->setTTL($ttl); + return $this; + } + + public function setTTL($ttl = null) + { + if (is_numeric($ttl) || ($ttl instanceof \DateInterval)) { + $this->expiresAfter($ttl); + } elseif ($ttl instanceof \DateTimeInterface) { + $this->expiresAt($ttl); + } else { + $this->expiration = null; + } + } + + public function expiresAt($expiration = null) + { + $this->expiration = $expiration; + return $this; + } - if (is_numeric($ttl)) { - $dateInterval = \DateInterval::createFromDateString(abs($ttl) . ' seconds'); - $date = new \DateTime(); - if ($ttl > 0) { + public function expiresAfter($time) + { + $date = new \DateTime(); + if (is_numeric($time)) { + $dateInterval = \DateInterval::createFromDateString(abs($time) . ' seconds'); + if ($time > 0) { $date->add($dateInterval); } else { $date->sub($dateInterval); } $this->expiration = $date; - } elseif ($ttl instanceof \DateTime) { - $this->expiration = $ttl; + } elseif ($time instanceof \DateInterval) { + $date->add($time); + $this->expiration = $date; + } else { } - return $this->save(); + return $this; } public function save() diff --git a/src/Stash/Session.php b/src/Stash/Session.php index 206d5014..990bc319 100644 --- a/src/Stash/Session.php +++ b/src/Stash/Session.php @@ -184,7 +184,7 @@ public function write($session_id, $session_data) { $cache = $this->getCache($session_id); - return $cache->set($session_data, $this->options['ttl']); + return $cache->set($session_data, $this->options['ttl'])->save(); } /** diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 7858befc..31b702dd 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -112,7 +112,7 @@ public function testSet() $this->assertAttributeInternalType('string', 'keyString', $stash, 'Argument based keys setup keystring'); $this->assertAttributeInternalType('array', 'key', $stash, 'Argument based keys setup key'); - $this->assertTrue($stash->set($value), 'Driver class able to store data type ' . $type); + $this->assertTrue($stash->set($value)->save(), 'Driver class able to store data type ' . $type); } $item = $this->getItem(); @@ -130,7 +130,7 @@ public function testGet() foreach ($this->data as $type => $value) { $key = array('base', $type); $stash = $this->testConstruct($key); - $stash->set($value); + $stash->set($value)->save(); // new object, but same backend $stash = $this->testConstruct($key); @@ -180,7 +180,7 @@ public function testInvalidation() $newValue = 'newValue'; $runningStash = $this->testConstruct($key); - $runningStash->set($oldValue, -300); + $runningStash->set($oldValue, -300)->save(); // Test without stampede $controlStash = $this->testConstruct($key); @@ -234,7 +234,7 @@ public function testInvalidation() unset($unknownStash); // Test that storing the cache turns off stampede mode. - $runningStash->set($newValue, 30); + $runningStash->set($newValue, 30)->save(); $this->assertAttributeEquals(false, 'stampedeRunning', $runningStash, 'Stampede flag is off.'); unset($runningStash); @@ -255,7 +255,7 @@ public function testInvalidation() // Test Stampede Flag Expiration $key = array('stampede', 'expire'); $Item_SPtest = $this->testConstruct($key); - $Item_SPtest->set($oldValue, -300); + $Item_SPtest->set($oldValue, -300)->save(); $Item_SPtest->lock(-5); $this->assertEquals($oldValue, $Item_SPtest->get(Item::SP_VALUE, $newValue), 'Expired lock is ignored'); } @@ -267,7 +267,7 @@ public function testSetWithDateTime() $key = array('base', 'expiration', 'test'); $stash = $this->testConstruct($key); - $stash->set(array(1, 2, 3, 'apples'), $expiration); + $stash->set(array(1, 2, 3, 'apples'), $expiration)->save(); $stash = $this->testConstruct($key); $data = $stash->get(); @@ -285,7 +285,7 @@ public function testGetCreation() $this->assertFalse($stash->getCreation(), 'no record exists yet, return null'); - $stash->set(array('stuff'), $creation); + $stash->set(array('stuff'), $creation)->save(); $stash = $this->testConstruct($key); $createdOn = $stash->getCreation(); @@ -312,7 +312,7 @@ public function testGetExpiration() #$this->assertFalse($stash->getExpiration(), 'no record exists yet, return null'); - $stash->set(array('stuff'), $expiration); + $stash->set(array('stuff'), $expiration)->save(); $stash = $this->testConstruct($key); $itemExpiration = $stash->getExpiration(); @@ -331,7 +331,7 @@ public function testIsMiss() $key = array('isMiss', 'test'); $stash = $this->testConstruct($key); - $stash->set('testString'); + $stash->set('testString')->save(); $stash = $this->testConstruct($key); $this->assertTrue(!$stash->isMiss(), 'isMiss returns false for valid data'); @@ -343,11 +343,11 @@ public function testClear() foreach ($this->data as $type => $value) { $key = array('base', $type); $stash = $this->testConstruct($key); - $stash->set($value); + $stash->set($value)->save(); $this->assertAttributeInternalType('string', 'keyString', $stash, 'Argument based keys setup keystring'); $this->assertAttributeInternalType('array', 'key', $stash, 'Argument based keys setup key'); - $this->assertTrue($stash->set($value), 'Driver class able to store data type ' . $type); + $this->assertTrue($stash->set($value)->save(), 'Driver class able to store data type ' . $type); } foreach ($this->data as $type => $value) { @@ -376,7 +376,7 @@ public function testClear() foreach ($this->data as $type => $value) { $key = array('base', $type); $stash = $this->testConstruct($key); - $stash->set($value); + $stash->set($value)->save(); } // clear @@ -406,10 +406,11 @@ public function testExtend() $stash = $this->testConstruct($key); - $stash->set($value, -600); + $stash->set($value, -600)->save(); $stash = $this->testConstruct($key); - $this->assertTrue($stash->extend(), 'extend returns true'); + $this->assertEquals($stash->extend(), $stash, 'extend returns item object'); + $stash->save(); $stash = $this->testConstruct($key); $data = $stash->get(); diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index 94c8f38a..8b75d9de 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -55,7 +55,7 @@ public function testGetItem() $stash = $pool->getItem('base', 'one'); $this->assertInstanceOf('Stash\Item', $stash, 'getItem returns a Stash\Item object'); - $stash->set($this->data); + $stash->set($this->data)->save(); $storedData = $stash->get(); $this->assertEquals($this->data, $storedData, 'getItem returns working Stash\Item object'); @@ -99,7 +99,7 @@ public function testGetItemIterator() foreach ($cacheIterator as $stash) { $key = $stash->getKey(); $this->assertTrue($stash->isMiss(), 'new Cache in iterator is empty'); - $stash->set($keyData[$key]); + $stash->set($keyData[$key])->save(); unset($keyData[$key]); } $this->assertCount(0, $keyData, 'all keys are accounted for the in cache iterator'); @@ -117,7 +117,7 @@ public function testFlushCache() $pool = $this->getTestPool(); $stash = $pool->getItem('base', 'one'); - $stash->set($this->data); + $stash->set($this->data)->save(); $this->assertTrue($pool->flush(), 'flush returns true'); $stash = $pool->getItem('base', 'one'); @@ -130,7 +130,7 @@ public function testPurgeCache() $pool = $this->getTestPool(); $stash = $pool->getItem('base', 'one'); - $stash->set($this->data, -600); + $stash->set($this->data, -600)->save(); $this->assertTrue($pool->purge(), 'purge returns true'); $stash = $pool->getItem('base', 'one'); diff --git a/tests/Stash/Test/CacheExceptionTest.php b/tests/Stash/Test/CacheExceptionTest.php index a8e6cbbd..ef10fb77 100644 --- a/tests/Stash/Test/CacheExceptionTest.php +++ b/tests/Stash/Test/CacheExceptionTest.php @@ -31,7 +31,7 @@ public function testSet() $item->setKey(array('path', 'to', 'store')); $this->assertFalse($item->isDisabled()); - $this->assertFalse($item->set(array(1, 2, 3), 3600)); + $this->assertFalse($item->set(array(1, 2, 3), 3600)->save()); $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver'); } diff --git a/tests/Stash/Test/Driver/FileSystemTest.php b/tests/Stash/Test/Driver/FileSystemTest.php index bde38b37..fc435154 100644 --- a/tests/Stash/Test/Driver/FileSystemTest.php +++ b/tests/Stash/Test/Driver/FileSystemTest.php @@ -75,7 +75,7 @@ public function testOptionKeyHashFunctionDirs() $poolStub->setDriver($driver); $item->setPool($poolStub); $item->setKey($paths); - $item->set($rand); + $item->set($rand)->save(); $allpaths = array_merge(array('cache'), $paths); $predicted = sys_get_temp_dir(). diff --git a/tests/Stash/Test/Driver/SqliteAnyTest.php b/tests/Stash/Test/Driver/SqliteAnyTest.php index 7e661da8..91cb4e28 100644 --- a/tests/Stash/Test/Driver/SqliteAnyTest.php +++ b/tests/Stash/Test/Driver/SqliteAnyTest.php @@ -47,7 +47,7 @@ public function testConstruction() $poolSub->setDriver($driver); $item->setPool($poolSub); $item->setKey($key); - $this->assertTrue($item->set($key), 'Able to load and store with unconfigured extension.'); + $this->assertTrue($item->set($key)->save(), 'Able to load and store with unconfigured extension.'); } public static function tearDownAfterClass() diff --git a/tests/Stash/Test/ItemLoggerTest.php b/tests/Stash/Test/ItemLoggerTest.php index cfc20b81..1aab6168 100644 --- a/tests/Stash/Test/ItemLoggerTest.php +++ b/tests/Stash/Test/ItemLoggerTest.php @@ -75,7 +75,7 @@ public function testSet() $item->setLogger($logger); // triggerlogging - $item->set('test_key'); + $item->set('test_key')->save(); $this->assertInstanceOf('Stash\Test\Exception\TestException', $logger->lastContext['exception'], 'Logger was passed exception in event context.'); diff --git a/tests/Stash/Test/PoolNamespaceTest.php b/tests/Stash/Test/PoolNamespaceTest.php index 3f4247a3..b4c0b30a 100644 --- a/tests/Stash/Test/PoolNamespaceTest.php +++ b/tests/Stash/Test/PoolNamespaceTest.php @@ -36,17 +36,17 @@ public function testFlushNamespacedCache() // No Namespace $item = $pool->getItem(array('base', 'one')); - $item->set($this->data); + $item->set($this->data)->save(); // TestNamespace $pool->setNamespace('TestNamespace'); $item = $pool->getItem(array('test', 'one')); - $item->set($this->data); + $item->set($this->data)->save(); // TestNamespace2 $pool->setNamespace('TestNamespace2'); $item = $pool->getItem(array('test', 'one')); - $item->set($this->data); + $item->set($this->data)->save(); // Flush TestNamespace $pool->setNamespace('TestNamespace'); From 94735f22241d09e0338c34c093ce3e46e02c5963 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 2 Aug 2015 23:57:56 -0700 Subject: [PATCH 05/92] Removed expiration time for `set` function --- src/Stash/Interfaces/ItemInterface.php | 3 +-- src/Stash/Item.php | 3 +-- src/Stash/Session.php | 2 +- tests/Stash/Test/AbstractItemTest.php | 13 ++++++++----- tests/Stash/Test/AbstractPoolTest.php | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 0ae2bcdc..6e2ae4aa 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -92,10 +92,9 @@ public function lock($ttl = null); * unable to be serialized. * * @param mixed $data bool - * @param int|\DateTime|null $ttl Int is time (seconds), DateTime a future expiration date * @return bool Returns whether the object was successfully stored or not. */ - public function set($data, $ttl = null); + public function set($data); /** * Extends the expiration on the current cached item. For some engines this diff --git a/src/Stash/Item.php b/src/Stash/Item.php index e3fea1a2..924fc79e 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -321,7 +321,7 @@ public function lock($ttl = null) /** * {@inheritdoc} */ - public function set($data, $ttl = null) + public function set($data) { if (!isset($this->key)) { return false; @@ -332,7 +332,6 @@ public function set($data, $ttl = null) } $this->data = $data; - $this->setTTL($ttl); return $this; } diff --git a/src/Stash/Session.php b/src/Stash/Session.php index 990bc319..a2a0cce5 100644 --- a/src/Stash/Session.php +++ b/src/Stash/Session.php @@ -184,7 +184,7 @@ public function write($session_id, $session_data) { $cache = $this->getCache($session_id); - return $cache->set($session_data, $this->options['ttl'])->save(); + return $cache->set($session_data)->expiresAfter($this->options['ttl'])->save(); } /** diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 31b702dd..fc628ad1 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -180,7 +180,7 @@ public function testInvalidation() $newValue = 'newValue'; $runningStash = $this->testConstruct($key); - $runningStash->set($oldValue, -300)->save(); + $runningStash->set($oldValue)->expiresAfter(-300)->save(); // Test without stampede $controlStash = $this->testConstruct($key); @@ -234,7 +234,7 @@ public function testInvalidation() unset($unknownStash); // Test that storing the cache turns off stampede mode. - $runningStash->set($newValue, 30)->save(); + $runningStash->set($newValue)->expiresAfter(30)->save(); $this->assertAttributeEquals(false, 'stampedeRunning', $runningStash, 'Stampede flag is off.'); unset($runningStash); @@ -255,7 +255,7 @@ public function testInvalidation() // Test Stampede Flag Expiration $key = array('stampede', 'expire'); $Item_SPtest = $this->testConstruct($key); - $Item_SPtest->set($oldValue, -300)->save(); + $Item_SPtest->set($oldValue)->expiresAfter(-300)->save(); $Item_SPtest->lock(-5); $this->assertEquals($oldValue, $Item_SPtest->get(Item::SP_VALUE, $newValue), 'Expired lock is ignored'); } @@ -267,7 +267,10 @@ public function testSetWithDateTime() $key = array('base', 'expiration', 'test'); $stash = $this->testConstruct($key); - $stash->set(array(1, 2, 3, 'apples'), $expiration)->save(); + + $stash->set(array(1, 2, 3, 'apples')) + ->expiresAt($expiration) + ->save(); $stash = $this->testConstruct($key); $data = $stash->get(); @@ -312,7 +315,7 @@ public function testGetExpiration() #$this->assertFalse($stash->getExpiration(), 'no record exists yet, return null'); - $stash->set(array('stuff'), $expiration)->save(); + $stash->set(array('stuff'))->expiresAt($expiration)->save(); $stash = $this->testConstruct($key); $itemExpiration = $stash->getExpiration(); diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index 8b75d9de..80bba6ea 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -130,7 +130,7 @@ public function testPurgeCache() $pool = $this->getTestPool(); $stash = $pool->getItem('base', 'one'); - $stash->set($this->data, -600)->save(); + $stash->set($this->data)->expiresAfter(-600)->save(); $this->assertTrue($pool->purge(), 'purge returns true'); $stash = $pool->getItem('base', 'one'); From 1c7f102b7f662773630c137800f0fb36026edadc Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 00:25:13 -0700 Subject: [PATCH 06/92] Split invalidation method from get function. --- src/Stash/Interfaces/ItemInterface.php | 5 +---- src/Stash/Item.php | 30 ++++++++++++++++++++------ tests/Stash/Test/AbstractItemTest.php | 21 +++++++++--------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 6e2ae4aa..0f590422 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -63,12 +63,9 @@ public function clear(); * function after call this one. If no value is stored at all then this * function will return null. * - * @param int $invalidation - * @param null $arg - * @param null $arg2 * @return mixed|null */ - public function get($invalidation = 0, $arg = null, $arg2 = null); + public function get(); /** * Returns true if the cached item needs to be refreshed. diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 924fc79e..ed4efd0a 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -88,6 +88,12 @@ class Item implements ItemInterface protected $data; protected $expiration; + protected $invalidationMethod = Invalidation::PRECOMPUTE; + protected $invalidationArg1 = null; + protected $invalidationArg2 = null; + + + /** * The identifier for the item being cached. It is set through the setupKey function. * @@ -225,11 +231,14 @@ private function executeClear() /** * {@inheritdoc} */ - public function get($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) + public function get() { try { if (!isset($this->data)) { - $this->data = $this->executeGet($invalidation, $arg, $arg2); + $this->data = $this->executeGet( + $this->invalidationMethod, + $this->invalidationArg1, + $this->invalidationArg2); } return $this->data; @@ -241,7 +250,14 @@ public function get($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 } } - private function executeGet($invalidation, $arg, $arg2) + public function setInvalidationMethod($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) + { + $this->invalidationMethod = $invalidation; + $this->invalidationArg1 = $arg; + $this->invalidationArg2 = $arg2; + } + + private function executeGet($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) { $this->isHit = false; @@ -338,12 +354,13 @@ public function set($data) public function setTTL($ttl = null) { if (is_numeric($ttl) || ($ttl instanceof \DateInterval)) { - $this->expiresAfter($ttl); + return $this->expiresAfter($ttl); } elseif ($ttl instanceof \DateTimeInterface) { - $this->expiresAt($ttl); + return $this->expiresAt($ttl); } else { $this->expiration = null; } + return $this; } public function expiresAt($expiration = null) @@ -596,7 +613,6 @@ protected function validateRecord($validation, &$record) case Invalidation::SLEEP: $time = isset($arg) && is_numeric($arg) ? $arg : $this->defaults['sleep_time']; $attempts = isset($arg2) && is_numeric($arg2) ? $arg2 : $this->defaults['sleep_attempts']; - $ptime = $time * 1000; if ($attempts <= 0) { @@ -606,7 +622,7 @@ protected function validateRecord($validation, &$record) } usleep($ptime); - $record['data']['return'] = $this->get(Invalidation::SLEEP, $time, $attempts - 1); + $record['data']['return'] = $this->executeGet(Invalidation::SLEEP, $time, $attempts - 1); break; case Invalidation::OLD: diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index fc628ad1..f7852f47 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -184,8 +184,8 @@ public function testInvalidation() // Test without stampede $controlStash = $this->testConstruct($key); - - $return = $controlStash->get(Item::SP_VALUE, $newValue); + $controlStash->setInvalidationMethod(Item::SP_VALUE, $newValue); + $return = $controlStash->get(); $this->assertEquals($oldValue, $return, 'Old value is returned'); $this->assertTrue($controlStash->isMiss()); unset($controlStash); @@ -196,7 +196,7 @@ public function testInvalidation() // Old $oldStash = $this->testConstruct($key); - + $oldStash->setInvalidationMethod(Item::SP_OLD); $return = $oldStash->get(Item::SP_OLD); $this->assertEquals($oldValue, $return, 'Old value is returned'); $this->assertFalse($oldStash->isMiss()); @@ -204,7 +204,7 @@ public function testInvalidation() // Value $valueStash = $this->testConstruct($key); - + $valueStash->setInvalidationMethod(Item::SP_VALUE, $newValue); $return = $valueStash->get(Item::SP_VALUE, $newValue); $this->assertEquals($newValue, $return, 'New value is returned'); $this->assertFalse($valueStash->isMiss()); @@ -212,9 +212,9 @@ public function testInvalidation() // Sleep $sleepStash = $this->testConstruct($key); - + $sleepStash->setInvalidationMethod(Item::SP_SLEEP, 250, 2); $start = microtime(true); - $return = $sleepStash->get(array(Item::SP_SLEEP, 250, 2)); + $return = $sleepStash->get(); $end = microtime(true); $this->assertTrue($sleepStash->isMiss()); @@ -240,24 +240,25 @@ public function testInvalidation() // Precompute - test outside limit $precomputeStash = $this->testConstruct($key); - + $precomputeStash->setInvalidationMethod(Item::SP_PRECOMPUTE, 10); $return = $precomputeStash->get(Item::SP_PRECOMPUTE, 10); $this->assertFalse($precomputeStash->isMiss(), 'Cache is marked as hit'); unset($precomputeStash); // Precompute - test inside limit $precomputeStash = $this->testConstruct($key); - - $return = $precomputeStash->get(Item::SP_PRECOMPUTE, 35); + $precomputeStash->setInvalidationMethod(Item::SP_PRECOMPUTE, 35); + $return = $precomputeStash->get(); $this->assertTrue($precomputeStash->isMiss(), 'Cache is marked as miss'); unset($precomputeStash); // Test Stampede Flag Expiration $key = array('stampede', 'expire'); $Item_SPtest = $this->testConstruct($key); + $Item_SPtest->setInvalidationMethod(Item::SP_VALUE, $newValue); $Item_SPtest->set($oldValue)->expiresAfter(-300)->save(); $Item_SPtest->lock(-5); - $this->assertEquals($oldValue, $Item_SPtest->get(Item::SP_VALUE, $newValue), 'Expired lock is ignored'); + $this->assertEquals($oldValue, $Item_SPtest->get(), 'Expired lock is ignored'); } public function testSetWithDateTime() From 6a8f49e527d4d2d09c796aea5538ecb3c5efe2a4 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 00:26:49 -0700 Subject: [PATCH 07/92] Fixed formatting --- src/Stash/Item.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index ed4efd0a..746e884c 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -252,9 +252,9 @@ public function get() public function setInvalidationMethod($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) { - $this->invalidationMethod = $invalidation; - $this->invalidationArg1 = $arg; - $this->invalidationArg2 = $arg2; + $this->invalidationMethod = $invalidation; + $this->invalidationArg1 = $arg; + $this->invalidationArg2 = $arg2; } private function executeGet($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null) From 56633a3ce42c16b20c87cfb5f2b8ee46857f2cfb Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 00:35:15 -0700 Subject: [PATCH 08/92] Fixed more "save" related changes --- tests/Stash/Test/Driver/EphemeralTest.php | 4 ++-- tests/Stash/Test/Driver/MemcacheAnyTest.php | 2 +- tests/Stash/Test/Driver/MemcacheTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Stash/Test/Driver/EphemeralTest.php b/tests/Stash/Test/Driver/EphemeralTest.php index cca9a7ed..acf97286 100644 --- a/tests/Stash/Test/Driver/EphemeralTest.php +++ b/tests/Stash/Test/Driver/EphemeralTest.php @@ -31,12 +31,12 @@ public function testKeyCollisions1() $item1 = new Item(); $item1->setPool($poolStub); $item1->setKey(array('##', '#')); - $item1->set('X'); + $item1->set('X'->save()); $item2 = new Item(); $item2->setPool($poolStub); $item2->setKey(array('#', '##')); - $item2->set('Y'); + $item2->set('Y')->save(); $this->assertEquals('X', $item1->get()); } diff --git a/tests/Stash/Test/Driver/MemcacheAnyTest.php b/tests/Stash/Test/Driver/MemcacheAnyTest.php index 65079cfc..697a8eff 100644 --- a/tests/Stash/Test/Driver/MemcacheAnyTest.php +++ b/tests/Stash/Test/Driver/MemcacheAnyTest.php @@ -59,6 +59,6 @@ public function testConstruction() $item->setPool($poolStub); $item->setKey($key); - $this->assertTrue($item->set($key), 'Able to load and store with unconfigured extension.'); + $this->assertTrue($item->set($key)->save(), 'Able to load and store with unconfigured extension.'); } } diff --git a/tests/Stash/Test/Driver/MemcacheTest.php b/tests/Stash/Test/Driver/MemcacheTest.php index 89a1aa49..994aa873 100644 --- a/tests/Stash/Test/Driver/MemcacheTest.php +++ b/tests/Stash/Test/Driver/MemcacheTest.php @@ -78,7 +78,7 @@ public function testConstructionOptions() $item->setPool($poolStub); $item->setKey($key); - $this->assertTrue($item->set($key), 'Able to load and store memcache driver using multiple servers'); + $this->assertTrue($item->set($key)->save(), 'Able to load and store memcache driver using multiple servers'); $options = array(); $options['extension'] = $this->extension; @@ -89,6 +89,6 @@ public function testConstructionOptions() $poolStub->setDriver($driver); $item->setPool($poolStub); $item->setKey($key); - $this->assertTrue($item->set($key), 'Able to load and store memcache driver using default server'); + $this->assertTrue($item->set($key)->save(), 'Able to load and store memcache driver using default server'); } } From 719d597f0c038fdaf2bf50e22aad5f388cf20609 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 00:52:11 -0700 Subject: [PATCH 09/92] Typo/syntax error --- tests/Stash/Test/Driver/EphemeralTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Stash/Test/Driver/EphemeralTest.php b/tests/Stash/Test/Driver/EphemeralTest.php index acf97286..ad47b920 100644 --- a/tests/Stash/Test/Driver/EphemeralTest.php +++ b/tests/Stash/Test/Driver/EphemeralTest.php @@ -31,7 +31,7 @@ public function testKeyCollisions1() $item1 = new Item(); $item1->setPool($poolStub); $item1->setKey(array('##', '#')); - $item1->set('X'->save()); + $item1->set('X')->save(); $item2 = new Item(); $item2->setPool($poolStub); From de27992cd23cdbf1441977ca9a4ba29ec2cc4e8f Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 00:56:10 -0700 Subject: [PATCH 10/92] Added save function to ItemInterface --- src/Stash/Interfaces/ItemInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 0f590422..df1e7c64 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -135,4 +135,5 @@ public function getExpiration(); public function expiresAfter($time); public function expiresAt($expiration); + public function save(); } From 2c5b04e171d869c961c5ddf2903454a35073ed0c Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 01:02:02 -0700 Subject: [PATCH 11/92] Changed `getItemIterator` to `getItems` --- src/Stash/Interfaces/PoolInterface.php | 2 +- src/Stash/Pool.php | 2 +- tests/Stash/Test/AbstractPoolTest.php | 6 +++--- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 16a5ab3b..2a6390b8 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -66,7 +66,7 @@ public function getItem(); * @param array $keys * @return \Iterator */ - public function getItemIterator($keys); + public function getItems($keys); /** * Empties the entire cache pool of all Items. diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index b2372261..2c756042 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -150,7 +150,7 @@ public function getItem() /** * {@inheritdoc} */ - public function getItemIterator($keys) + public function getItems($keys) { // temporarily cheating here by wrapping around single calls. diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index 80bba6ea..f1849661 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -88,13 +88,13 @@ public function testGetItemInvalidKeyMissingNode() $item = $pool->getItem('This/Test//Fail'); } - public function testGetItemIterator() + public function testgetItems() { $pool = $this->getTestPool(); $keys = array_keys($this->multiData); - $cacheIterator = $pool->getItemIterator($keys); + $cacheIterator = $pool->getItems($keys); $keyData = $this->multiData; foreach ($cacheIterator as $stash) { $key = $stash->getKey(); @@ -104,7 +104,7 @@ public function testGetItemIterator() } $this->assertCount(0, $keyData, 'all keys are accounted for the in cache iterator'); - $cacheIterator = $pool->getItemIterator($keys); + $cacheIterator = $pool->getItems($keys); foreach ($cacheIterator as $stash) { $key = $stash->getKey(); $data = $stash->get($key); diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index 367acbb2..a7dbd0b4 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -43,7 +43,7 @@ public function getItem() return false; } - public function getItemIterator($keys) + public function getItems($keys) { return false; } From 7c573de5f8ec589692d3005b8152ed44e87ca3c5 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 01:26:09 -0700 Subject: [PATCH 12/92] Added commit, saveDeferred, save, and deleteItems to the Pool Interface --- src/Stash/Interfaces/PoolInterface.php | 6 ++ src/Stash/Pool.php | 41 ++++++++++++ tests/Stash/Test/AbstractPoolTest.php | 66 +++++++++++++++++++- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 21 +++++++ 4 files changed, 133 insertions(+), 1 deletion(-) diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 2a6390b8..55b16e73 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -127,4 +127,10 @@ public function getNamespace(); * @return bool */ public function setLogger($logger); + + + public function commit(); + public function saveDeferred($item); + public function save($item); + public function deleteItems(array $keys); } diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 2c756042..7c1b4219 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -162,6 +162,47 @@ public function getItems($keys) return new \ArrayIterator($items); } + /** + * {@inheritdoc} + */ + public function save($item) + { + $item->save(); + return $this; + } + + /** + * {@inheritdoc} + */ + public function saveDeferred($item) + { + return $this->save($item); + } + + /** + * {@inheritdoc} + */ + public function commit() + { + return true; + } + + + /** + * {@inheritdoc} + */ + public function deleteItems(array $keys) + { + // temporarily cheating here by wrapping around single calls. + + $items = array(); + foreach ($keys as $key) { + $items[] = $this->getItem($key)->clear(); + } + + return $this; + } + /** * {@inheritdoc} */ diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index f1849661..35523d30 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -68,6 +68,38 @@ public function testGetItem() $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } + public function testSaveItem() + { + $pool = $this->getTestPool(); + + $item = $pool->getItem('base', 'one'); + $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); + + $key = $item->getKey(); + $this->assertEquals('base/one', $key, 'Pool sets proper Item key.'); + + $item->set($this->data); + $this->assertEquals($pool, $pool->save($item), 'Pool->save() returns pool instance.'); + $storedData = $item->get(); + $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on passed Item.'); + + $item = $pool->getItem('base', 'one'); + $storedData = $item->get(); + $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); + + $pool->setNamespace('TestNamespace'); + $item = $pool->getItem(array('test', 'item')); + + $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); + } + + public function testCommit() + { + $pool = $this->getTestPool(); + $this->assertTrue($pool->commit()); + } + + /** * @expectedException InvalidArgumentException * @expectedExceptionMessage Item constructor requires a key. @@ -88,7 +120,7 @@ public function testGetItemInvalidKeyMissingNode() $item = $pool->getItem('This/Test//Fail'); } - public function testgetItems() + public function testGetItems() { $pool = $this->getTestPool(); @@ -112,6 +144,38 @@ public function testgetItems() } } + public function testDeleteItems() + { + $pool = $this->getTestPool(); + + $keys = array_keys($this->multiData); + + $cacheIterator = $pool->getItems($keys); + $keyData = $this->multiData; + foreach ($cacheIterator as $stash) { + $key = $stash->getKey(); + $this->assertTrue($stash->isMiss(), 'new Cache in iterator is empty'); + $stash->set($keyData[$key])->save(); + unset($keyData[$key]); + } + $this->assertCount(0, $keyData, 'all keys are accounted for the in cache iterator'); + + $cacheIterator = $pool->getItems($keys); + foreach ($cacheIterator as $item) { + $key = $item->getKey(); + $data = $item->get($key); + $this->assertEquals($this->multiData[$key], $data, 'data put into the pool comes back the same through iterators.'); + } + + $this->assertEquals($pool, $pool->deleteItems($keys), 'deleteItems returns Pool class.'); + $cacheIterator = $pool->getItems($keys); + foreach ($cacheIterator as $item) { + $this->assertTrue($item->isMiss(), 'data cleared using deleteItems is removed from the cache.'); + } + } + + + public function testFlushCache() { $pool = $this->getTestPool(); diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index a7dbd0b4..d0b63c3c 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -72,4 +72,25 @@ public function setLogger($logger) { return false; } + + public function commit() + { + return false; + } + + public function saveDeferred($item) + { + return false; + } + + public function save($item) + { + return false; + } + + public function deleteItems(array $keys) + { + return false; + } + } From 10b18d8292d7e8e7663d152aed50fe4a76db2131 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 3 Aug 2015 01:27:14 -0700 Subject: [PATCH 13/92] Fixed formatting --- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index d0b63c3c..6b62a64c 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -92,5 +92,4 @@ public function deleteItems(array $keys) { return false; } - } From 84e2638d965eb25d2da87ae61fcdb039a9d6dd31 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 18:55:15 -0700 Subject: [PATCH 14/92] Extend from RuntimeException --- src/Stash/Exception/WindowsPathMaxLengthException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stash/Exception/WindowsPathMaxLengthException.php b/src/Stash/Exception/WindowsPathMaxLengthException.php index 2c5d481c..f57fdba6 100644 --- a/src/Stash/Exception/WindowsPathMaxLengthException.php +++ b/src/Stash/Exception/WindowsPathMaxLengthException.php @@ -28,7 +28,7 @@ * @package Stash\Exception * @author Jonathan Chan */ -class WindowsPathMaxLengthException extends \Exception implements Exception +class WindowsPathMaxLengthException extends RuntimeException implements Exception { public function __construct($message="", $code=0, $previous=null) { From 5f50f70b1193720d94badb515734dcb7a0617002 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 19:10:01 -0700 Subject: [PATCH 15/92] Stopped "collecting" deleted items --- src/Stash/Pool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 972f629e..38c3ecb1 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -198,7 +198,7 @@ public function deleteItems(array $keys) $items = array(); foreach ($keys as $key) { - $items[] = $this->getItem($key)->clear(); + $this->getItem($key)->clear(); } return $this; From cbf4723030aa57713e9172a58b43dcd96261e8e2 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 19:19:31 -0700 Subject: [PATCH 16/92] Added isHit function --- src/Stash/Interfaces/ItemInterface.php | 8 ++++++++ src/Stash/Item.php | 9 +++++++++ tests/Stash/Test/AbstractItemTest.php | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index df1e7c64..7766d635 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -67,6 +67,14 @@ public function clear(); */ public function get(); + /** + * Returns true if the cached item is valid and usable. + * + * @return bool + */ + public function isHit(); + + /** * Returns true if the cached item needs to be refreshed. * diff --git a/src/Stash/Item.php b/src/Stash/Item.php index d2f08327..97a9198e 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -294,6 +294,15 @@ private function executeGet($invalidation = Invalidation::PRECOMPUTE, $arg = nul return isset($record['data']['return']) ? $record['data']['return'] : null; } + + /** + * {@inheritdoc} + */ + public function isHit() + { + return !$this->isMiss(); + } + /** * {@inheritdoc} */ diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index f7852f47..1fea5966 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -341,6 +341,22 @@ public function testIsMiss() $this->assertTrue(!$stash->isMiss(), 'isMiss returns false for valid data'); } + public function testIsHit() + { + $stash = $this->testConstruct(array('This', 'Should', 'Fail')); + $this->assertFalse($stash->isHit(), 'isHit returns false for missing data'); + $data = $stash->get(); + $this->assertNull($data, 'getData returns null for missing data'); + + $key = array('isHit', 'test'); + + $stash = $this->testConstruct($key); + $stash->set('testString')->save(); + + $stash = $this->testConstruct($key); + $this->assertTrue($stash->isHit(), 'isHit returns true for valid data'); + } + public function testClear() { // repopulate From 30877014fe5a3a38d86aefb89fb17e5cb02eb8e9 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 19:29:36 -0700 Subject: [PATCH 17/92] Added "exists" function --- src/Stash/Interfaces/PoolInterface.php | 1 + src/Stash/Pool.php | 8 ++++++++ tests/Stash/Test/AbstractPoolTest.php | 13 +++++++++++++ tests/Stash/Test/Stubs/PoolGetDriverStub.php | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 55b16e73..26a6ee84 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -133,4 +133,5 @@ public function commit(); public function saveDeferred($item); public function save($item); public function deleteItems(array $keys); + public function exists($key); } diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 38c3ecb1..c3aa30b4 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -163,6 +163,14 @@ public function getItems($keys) return new \ArrayIterator($items); } + /** + * {@inheritdoc} + */ + public function exists($key) + { + return $this->getItem($key)->isHit(); + } + /** * {@inheritdoc} */ diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index 03d97ac0..b410fc74 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -73,6 +73,7 @@ public function testSaveItem() { $pool = $this->getTestPool(); + $this->assertFalse($pool->exists('base/one'), 'Pool->exists() returns false for item without stored data.'); $item = $pool->getItem('base', 'one'); $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); @@ -88,12 +89,24 @@ public function testSaveItem() $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); + $this->assertTrue($pool->exists('base/one'), 'Pool->exists() returns true for item with stored data.'); + $pool->setNamespace('TestNamespace'); $item = $pool->getItem(array('test', 'item')); $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } + public function testExists() + { + $pool = $this->getTestPool(); + $this->assertFalse($pool->exists('base/one'), 'Pool->exists() returns false for item without stored data.'); + $item = $pool->getItem('base', 'one'); + $item->set($this->data); + $pool->save($item); + $this->assertTrue($pool->exists('base/one'), 'Pool->exists() returns true for item with stored data.'); + } + public function testCommit() { $pool = $this->getTestPool(); diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index 6b62a64c..a7392e57 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -73,6 +73,11 @@ public function setLogger($logger) return false; } + public function exists($key) + { + return false; + } + public function commit() { return false; From 44fd506836f8aa507599a01fbd31ec243a78ed61 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 19:33:51 -0700 Subject: [PATCH 18/92] Made expiresAt throw InvalidArgumentException on non-datetime arguments --- src/Stash/Item.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 97a9198e..53630b71 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -12,6 +12,7 @@ namespace Stash; use Stash\Exception\Exception; +use Stash\Exception\InvalidArgumentException; use Stash\Interfaces\DriverInterface; use Stash\Interfaces\ItemInterface; use Stash\Interfaces\PoolInterface; @@ -374,6 +375,10 @@ public function setTTL($ttl = null) public function expiresAt($expiration = null) { + if(!is_null($expiration) && !($expiration instanceof \DateTimeInterface)) { + throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); + } + $this->expiration = $expiration; return $this; } From ee777fa46dcae342dd8e66e4f61096383a72cda0 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 19:39:09 -0700 Subject: [PATCH 19/92] Formatting --- src/Stash/Item.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 53630b71..962d03a4 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -375,8 +375,8 @@ public function setTTL($ttl = null) public function expiresAt($expiration = null) { - if(!is_null($expiration) && !($expiration instanceof \DateTimeInterface)) { - throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); + if (!is_null($expiration) && !($expiration instanceof \DateTimeInterface)) { + throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); } $this->expiration = $expiration; From 072bae11c949843da15996cd17b60e14d1bb65dc Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 19:39:52 -0700 Subject: [PATCH 20/92] Added PSR-6 additions to changelog --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d375153e..4043c912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ +## Stash v1.0.0 Changelog + +### v1.0.0 + +* The `set` function no longer persists data. + +* Removed expiration time for `set` function + +* Added `expiresAt` and `expiresAfter` functions to the Item class. + +* `getExpiration` to return current datetime when no record exists. + +* Added `save` function to ItemInterface. + +* Changed `getItemIterator` to `getItems` + +* RuntimeException now extends from \RuntimeException + +* Added `isHit` function to ItemInterface. + +* Added the "exists" function, which should mostly be avoided. + + ## Stash v0.13 Changelog ### 0.13.1 From f8f7e5acbdd6a113ae1d9361037b06ff02db0b7a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 20:23:18 -0700 Subject: [PATCH 21/92] Rejiggered the exists function --- CHANGELOG.md | 4 +++- src/Stash/Item.php | 21 +++++++++++++++++++++ tests/Stash/Test/AbstractItemTest.php | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4043c912..13f69369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ * Added `isHit` function to ItemInterface. -* Added the "exists" function, which should mostly be avoided. +* Added the `exists` function to ItemInterface, which should mostly be avoided. + +* Added the `exists` function to the Pool, which should mostly be avoided. ## Stash v0.13 Changelog diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 962d03a4..ac884f4f 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -469,6 +469,27 @@ public function extend($ttl = null) return $this->set($this->get(), $ttl); } + /** + * {@inheritdoc} + */ + public function exists() + { + if ($this->isDisabled()) { + return false; + } + $storedData = $this->driver->getData($this->key); + + if ($storedData === false) { + return false; + } + + if (!is_array($storedData)) { + return false; + } + + return isset($storedData['data']); + } + /** * {@inheritdoc} */ diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 1fea5966..17e39254 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -357,6 +357,22 @@ public function testIsHit() $this->assertTrue($stash->isHit(), 'isHit returns true for valid data'); } + public function testExists() + { + $stash = $this->testConstruct(array('This', 'Should', 'Fail')); + $this->assertFalse($stash->exists(), 'exists returns false for missing data'); + $data = $stash->get(); + $this->assertNull($data, 'getData returns null for missing data'); + + $key = array('isHit', 'test'); + + $stash = $this->testConstruct($key); + $stash->set('testString')->save(); + + $stash = $this->testConstruct($key); + $this->assertTrue($stash->exists(), 'exists returns true for valid data'); + } + public function testClear() { // repopulate From 5d24d2be67cae489733220c0e1c9cd1bdb4f848d Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 20:23:32 -0700 Subject: [PATCH 22/92] Documented Interfaces --- src/Stash/Interfaces/ItemInterface.php | 28 +++++++++++++++++++++- src/Stash/Interfaces/PoolInterface.php | 33 ++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 7766d635..44f7465d 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -140,8 +140,34 @@ public function getCreation(); public function getExpiration(); - + /** + * Sets the expiration based off of an integer or DateInterval + * + * @param int|\DateInterval $time + * @return static The invoked object. + */ public function expiresAfter($time); + + + /** + * Sets the expiration to a specific time. + * + * @param \DateTimeInterface $expiration + * @return static The invoked object. + */ public function expiresAt($expiration); + + + /** + * Persists the Item's value to the backend storage. + * + * @return bool + */ public function save(); + + + /** + * @return boolean True if item exists in the cache, false otherwise. + */ + public function exists(); } diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 26a6ee84..7c2bd76f 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -128,10 +128,39 @@ public function getNamespace(); */ public function setLogger($logger); - + /** + * Forces any save-deferred objects to get flushed to the backend drivers. + */ public function commit(); + + /** + * Sets an Item to be saved at some point. This allows buffering for + * multi-save events. + * + * @param CacheItemInterface $item + * @return static The invoked object. + */ public function saveDeferred($item); + + /** + * Sets an Item to be saved immediately. + * + * @param CacheItemInterface $item + * @return static The invoked object. + */ public function save($item); + + /** + * Removes multiple items from the pool. + * + * @param array $keys + * @return static The invoked object. + */ public function deleteItems(array $keys); - public function exists($key); + + + /** + * @return boolean True if item exists in the cache, false otherwise. + */ + public function exists(); } From ad8bf397cbc0390011a936a0289facd47572162f Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 20:30:15 -0700 Subject: [PATCH 23/92] Added DateTime php5.4 compatibility fix --- src/Stash/Item.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index ac884f4f..dbf26a17 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -376,7 +376,10 @@ public function setTTL($ttl = null) public function expiresAt($expiration = null) { if (!is_null($expiration) && !($expiration instanceof \DateTimeInterface)) { - throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); + # For compatbility with PHP 5.4 we also allow inheriting from the DateTime object. + if(!($expiration instanceof \DateTime)) { + throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); + } } $this->expiration = $expiration; From e95926fa5a6a246e8a3be14d7adb3dcb52fba515 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 20:34:44 -0700 Subject: [PATCH 24/92] Fixed formatting and exists signature --- src/Stash/Interfaces/PoolInterface.php | 5 ++++- src/Stash/Item.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 7c2bd76f..19c85df6 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -160,7 +160,10 @@ public function deleteItems(array $keys); /** + * Checks for the existance of an item in the cache. + * + * @param array|string $key * @return boolean True if item exists in the cache, false otherwise. */ - public function exists(); + public function exists($key); } diff --git a/src/Stash/Item.php b/src/Stash/Item.php index dbf26a17..f3e16018 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -377,8 +377,8 @@ public function expiresAt($expiration = null) { if (!is_null($expiration) && !($expiration instanceof \DateTimeInterface)) { # For compatbility with PHP 5.4 we also allow inheriting from the DateTime object. - if(!($expiration instanceof \DateTime)) { - throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); + if (!($expiration instanceof \DateTime)) { + throw new InvalidArgumentException('expiresAt requires \DateTimeInterface or null'); } } From 373420f666bc87f17a0f2ce04791ebc33d721adb Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 22:40:47 -0700 Subject: [PATCH 25/92] Removed unused method "setDriver" --- src/Stash/Item.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index f3e16018..57fe0f75 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -511,16 +511,6 @@ public function setLogger($logger) $this->logger = $logger; } - /** - * Sets the driver this object uses to interact with the caching system. - * - * @param DriverInterface $driver - */ - protected function setDriver(DriverInterface $driver) - { - $this->driver = $driver; - } - /** * Logs an exception with the Logger class, if it exists. * From 0ccae4809a0275573ffef29ea250158a44ebed7a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 22:41:03 -0700 Subject: [PATCH 26/92] Added additional expiration tests --- tests/Stash/Test/AbstractItemTest.php | 78 ++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 17e39254..ecf345c3 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -261,7 +261,57 @@ public function testInvalidation() $this->assertEquals($oldValue, $Item_SPtest->get(), 'Expired lock is ignored'); } - public function testSetWithDateTime() + public function testSetTTLDatetime() + { + $expiration = new \DateTime('now'); + $expiration->add(new \DateInterval('P1D')); + + $key = array('ttl', 'expiration', 'test'); + $stash = $this->testConstruct($key); + + $stash->set(array(1, 2, 3, 'apples')) + ->setTTL($expiration) + ->save(); + $this->assertEquals($expiration, $stash->getExpiration()); + + $stash = $this->testConstruct($key); + $data = $stash->get(); + $this->assertEquals(array(1, 2, 3, 'apples'), $data, 'getData returns data stores using a datetime expiration'); + $this->assertLessThanOrEqual($expiration->getTimestamp(), $stash->getExpiration()->getTimestamp()); + } + + public function testSetTTLDateInterval() + { + $interval = new \DateInterval('P1D'); + $expiration = new \DateTime('now'); + $expiration->add($interval); + + $key = array('ttl', 'expiration', 'test'); + $stash = $this->testConstruct($key); + $stash->set(array(1, 2, 3, 'apples')) + ->setTTL($interval) + ->save(); + + $stash = $this->testConstruct($key); + $data = $stash->get(); + $this->assertEquals(array(1, 2, 3, 'apples'), $data, 'getData returns data stores using a datetime expiration'); + $this->assertLessThanOrEqual($expiration->getTimestamp(), $stash->getExpiration()->getTimestamp()); + } + + public function testSetTTLNulll() + { + + $key = array('ttl', 'expiration', 'test'); + $stash = $this->testConstruct($key); + $stash->set(array(1, 2, 3, 'apples')) + ->setTTL(null) + ->save(); + + $this->assertAttributeEquals(null, 'expiration', $stash); + } + + + public function testExpiresAt() { $expiration = new \DateTime('now'); $expiration->add(new \DateInterval('P1D')); @@ -276,8 +326,34 @@ public function testSetWithDateTime() $stash = $this->testConstruct($key); $data = $stash->get(); $this->assertEquals(array(1, 2, 3, 'apples'), $data, 'getData returns data stores using a datetime expiration'); + $this->assertLessThanOrEqual($expiration->getTimestamp(), $stash->getExpiration()->getTimestamp()); + } + + /** + * @expectedException Stash\Exception\InvalidArgumentException + * @expectedExceptionMessage expiresAt requires \DateTimeInterface or null + */ + public function testExpiresAtException() + { + $stash = $this->testConstruct(array('base', 'expiration', 'test')); + $stash->expiresAt(false); + } + + public function testExpiresAfterWithDateTimeInterval() + { + $key = array('base', 'expiration', 'test'); + $stash = $this->testConstruct($key); + + $stash->set(array(1, 2, 3, 'apples')) + ->expiresAfter(new \DateInterval('P1D')) + ->save(); + + $stash = $this->testConstruct($key); + $data = $stash->get(); + $this->assertEquals(array(1, 2, 3, 'apples'), $data, 'getData returns data stores using a datetime expiration'); } + public function testGetCreation() { $creation = new \DateTime('now'); From b35808aea58e7cae012c33f2004b2353248cf8b1 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 22:41:58 -0700 Subject: [PATCH 27/92] formatting --- tests/Stash/Test/AbstractItemTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index ecf345c3..4ace4943 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -300,7 +300,6 @@ public function testSetTTLDateInterval() public function testSetTTLNulll() { - $key = array('ttl', 'expiration', 'test'); $stash = $this->testConstruct($key); $stash->set(array(1, 2, 3, 'apples')) From 3aef95a16a86a28f96ef795094d2a8e5a801f981 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 22:55:05 -0700 Subject: [PATCH 28/92] Switched datetime test for compatibility with set(array(1, 2, 3, 'apples')) ->setTTL($expiration) ->save(); - $this->assertEquals($expiration, $stash->getExpiration()); + $this->assertLessThanOrEqual($expiration->getTimestamp(), $stash->getExpiration()->getTimestamp()); $stash = $this->testConstruct($key); $data = $stash->get(); From d912ae01c95df82067e17523388da237ad038c64 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 22:55:19 -0700 Subject: [PATCH 29/92] Changed exception test to handle php7 TypeError --- tests/Stash/Test/AbstractItemTest.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 44a4cccf..56d8f165 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -151,17 +151,20 @@ public function testGet() $this->assertEquals(null, $item->get(), 'Item without key returns null for get.'); } - /** - * @expectedException PHPUnit_Framework_Error - * @expectedExceptionMessage Argument 1 passed to Stash\Item::setKey() - */ public function testGetItemInvalidKey() { - $item = $this->getItem(); - $poolStub = new PoolGetDriverStub(); - $poolStub->setDriver(new Ephemeral(array())); - $item->setPool($poolStub); - $item->setKey('This is not an array'); + try { + $item = $this->getItem(); + $poolStub = new PoolGetDriverStub(); + $poolStub->setDriver(new Ephemeral(array())); + $item->setPool($poolStub); + $item->setKey('This is not an array'); + } + catch (\Exception $expected) { + return; + } + + $this->fail('An expected exception has not been raised.'); } public function testLock() From 94ee3539605f34ecc208eeed02384abfbff78476 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 22:56:14 -0700 Subject: [PATCH 30/92] Formatting --- tests/Stash/Test/AbstractItemTest.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 56d8f165..82d75c4b 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -154,13 +154,12 @@ public function testGet() public function testGetItemInvalidKey() { try { - $item = $this->getItem(); - $poolStub = new PoolGetDriverStub(); - $poolStub->setDriver(new Ephemeral(array())); - $item->setPool($poolStub); - $item->setKey('This is not an array'); - } - catch (\Exception $expected) { + $item = $this->getItem(); + $poolStub = new PoolGetDriverStub(); + $poolStub->setDriver(new Ephemeral(array())); + $item->setPool($poolStub); + $item->setKey('This is not an array'); + } catch (\Exception $expected) { return; } From 62684994d445cfb4bc84e60fd43fb9f7fa5d1838 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 23:06:55 -0700 Subject: [PATCH 31/92] Added php5.4 datetime compatibility --- src/Stash/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 57fe0f75..c6af5b01 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -365,7 +365,7 @@ public function setTTL($ttl = null) { if (is_numeric($ttl) || ($ttl instanceof \DateInterval)) { return $this->expiresAfter($ttl); - } elseif ($ttl instanceof \DateTimeInterface) { + } elseif (($ttl instanceof \DateTimeInterface) || ($ttl instanceof \DateTime)) { return $this->expiresAt($ttl); } else { $this->expiration = null; From 0471deb5ac0e34f30ab2a4f73b25a766ac8ae1d1 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 23:57:33 -0700 Subject: [PATCH 32/92] Removed dead code path Driver is set by constructor so this is never reached. --- src/Stash/Pool.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index c3aa30b4..600e4c48 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -274,10 +274,6 @@ public function setDriver(DriverInterface $driver) */ public function getDriver() { - if (!isset($this->driver)) { - $this->driver = new Ephemeral(); - } - return $this->driver; } From e901c390cd3d99e84404ba368b3ed700235ac453 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 8 Aug 2015 23:57:58 -0700 Subject: [PATCH 33/92] Added additional testing of the pool class. --- tests/Stash/Test/AbstractPoolTest.php | 64 ++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index b410fc74..2f99f964 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -33,8 +33,14 @@ class AbstractPoolTest extends \PHPUnit_Framework_TestCase public function testSetDriver() { - $pool = $this->getTestPool(); + $driver = new Ephemeral(); + $pool = new $this->poolClass($driver); + $this->assertAttributeEquals($driver, 'driver', $pool); + } + public function testSetItemDriver() + { + $pool = $this->getTestPool(); $stash = $pool->getItem('test'); $this->assertAttributeInstanceOf('Stash\Driver\Ephemeral', 'driver', $stash, 'set driver is pushed to new stash objects'); } @@ -49,6 +55,28 @@ public function testSetItemClass() $this->assertAttributeEquals($mockClassName, 'itemClass', $pool); } + public function testSetItemClassFakeClassException() + { + try { + $pool = $this->getTestPool(); + $pool->setItemClass('FakeClassName'); + } catch (\Exception $expected) { + return; + } + $this->fail('An expected exception has not been raised.'); + } + + public function testSetItemClassImproperClassException() + { + try { + $pool = $this->getTestPool(); + $pool->setItemClass('\stdClass'); + } catch (\Exception $expected) { + return; + } + $this->fail('An expected exception has not been raised.'); + } + public function testGetItem() { $pool = $this->getTestPool(); @@ -97,6 +125,35 @@ public function testSaveItem() $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } + + public function testSaveDeferredItem() + { + $pool = $this->getTestPool(); + + $this->assertFalse($pool->exists('base/one'), 'Pool->exists() returns false for item without stored data.'); + $item = $pool->getItem('base', 'one'); + $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); + + $key = $item->getKey(); + $this->assertEquals('base/one', $key, 'Pool sets proper Item key.'); + + $item->set($this->data); + $this->assertEquals($pool, $pool->saveDeferred($item), 'Pool->save() returns pool instance.'); + $storedData = $item->get(); + $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on passed Item.'); + + $item = $pool->getItem('base', 'one'); + $storedData = $item->get(); + $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); + + $this->assertTrue($pool->exists('base/one'), 'Pool->exists() returns true for item with stored data.'); + + $pool->setNamespace('TestNamespace'); + $item = $pool->getItem(array('test', 'item')); + + $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); + } + public function testExists() { $pool = $this->getTestPool(); @@ -257,7 +314,10 @@ public function testSetLogger() $logger = new LoggerStub(); $pool->setLogger($logger); - $this->assertAttributeInstanceOf('Stash\Test\Stubs\LoggerStub', 'logger', $pool, 'setLogger injects logger into Item.'); + $this->assertAttributeInstanceOf('Stash\Test\Stubs\LoggerStub', 'logger', $pool, 'setLogger injects logger into Pool.'); + + $item = $pool->getItem('testItem'); + $this->assertAttributeInstanceOf('Stash\Test\Stubs\LoggerStub', 'logger', $item, 'setLogger injects logger into Pool.'); } public function testLoggerFlush() From 1f410e3e884377cb6cb9932553b20e9e65ca36e1 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 00:47:23 -0700 Subject: [PATCH 34/92] Removed SQLite2 --- src/Stash/Driver/Sqlite.php | 5 - src/Stash/Driver/Sub/Sqlite.php | 302 ------------------ src/Stash/Driver/Sub/SqlitePdo.php | 90 ------ tests/Stash/Test/Driver/SqliteSqlite2Test.php | 45 --- 4 files changed, 442 deletions(-) delete mode 100644 src/Stash/Driver/Sub/Sqlite.php delete mode 100644 src/Stash/Driver/Sub/SqlitePdo.php delete mode 100644 tests/Stash/Test/Driver/SqliteSqlite2Test.php diff --git a/src/Stash/Driver/Sqlite.php b/src/Stash/Driver/Sqlite.php index 9904035c..8043753a 100644 --- a/src/Stash/Driver/Sqlite.php +++ b/src/Stash/Driver/Sqlite.php @@ -74,17 +74,12 @@ public function setOptions(array $options = array()) if (Sub\SqlitePdo::isAvailable()) { $subdrivers['pdo'] = '\Stash\Driver\Sub\SqlitePdo'; } - if (Sub\Sqlite::isAvailable()) { - $subdrivers['sqlite'] = '\Stash\Driver\Sub\Sqlite'; - } if (Sub\SqlitePdo2::isAvailable()) { $subdrivers['pdo2'] = '\Stash\Driver\Sub\SqlitePdo2'; } if ($extension == 'pdo' && $version != '2' && isset($subdrivers['pdo'])) { $driver = $subdrivers['pdo']; - } elseif ($extension == 'sqlite' && isset($subdrivers['sqlite'])) { - $driver = $subdrivers['sqlite']; } elseif ($extension == 'pdo' && $version != '3' && isset($subdrivers['pdo2'])) { $driver = $subdrivers['pdo2']; } elseif (count($subdrivers) > 0 && $extension == 'any') { diff --git a/src/Stash/Driver/Sub/Sqlite.php b/src/Stash/Driver/Sub/Sqlite.php deleted file mode 100644 index 09b891cc..00000000 --- a/src/Stash/Driver/Sub/Sqlite.php +++ /dev/null @@ -1,302 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Stash\Driver\Sub; - -use Stash\Exception\RuntimeException; -use Stash\Exception\InvalidArgumentException; - -/** - * Class Sqlite - * - * This SQLite subdriver is used by the main Sqlite driver for interacting with the SQLite extension. - * - * @internal - * @package Stash - * @author Robert Hafner - */ -class Sqlite -{ - /** - * Directory where the SQLite databases are stored. - * - * @var string - */ - protected $path; - - /** - * Output of buildDriver, used to interact with the relevant SQLite extension. - * - * @var \SQLiteDatabase - */ - protected $driver; - - /** - * The SQLite query used to generate the database. - * - * @var string - */ - protected $creationSql = 'CREATE TABLE cacheStore ( - key TEXT UNIQUE ON CONFLICT REPLACE, - expiration INTEGER, - encoding TEXT, - data BLOB - ); - CREATE INDEX keyIndex ON cacheStore (key);'; - - /** - * File permissions of new SQLite databases. - * - * @var string - */ - protected $filePermissions; - - /** - * File permissions of new directories leading to SQLite databases. - * - * @var string - */ - protected $dirPermissions; - - /** - * Amounts of time to wait for the SQLite engine before timing out. - * - * @var int milliseconds - */ - protected $busyTimeout; - - /** - * The appropriate response code to use when retrieving data. - * - * @var int - */ - protected $responseCode; - - /** - * @param string $path - * @param string $directoryPermission - * @param string $filePermission - * @param int $busyTimeout - */ - public function __construct($path, $directoryPermission, $filePermission, $busyTimeout) - { - $this->path = $path; - $this->filePermissions = $filePermission; - $this->dirPermissions = $directoryPermission; - $this->busyTimeout = $busyTimeout; - $this->responseCode = 1; // SQLITE_ASSOC - } - - /** - * Clear out driver, closing file sockets. - */ - public function __destruct() - { - $this->driver = null; - } - - /** - * Retrieves data from cache store. - * - * @param string $key - * @return bool|mixed - */ - public function get($key) - { - if (!($driver = $this->getDriver())) { - return false; - } - - $query = $driver->query("SELECT * FROM cacheStore WHERE key LIKE '{$key}'"); - if ($query === false) { - return false; - } - - if ($resultArray = $query->fetch($this->responseCode)) { - return unserialize(base64_decode($resultArray['data'])); - } - - return false; - } - - /** - * Stores data in sqlite database. - * - * @param string $key - * @param mixed $value - * @param int $expiration - * @return bool - */ - public function set($key, $value, $expiration) - { - if (!($driver = $this->getDriver())) { - return false; - } - - $data = base64_encode(serialize($value)); - - $contentLength = strlen($data); - if ($contentLength > 100000) { - $this->setTimeout($this->busyTimeout * (ceil($contentLength / 100000))); // .5s per 100k - } - - $driver->query("INSERT INTO cacheStore (key, expiration, data) - VALUES ('{$key}', '{$expiration}', '{$data}')"); - - return true; - } - - /** - * Clears data from database. If a key is defined only it and it's children are removed. If everything is set to be - * cleared then the database itself is deleted off disk. - * - * @param null|string $key - * @return bool - */ - public function clear($key = null) - { - // return true if the cache is already empty - if (!($driver = $this->getDriver())) { - return true; - } - - if (!isset($key)) { - unset($driver); - $this->driver = null; - $this->driver = false; - \Stash\Utilities::deleteRecursive($this->path); - } else { - $driver->query("DELETE FROM cacheStore WHERE key LIKE '{$key}%'"); - } - - return true; - } - - /** - * Old data is removed and the "vacuum" operation is run. - * - * @return bool - */ - public function purge() - { - if (!($driver = $this->getDriver())) { - return false; - } - - $driver->query('DELETE FROM cacheStore WHERE expiration < ' . time()); - $driver->query('VACUUM'); - - return true; - } - - /** - * Filesystem integrity and permissions are checked and exceptions thrown for relevant issues. - * - * @throws \Stash\Exception\InvalidArgumentException - * @throws \Stash\Exception\RuntimeException - */ - public function checkFileSystemPermissions() - { - if (!isset($this->path)) { - throw new RuntimeException('No cache path is set.'); - } - - if (!is_writable($this->path) && !is_writable(dirname($this->path))) { - throw new InvalidArgumentException('The cache sqlite file is not writable.'); - } - } - - /** - * Returns true if the SQLiteDatabase class exists. - * - * @return bool - */ - public static function isAvailable() - { - return class_exists('SQLiteDatabase', false); - } - - /** - * Tells the SQLite driver how long to wait for data to be written. - * - * @param int $milliseconds - * @return bool - */ - protected function setTimeout($milliseconds) - { - if (!($driver = $this->getDriver())) { - return false; - } - $driver->busyTimeout($milliseconds); - } - - /** - * Retrieves the relevant SQLite driver, creating the database file if necessary. - * - * @return \SQLiteDatabase - * @throws \Stash\Exception\RuntimeException - */ - protected function getDriver() - { - if (isset($this->driver) && $this->driver !== false) { - return $this->driver; - } - - if (!file_exists($this->path)) { - $dir = $this->path; - - // Since PHP will understand paths with mixed slashes- both the windows \ and unix / variants- we have - // to test for both and see which one is the last in the string. - $pos1 = strrpos($this->path, '/'); - $pos2 = strrpos($this->path, '\\'); - - if ($pos1 || $pos2) { - $pos = $pos1 >= $pos2 ? $pos1 : $pos2; - $dir = substr($this->path, 0, $pos); - } - - if (!is_dir($dir)) { - mkdir($dir, $this->dirPermissions, true); - } - $runInstall = true; - } else { - $runInstall = false; - } - - $db = $this->buildDriver(); - - if ($runInstall && !$db->query($this->creationSql)) { - unlink($this->path); - throw new RuntimeException('Unable to set SQLite: structure'); - } - $this->driver = $db; - - // prevent the cache from getting hungup waiting on a return - $this->setTimeout($this->busyTimeout); - - return $db; - } - - /** - * Creates the actual database driver itself. - * - * @return \SQLiteDatabase - * @throws \Stash\Exception\RuntimeException - */ - protected function buildDriver() - { - if (!$db = new \SQLiteDatabase($this->path, $this->filePermissions, $errorMessage)) { - throw new RuntimeException('Unable to open SQLite Database: ' . $errorMessage); - } - - return $db; - } -} diff --git a/src/Stash/Driver/Sub/SqlitePdo.php b/src/Stash/Driver/Sub/SqlitePdo.php deleted file mode 100644 index 60bee68e..00000000 --- a/src/Stash/Driver/Sub/SqlitePdo.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Stash\Driver\Sub; - -/** - * Class SqlitePDO - * - * This SQLite subdriver uses PDO and the latest version of SQLite. - * - * @internal - * @package Stash - * @author Robert Hafner - */ -class SqlitePdo extends Sqlite -{ - /** - * Output of buildDriver, used to interact with the relevant SQLite extension. - * - * @var \PDO - */ - protected $driver; - - /** - * PDO driver string, used to distinguish between SQLite versions. - * - * @var string - */ - protected static $pdoDriver = 'sqlite'; - - /** - * {@inheritdoc} - */ - protected $responseCode = \PDO::FETCH_ASSOC; - - /** - * {@inheritdoc} - */ - public function __construct($path, $directoryPermission, $filePermission, $busyTimeout) - { - parent::__construct($path, $directoryPermission, $filePermission, $busyTimeout); - $this->responseCode = \PDO::FETCH_ASSOC; - } - - /** - * Checks that PDO extension is present and has the appropriate SQLite driver. - * - */ - public static function isAvailable() - { - if (!class_exists('\PDO', false)) { - return false; - } - - $drivers = \PDO::getAvailableDrivers(); - - return in_array(static::$pdoDriver, $drivers); - } - - /** - * {@inheritdoc} - */ - protected function setTimeout($milliseconds) - { - if (!($driver = $this->getDriver())) { - return false; - } - - $timeout = ceil($milliseconds / 1000); - $driver->setAttribute(\PDO::ATTR_TIMEOUT, $timeout); - } - - /** - * {@inheritdoc} - */ - protected function buildDriver() - { - $db = new \PDO(static::$pdoDriver . ':' . $this->path); - - return $db; - } -} diff --git a/tests/Stash/Test/Driver/SqliteSqlite2Test.php b/tests/Stash/Test/Driver/SqliteSqlite2Test.php deleted file mode 100644 index adad35df..00000000 --- a/tests/Stash/Test/Driver/SqliteSqlite2Test.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Stash\Test\Driver; - -/** - * @package Stash - * @author Robert Hafner - */ -class SqliteSqlite2Test extends AbstractDriverTest -{ - protected $driverClass = 'Stash\Driver\Sqlite'; - protected $subDriverClass = 'Stash\Driver\Sub\Sqlite'; - - protected function setUp() - { - $driver = '\\' . $this->driverClass; - $subDriver = '\\' . $this->subDriverClass; - - if (!$driver::isAvailable() || !$subDriver::isAvailable()) { - $this->markTestSkipped('Driver class unsuited for current environment'); - - return; - } - - parent::setUp(); - } - - public function getOptions() - { - $options = parent::getOptions(); - $options['extension'] = 'sqlite'; - $options['nesting'] = 2; - - return $options; - } -} From 711f5d932bf70ec7bc3a3b511b31b488d7b98746 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 00:54:21 -0700 Subject: [PATCH 35/92] Fixed SqlitePDO class --- src/Stash/Driver/Sqlite.php | 2 +- src/Stash/Driver/Sub/SqlitePdo.php | 313 +++++++++++++++++++++++++++++ 2 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 src/Stash/Driver/Sub/SqlitePdo.php diff --git a/src/Stash/Driver/Sqlite.php b/src/Stash/Driver/Sqlite.php index 8043753a..b5f453dd 100644 --- a/src/Stash/Driver/Sqlite.php +++ b/src/Stash/Driver/Sqlite.php @@ -276,7 +276,7 @@ protected function checkStatus() */ public static function isAvailable() { - return (Sub\SqlitePdo::isAvailable()) || (Sub\Sqlite::isAvailable()) || (Sub\SqlitePdo2::isAvailable()); + return (Sub\SqlitePdo::isAvailable()) || (Sub\SqlitePdo2::isAvailable()); } /** diff --git a/src/Stash/Driver/Sub/SqlitePdo.php b/src/Stash/Driver/Sub/SqlitePdo.php new file mode 100644 index 00000000..216bf78e --- /dev/null +++ b/src/Stash/Driver/Sub/SqlitePdo.php @@ -0,0 +1,313 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Stash\Driver\Sub; + +/** + * Class SqlitePDO + * + * This SQLite subdriver uses PDO and the latest version of SQLite. + * + * @internal + * @package Stash + * @author Robert Hafner + */ +class SqlitePdo +{ + /** + * Directory where the SQLite databases are stored. + * + * @var string + */ + protected $path; + + /** + * Output of buildDriver, used to interact with the relevant SQLite extension. + * + * @var \PDO + */ + protected $driver; + + /** + * PDO driver string, used to distinguish between SQLite versions. + * + * @var string + */ + protected static $pdoDriver = 'sqlite'; + + + /** + * The SQLite query used to generate the database. + * + * @var string + */ + protected $creationSql = 'CREATE TABLE cacheStore ( + key TEXT UNIQUE ON CONFLICT REPLACE, + expiration INTEGER, + encoding TEXT, + data BLOB + ); + CREATE INDEX keyIndex ON cacheStore (key);'; + + /** + * File permissions of new SQLite databases. + * + * @var string + */ + protected $filePermissions; + + /** + * File permissions of new directories leading to SQLite databases. + * + * @var string + */ + protected $dirPermissions; + + /** + * Amounts of time to wait for the SQLite engine before timing out. + * + * @var int milliseconds + */ + protected $busyTimeout; + + /** + * The appropriate response code to use when retrieving data. + * + * @var int + */ + protected $responseCode; + + /** + * @param string $path + * @param string $directoryPermission + * @param string $filePermission + * @param int $busyTimeout + */ + public function __construct($path, $directoryPermission, $filePermission, $busyTimeout) + { + $this->path = $path; + $this->filePermissions = $filePermission; + $this->dirPermissions = $directoryPermission; + $this->busyTimeout = $busyTimeout; + $this->responseCode = \PDO::FETCH_ASSOC; + } + + /** + * Clear out driver, closing file sockets. + */ + public function __destruct() + { + $this->driver = null; + } + + /** + * Retrieves data from cache store. + * + * @param string $key + * @return bool|mixed + */ + public function get($key) + { + if (!($driver = $this->getDriver())) { + return false; + } + + $query = $driver->query("SELECT * FROM cacheStore WHERE key LIKE '{$key}'"); + if ($query === false) { + return false; + } + + if ($resultArray = $query->fetch($this->responseCode)) { + return unserialize(base64_decode($resultArray['data'])); + } + + return false; + } + + /** + * Stores data in sqlite database. + * + * @param string $key + * @param mixed $value + * @param int $expiration + * @return bool + */ + public function set($key, $value, $expiration) + { + if (!($driver = $this->getDriver())) { + return false; + } + + $data = base64_encode(serialize($value)); + + $contentLength = strlen($data); + if ($contentLength > 100000) { + $this->setTimeout($this->busyTimeout * (ceil($contentLength / 100000))); // .5s per 100k + } + + $driver->query("INSERT INTO cacheStore (key, expiration, data) + VALUES ('{$key}', '{$expiration}', '{$data}')"); + + return true; + } + + /** + * Clears data from database. If a key is defined only it and it's children are removed. If everything is set to be + * cleared then the database itself is deleted off disk. + * + * @param null|string $key + * @return bool + */ + public function clear($key = null) + { + // return true if the cache is already empty + if (!($driver = $this->getDriver())) { + return true; + } + + if (!isset($key)) { + unset($driver); + $this->driver = null; + $this->driver = false; + \Stash\Utilities::deleteRecursive($this->path); + } else { + $driver->query("DELETE FROM cacheStore WHERE key LIKE '{$key}%'"); + } + + return true; + } + + /** + * Old data is removed and the "vacuum" operation is run. + * + * @return bool + */ + public function purge() + { + if (!($driver = $this->getDriver())) { + return false; + } + + $driver->query('DELETE FROM cacheStore WHERE expiration < ' . time()); + $driver->query('VACUUM'); + + return true; + } + + /** + * Filesystem integrity and permissions are checked and exceptions thrown for relevant issues. + * + * @throws \Stash\Exception\InvalidArgumentException + * @throws \Stash\Exception\RuntimeException + */ + public function checkFileSystemPermissions() + { + if (!isset($this->path)) { + throw new RuntimeException('No cache path is set.'); + } + + if (!is_writable($this->path) && !is_writable(dirname($this->path))) { + throw new InvalidArgumentException('The cache sqlite file is not writable.'); + } + } + + /** + * Checks that PDO extension is present and has the appropriate SQLite driver. + * + */ + public static function isAvailable() + { + if (!class_exists('\PDO', false)) { + return false; + } + + $drivers = \PDO::getAvailableDrivers(); + + return in_array(static::$pdoDriver, $drivers); + } + + + /** + * Tells the SQLite driver how long to wait for data to be written. + * + * @param int $milliseconds + * @return bool + */ + protected function setTimeout($milliseconds) + { + if (!($driver = $this->getDriver())) { + return false; + } + + $timeout = ceil($milliseconds / 1000); + $driver->setAttribute(\PDO::ATTR_TIMEOUT, $timeout); + } + + /** + * Retrieves the relevant SQLite driver, creating the database file if necessary. + * + * @return \SQLiteDatabase + * @throws \Stash\Exception\RuntimeException + */ + protected function getDriver() + { + if (isset($this->driver) && $this->driver !== false) { + return $this->driver; + } + + if (!file_exists($this->path)) { + $dir = $this->path; + + // Since PHP will understand paths with mixed slashes- both the windows \ and unix / variants- we have + // to test for both and see which one is the last in the string. + $pos1 = strrpos($this->path, '/'); + $pos2 = strrpos($this->path, '\\'); + + if ($pos1 || $pos2) { + $pos = $pos1 >= $pos2 ? $pos1 : $pos2; + $dir = substr($this->path, 0, $pos); + } + + if (!is_dir($dir)) { + mkdir($dir, $this->dirPermissions, true); + } + $runInstall = true; + } else { + $runInstall = false; + } + + $db = $this->buildDriver(); + + if ($runInstall && !$db->query($this->creationSql)) { + unlink($this->path); + throw new RuntimeException('Unable to set SQLite: structure'); + } + $this->driver = $db; + + // prevent the cache from getting hungup waiting on a return + $this->setTimeout($this->busyTimeout); + + return $db; + } + + /** + * Creates the actual database driver itself. + * + * @return \SQLiteDatabase + * @throws \Stash\Exception\RuntimeException + */ + protected function buildDriver() + { + $db = new \PDO(static::$pdoDriver . ':' . $this->path); + + return $db; + } +} From 3a638886d65357a42ae1e7dfd54e11b494d8a9c4 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 01:08:54 -0700 Subject: [PATCH 36/92] Updated changelog- removed sqlite3 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f69369..1a65d975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### v1.0.0 +* Removed SQLite Extension support (SQLite3 is still available). + * The `set` function no longer persists data. * Removed expiration time for `set` function From 58e716f29c9f31438d7ec59d3d3ed811a6bf0174 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 01:24:55 -0700 Subject: [PATCH 37/92] Install apcu-beta for apc testing --- tests/travis/php_setup.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index a44e55af..171d1afd 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -42,6 +42,21 @@ else set -e echo "Finished installing uopz extension." + + + if [ "$TRAVIS_PHP_VERSION" != "5.4" && "$TRAVIS_PHP_VERSION" != "hhvm" ] + then + echo "" + echo "******************************" + echo "Installing apcu-beta extension" + echo "******************************" + set +e + echo "no" | pecl install apcu-beta + set -e + echo "Finished installing apcu-beta extension." + fi + + echo "" echo "*********************" echo "Updating php.ini file" From 3a2bd4df7452b878e1fca7b7f6f9d66aa60e3e31 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 01:31:20 -0700 Subject: [PATCH 38/92] Fixed comparison format --- tests/travis/php_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 171d1afd..146175f8 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -44,7 +44,7 @@ else - if [ "$TRAVIS_PHP_VERSION" != "5.4" && "$TRAVIS_PHP_VERSION" != "hhvm" ] + if [ "$TRAVIS_PHP_VERSION" != "5.4" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] then echo "" echo "******************************" From dacc1b90a463f6e7b514d59c851990df4e12b7e9 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 01:40:38 -0700 Subject: [PATCH 39/92] Replaced check for apc extension with check for apc_fetch function --- src/Stash/Driver/Apc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index 5be0ab1d..4c19d254 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -150,8 +150,7 @@ public static function isAvailable() return false; } - return (extension_loaded('apc') && ini_get('apc.enabled')) - && ((php_sapi_name() !== 'cli') || ini_get('apc.enable_cli')); + return function_exists('apc_fetch'); } /** From 1de9efa7724d35c278a09bd3a8a9234615473dee Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 01:41:09 -0700 Subject: [PATCH 40/92] Removed pac extension as the pecl command adds it to php.ini --- tests/travis/php_extensions.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/travis/php_extensions.ini b/tests/travis/php_extensions.ini index 7fa8c39f..62d061f6 100644 --- a/tests/travis/php_extensions.ini +++ b/tests/travis/php_extensions.ini @@ -1,7 +1,6 @@ -extension="apc.so" extension="memcache.so" extension="memcached.so" extension="redis.so" apc.enabled=1 -apc.enable_cli=1 +apc.enable_cli=1 From f03ec63744a3e9de6a7e4db5f8e39ffad688c1d0 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 02:13:23 -0700 Subject: [PATCH 41/92] Manually adding apache extension to php.ini --- tests/travis/php_setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 146175f8..12b053cf 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -52,6 +52,7 @@ else echo "******************************" set +e echo "no" | pecl install apcu-beta + echo "extension = apcu.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini set -e echo "Finished installing apcu-beta extension." fi From 4687cb608b9371b2f405659bc2ff4815c2f1f43a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 02:16:00 -0700 Subject: [PATCH 42/92] Added apc.so back to php5.4 build --- tests/travis/php_setup.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 12b053cf..7d4f7a59 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -42,6 +42,10 @@ else set -e echo "Finished installing uopz extension." + if [ "$TRAVIS_PHP_VERSION" == "5.4" ] + then + echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + fi if [ "$TRAVIS_PHP_VERSION" != "5.4" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] From 140f84154bd47a0030a149f341ba895aba2ec490 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 02:27:22 -0700 Subject: [PATCH 43/92] Another attempt to make travis use the apcu and apc extensions --- tests/travis/php_extensions.ini | 2 ++ tests/travis/php_setup.sh | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/travis/php_extensions.ini b/tests/travis/php_extensions.ini index 62d061f6..d541248c 100644 --- a/tests/travis/php_extensions.ini +++ b/tests/travis/php_extensions.ini @@ -1,3 +1,5 @@ +extension="apc.so" +extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 7d4f7a59..b89ea24c 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -42,11 +42,6 @@ else set -e echo "Finished installing uopz extension." - if [ "$TRAVIS_PHP_VERSION" == "5.4" ] - then - echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - fi - if [ "$TRAVIS_PHP_VERSION" != "5.4" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] then @@ -56,7 +51,6 @@ else echo "******************************" set +e echo "no" | pecl install apcu-beta - echo "extension = apcu.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini set -e echo "Finished installing apcu-beta extension." fi From d8d28675ae51f8fb6dab299246f4dbf2d320bf66 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 02:32:16 -0700 Subject: [PATCH 44/92] Removed useless addition of apcu extension --- tests/travis/php_extensions.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/travis/php_extensions.ini b/tests/travis/php_extensions.ini index d541248c..4ad3ced4 100644 --- a/tests/travis/php_extensions.ini +++ b/tests/travis/php_extensions.ini @@ -1,5 +1,4 @@ extension="apc.so" -extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" From e9131f6e0464d0d8950c3a70e18702a6db74c5c0 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 10:49:56 -0700 Subject: [PATCH 45/92] Split travis-ci php config by version --- ..._extensions.ini => php_extensions_5.4.ini} | 0 tests/travis/php_extensions_5.5.ini | 7 +++++++ tests/travis/php_extensions_5.6.ini | 7 +++++++ tests/travis/php_setup.sh | 21 ++++++++++--------- 4 files changed, 25 insertions(+), 10 deletions(-) rename tests/travis/{php_extensions.ini => php_extensions_5.4.ini} (100%) create mode 100644 tests/travis/php_extensions_5.5.ini create mode 100644 tests/travis/php_extensions_5.6.ini diff --git a/tests/travis/php_extensions.ini b/tests/travis/php_extensions_5.4.ini similarity index 100% rename from tests/travis/php_extensions.ini rename to tests/travis/php_extensions_5.4.ini diff --git a/tests/travis/php_extensions_5.5.ini b/tests/travis/php_extensions_5.5.ini new file mode 100644 index 00000000..6acc7e8f --- /dev/null +++ b/tests/travis/php_extensions_5.5.ini @@ -0,0 +1,7 @@ + +extension="memcache.so" +extension="memcached.so" +extension="redis.so" + +apc.enabled=1 +apc.enable_cli=1 diff --git a/tests/travis/php_extensions_5.6.ini b/tests/travis/php_extensions_5.6.ini new file mode 100644 index 00000000..6acc7e8f --- /dev/null +++ b/tests/travis/php_extensions_5.6.ini @@ -0,0 +1,7 @@ + +extension="memcache.so" +extension="memcached.so" +extension="redis.so" + +apc.enabled=1 +apc.enable_cli=1 diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index b89ea24c..0d9e2361 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -43,7 +43,7 @@ else echo "Finished installing uopz extension." - if [ "$TRAVIS_PHP_VERSION" != "5.4" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] + if [ "$TRAVIS_PHP_VERSION" != "5.4" ] then echo "" echo "******************************" @@ -55,13 +55,14 @@ else echo "Finished installing apcu-beta extension." fi - - echo "" - echo "*********************" - echo "Updating php.ini file" - echo "*********************" - echo "" - echo "" - phpenv config-add tests/travis/php_extensions.ini - + if [ -f "tests/travis/php_extensions_${TRAVIS_PHP_VERSION}.ini" ] + then + echo "" + echo "*********************" + echo "Updating php.ini file" + echo "*********************" + echo "" + echo "" + phpenv config-add "tests/travis/php_extensions_${TRAVIS_PHP_VERSION}.ini" + fi fi \ No newline at end of file From 57b14ebd37607882dedc83af64bf002bdb7bd4ab Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 11:13:21 -0700 Subject: [PATCH 46/92] Added "isPersistent" test --- src/Stash/Driver/Apc.php | 9 +++++++++ tests/Stash/Test/Driver/AbstractDriverTest.php | 12 ++++++++++++ tests/Stash/Test/Driver/ApcTest.php | 1 + tests/Stash/Test/Driver/FileSystemTest.php | 1 + tests/Stash/Test/Driver/MemcacheTest.php | 1 + tests/Stash/Test/Driver/RedisArrayTest.php | 1 + tests/Stash/Test/Driver/RedisTest.php | 1 + tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php | 1 + tests/Stash/Test/Driver/SqlitePdoSqlite3Test.php | 1 + 9 files changed, 28 insertions(+) diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index 4c19d254..7fb9e93e 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -186,4 +186,13 @@ protected function getCacheTime($expiration) return $this->ttl < $life ? $this->ttl : $life; } + + + /** + * {@inheritdoc} + */ + public function isPersistent() + { + return true; + } } diff --git a/tests/Stash/Test/Driver/AbstractDriverTest.php b/tests/Stash/Test/Driver/AbstractDriverTest.php index 9ac57701..e35b6391 100644 --- a/tests/Stash/Test/Driver/AbstractDriverTest.php +++ b/tests/Stash/Test/Driver/AbstractDriverTest.php @@ -44,6 +44,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase protected $driverClass; protected $startTime; protected $setup = false; + protected $persistence = false; public static function tearDownAfterClass() { @@ -227,4 +228,15 @@ public function testDestructor($driver) { $driver=null; } + + /** + * @depends testDestructor + */ + public function testIsPersistant() + { + if (!$driver = $this->getFreshDriver()) { + $this->markTestSkipped('Driver class unsuited for current environment'); + } + $this->assertEquals($this->persistence, $driver->isPersistent()); + } } diff --git a/tests/Stash/Test/Driver/ApcTest.php b/tests/Stash/Test/Driver/ApcTest.php index 857b047a..2785b377 100644 --- a/tests/Stash/Test/Driver/ApcTest.php +++ b/tests/Stash/Test/Driver/ApcTest.php @@ -18,6 +18,7 @@ class ApcTest extends AbstractDriverTest { protected $driverClass = 'Stash\Driver\Apc'; + protected $persistence = true; public function testSetOptions() { diff --git a/tests/Stash/Test/Driver/FileSystemTest.php b/tests/Stash/Test/Driver/FileSystemTest.php index fc435154..416f73f4 100644 --- a/tests/Stash/Test/Driver/FileSystemTest.php +++ b/tests/Stash/Test/Driver/FileSystemTest.php @@ -28,6 +28,7 @@ class FileSystemTest extends AbstractDriverTest { protected $driverClass = 'Stash\Driver\FileSystem'; protected $extension = '.php'; + protected $persistence = true; protected function getOptions($options = array()) { diff --git a/tests/Stash/Test/Driver/MemcacheTest.php b/tests/Stash/Test/Driver/MemcacheTest.php index 994aa873..78362921 100644 --- a/tests/Stash/Test/Driver/MemcacheTest.php +++ b/tests/Stash/Test/Driver/MemcacheTest.php @@ -25,6 +25,7 @@ class MemcacheTest extends AbstractDriverTest protected $extension = 'memcache'; protected $servers = array('127.0.0.1', '11211'); + protected $persistence = true; protected function getOptions() { diff --git a/tests/Stash/Test/Driver/RedisArrayTest.php b/tests/Stash/Test/Driver/RedisArrayTest.php index acc9ab76..858b9b4e 100644 --- a/tests/Stash/Test/Driver/RedisArrayTest.php +++ b/tests/Stash/Test/Driver/RedisArrayTest.php @@ -21,6 +21,7 @@ class RedisArrayTest extends RedisTest protected $redisSecondServer = '127.0.0.1'; protected $redisSecondPort = '6380'; + protected $persistence = true; protected function setUp() { diff --git a/tests/Stash/Test/Driver/RedisTest.php b/tests/Stash/Test/Driver/RedisTest.php index ca4f1d6c..4d728c7b 100644 --- a/tests/Stash/Test/Driver/RedisTest.php +++ b/tests/Stash/Test/Driver/RedisTest.php @@ -23,6 +23,7 @@ class RedisTest extends AbstractDriverTest protected $redisNoServer = '127.0.0.1'; protected $redisNoPort = '6381'; + protected $persistence = true; protected function setUp() { diff --git a/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php b/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php index 123d0e5c..a5d5b84a 100644 --- a/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php +++ b/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php @@ -19,6 +19,7 @@ class SqlitePdoSqlite2Test extends AbstractDriverTest { protected $driverClass = 'Stash\Driver\Sqlite'; protected $subDriverClass = 'Stash\Driver\Sub\SqlitePdo2'; + protected $persistence = true; protected function setUp() { diff --git a/tests/Stash/Test/Driver/SqlitePdoSqlite3Test.php b/tests/Stash/Test/Driver/SqlitePdoSqlite3Test.php index cd89b4aa..65144b2d 100644 --- a/tests/Stash/Test/Driver/SqlitePdoSqlite3Test.php +++ b/tests/Stash/Test/Driver/SqlitePdoSqlite3Test.php @@ -19,6 +19,7 @@ class SqlitePdoSqlite3Test extends AbstractDriverTest { protected $driverClass = 'Stash\Driver\Sqlite'; protected $subDriverClass = 'Stash\Driver\Sub\SqlitePdo'; + protected $persistence = true; protected function setUp() { From a5a8a2010f6807b50ff1a4c98d8f3af576ee114a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 14:19:38 -0700 Subject: [PATCH 47/92] Testing changes to apcu extension for travis ci --- tests/travis/php_extensions_5.5.ini | 2 +- tests/travis/php_extensions_5.6.ini | 2 +- tests/travis/php_setup.sh | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/travis/php_extensions_5.5.ini b/tests/travis/php_extensions_5.5.ini index 6acc7e8f..5a33e8a1 100644 --- a/tests/travis/php_extensions_5.5.ini +++ b/tests/travis/php_extensions_5.5.ini @@ -1,4 +1,4 @@ - +extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" diff --git a/tests/travis/php_extensions_5.6.ini b/tests/travis/php_extensions_5.6.ini index 6acc7e8f..5a33e8a1 100644 --- a/tests/travis/php_extensions_5.6.ini +++ b/tests/travis/php_extensions_5.6.ini @@ -1,4 +1,4 @@ - +extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 0d9e2361..707746bb 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -50,7 +50,8 @@ else echo "Installing apcu-beta extension" echo "******************************" set +e - echo "no" | pecl install apcu-beta + pecl config-set preferred_state beta + printf "yes\n" | pecl install apcu set -e echo "Finished installing apcu-beta extension." fi From cfa2b05bea6804aebe14a8ab96f53b8deebcf6a9 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 15:42:32 -0700 Subject: [PATCH 48/92] Removed apache extension (again), since pecl also adds it --- tests/travis/php_extensions_5.5.ini | 1 - tests/travis/php_extensions_5.6.ini | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/travis/php_extensions_5.5.ini b/tests/travis/php_extensions_5.5.ini index 5a33e8a1..62d061f6 100644 --- a/tests/travis/php_extensions_5.5.ini +++ b/tests/travis/php_extensions_5.5.ini @@ -1,4 +1,3 @@ -extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" diff --git a/tests/travis/php_extensions_5.6.ini b/tests/travis/php_extensions_5.6.ini index 5a33e8a1..62d061f6 100644 --- a/tests/travis/php_extensions_5.6.ini +++ b/tests/travis/php_extensions_5.6.ini @@ -1,4 +1,3 @@ -extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" From cac1f2df81c23e69b4fba5586b13135cc5112ae2 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 15:53:20 -0700 Subject: [PATCH 49/92] Upgraded phpunit to 4.8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 06c749a6..d7bac29e 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "require-dev": { "fabpot/php-cs-fixer": "^1.9", - "phpunit/phpunit": "4.7.*", + "phpunit/phpunit": "4.8.*", "satooshi/php-coveralls": "dev-master" }, "autoload": { From 49678149253c05b9222ca8a1d609b2cedfa7add8 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 16:10:51 -0700 Subject: [PATCH 50/92] Test Redit Socket --- tests/Stash/Test/Driver/RedisSocketTest.php | 27 +++++++++++++++++++++ tests/travis/files/redis/redis-server2.conf | 24 +++++++++--------- 2 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 tests/Stash/Test/Driver/RedisSocketTest.php diff --git a/tests/Stash/Test/Driver/RedisSocketTest.php b/tests/Stash/Test/Driver/RedisSocketTest.php new file mode 100644 index 00000000..62241cbc --- /dev/null +++ b/tests/Stash/Test/Driver/RedisSocketTest.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Stash\Test\Driver; + +/** + * @package Stash + * @author Robert Hafner + */ +class RedisSocketTest extends RedisTest +{ + protected function getOptions() + { + $socket = '/tmp/redis.sock' + return array('servers' => array( + array('socket' => $socket, 'ttl' => 0.1) + )); + } +} diff --git a/tests/travis/files/redis/redis-server2.conf b/tests/travis/files/redis/redis-server2.conf index 1c41fc50..675a5e9b 100644 --- a/tests/travis/files/redis/redis-server2.conf +++ b/tests/travis/files/redis/redis-server2.conf @@ -33,8 +33,8 @@ port 6380 # incoming connections. There is no default, so Redis will not listen # on a unix socket when not specified. # -# unixsocket /tmp/redis.sock -# unixsocketperm 755 +unixsocket /tmp/redis.sock +unixsocketperm 755 # Close the connection after a client is idle for N seconds (0 to disable) timeout 0 @@ -146,9 +146,9 @@ dbfilename dump.rdb # # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. -# +# # The Append Only File will also be created inside this directory. -# +# # Note that you must specify a directory here, not a file name. dir /var/lib/redis2 @@ -250,7 +250,7 @@ slave-priority 100 # # This should stay commented out for backward compatibility and because most # people do not need auth (e.g. they run their own servers). -# +# # Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break. @@ -316,14 +316,14 @@ slave-priority 100 # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory # is reached. You can select among five behaviors: -# +# # volatile-lru -> remove the key with an expire set using an LRU algorithm # allkeys-lru -> remove any key accordingly to the LRU algorithm # volatile-random -> remove a random key with an expire set # allkeys-random -> remove a random key, any key # volatile-ttl -> remove the key with the nearest expire time (minor TTL) # noeviction -> don't expire at all, just return an error on write operations -# +# # Note: with any of the above policies, Redis will return an error on write # operations, when there are not suitable keys for eviction. # @@ -371,7 +371,7 @@ appendonly no # appendfilename appendonly.aof # The fsync() call tells the Operating System to actually write data on disk -# instead to wait for more data in the output buffer. Some OS will really flush +# instead to wait for more data in the output buffer. Some OS will really flush # data on disk, some other OS will just try to do it ASAP. # # Redis supports three different modes: @@ -412,7 +412,7 @@ appendfsync everysec # the same as "appendfsync none". In practical terms, this means that it is # possible to lose up to 30 seconds of log in the worst scenario (with the # default Linux settings). -# +# # If you have latency problems turn this to "yes". Otherwise leave it as # "no" that is the safest pick from the point of view of durability. no-appendfsync-on-rewrite no @@ -420,7 +420,7 @@ no-appendfsync-on-rewrite no # Automatic rewrite of the append only file. # Redis is able to automatically rewrite the log file implicitly calling # BGREWRITEAOF when the AOF log size grows by the specified percentage. -# +# # This is how it works: Redis remembers the size of the AOF file after the # latest rewrite (if no rewrite has happened since the restart, the size of # the AOF at startup is used). @@ -463,7 +463,7 @@ lua-time-limit 5000 # but just the time needed to actually execute the command (this is the only # stage of command execution where the thread is blocked and can not serve # other requests in the meantime). -# +# # You can configure the slow log with two parameters: one tells Redis # what is the execution time, in microseconds, to exceed in order for the # command to get logged, and the other parameter is the length of the @@ -513,7 +513,7 @@ zset-max-ziplist-value 64 # that is rehashing, the more rehashing "steps" are performed, so if the # server is idle the rehashing is never complete and some more memory is used # by the hash table. -# +# # The default is to use this millisecond 10 times every second in order to # active rehashing the main dictionaries, freeing memory when possible. # From e1bfa342552b9de7979166e8ab89351deb6910b2 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 16:24:26 -0700 Subject: [PATCH 51/92] fixed syntax, yelled at editor --- tests/Stash/Test/Driver/RedisSocketTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Stash/Test/Driver/RedisSocketTest.php b/tests/Stash/Test/Driver/RedisSocketTest.php index 62241cbc..528160ff 100644 --- a/tests/Stash/Test/Driver/RedisSocketTest.php +++ b/tests/Stash/Test/Driver/RedisSocketTest.php @@ -19,7 +19,8 @@ class RedisSocketTest extends RedisTest { protected function getOptions() { - $socket = '/tmp/redis.sock' + $socket = '/tmp/redis.sock'; + return array('servers' => array( array('socket' => $socket, 'ttl' => 0.1) )); From d266c0340d8e04d0d65638cc59a5fe196338ea9d Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 16:31:02 -0700 Subject: [PATCH 52/92] Changed redis socket permissions --- tests/travis/files/redis/redis-server2.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis/files/redis/redis-server2.conf b/tests/travis/files/redis/redis-server2.conf index 675a5e9b..131feed4 100644 --- a/tests/travis/files/redis/redis-server2.conf +++ b/tests/travis/files/redis/redis-server2.conf @@ -34,7 +34,7 @@ port 6380 # on a unix socket when not specified. # unixsocket /tmp/redis.sock -unixsocketperm 755 +unixsocketperm 777 # Close the connection after a client is idle for N seconds (0 to disable) timeout 0 From 26b9bb8c7c28fd5044842212261cc301b7dcce85 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 16:39:52 -0700 Subject: [PATCH 53/92] Added check for throwable in test suite - php7 compatibility --- tests/Stash/Test/AbstractItemTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 82d75c4b..3c622b45 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -159,6 +159,9 @@ public function testGetItemInvalidKey() $poolStub->setDriver(new Ephemeral(array())); $item->setPool($poolStub); $item->setKey('This is not an array'); + + } catch (\Throwable $t) { + return; } catch (\Exception $expected) { return; } From 9dc90adbf449426cee2ca7e1b8096a870c299c70 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 16:43:04 -0700 Subject: [PATCH 54/92] Formatting --- tests/Stash/Test/AbstractItemTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 3c622b45..990e6b7a 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -159,7 +159,6 @@ public function testGetItemInvalidKey() $poolStub->setDriver(new Ephemeral(array())); $item->setPool($poolStub); $item->setKey('This is not an array'); - } catch (\Throwable $t) { return; } catch (\Exception $expected) { From a1ae6c95e095f6ea0707818fe33614415b7ee17a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 16:54:24 -0700 Subject: [PATCH 55/92] Test invalid encoder --- tests/Stash/Test/Driver/FileSystemTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Stash/Test/Driver/FileSystemTest.php b/tests/Stash/Test/Driver/FileSystemTest.php index 416f73f4..0a537d81 100644 --- a/tests/Stash/Test/Driver/FileSystemTest.php +++ b/tests/Stash/Test/Driver/FileSystemTest.php @@ -44,6 +44,17 @@ public function testOptionKeyHashFunctionException() $driver->setOptions($this->getOptions(array('keyHashFunction' => 'foobar_'.mt_rand()))); } + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testOptionEncoderException() + { + $driver = new FileSystem(); + $encoder = new \stdClass(); + $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + } + + public function testOptionKeyHashFunction() { $driver = new FileSystem(array('keyHashFunction' => 'md5')); From 36949886fe2918a48b1c50a5dee7cc8a9c628205 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 17:53:04 -0700 Subject: [PATCH 56/92] Improved Filesystem Encoder testing. --- src/Stash/Driver/FileSystem.php | 5 +++-- tests/Stash/Test/Driver/FileSystemTest.php | 26 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Stash/Driver/FileSystem.php b/src/Stash/Driver/FileSystem.php index 018eace1..ab915759 100644 --- a/src/Stash/Driver/FileSystem.php +++ b/src/Stash/Driver/FileSystem.php @@ -154,10 +154,11 @@ public function setOptions(array $options = array()) } $this->encoder = new $encoder; } else { + $encoderInterface = 'Stash\Driver\FileSystem\EncoderInterface'; $encoderClass = 'Stash\Driver\FileSystem\\' . $encoder . 'Encoder'; - if (class_exists($encoder)) { + if (class_exists($encoder) && in_array($encoderInterface, class_implements($encoder))) { $this->encoder = new $encoder(); - } elseif (class_exists($encoderClass)) { + } elseif (class_exists($encoderClass) && in_array($encoderInterface, class_implements($encoderClass))) { $this->encoder = new $encoderClass(); } else { throw new RuntimeException('Invalid Encoder: ' . $encoder); diff --git a/tests/Stash/Test/Driver/FileSystemTest.php b/tests/Stash/Test/Driver/FileSystemTest.php index 0a537d81..4b997149 100644 --- a/tests/Stash/Test/Driver/FileSystemTest.php +++ b/tests/Stash/Test/Driver/FileSystemTest.php @@ -47,13 +47,37 @@ public function testOptionKeyHashFunctionException() /** * @expectedException Stash\Exception\RuntimeException */ - public function testOptionEncoderException() + public function testOptionEncoderObjectException() { $driver = new FileSystem(); $encoder = new \stdClass(); $driver->setOptions($this->getOptions(array('encoder' => $encoder))); } + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testOptionEncoderStringException() + { + $driver = new FileSystem(); + $encoder = 'stdClass'; + $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + } + + public function testOptionEncoderAsObject() + { + $driver = new FileSystem(); + $encoder = new \Stash\Driver\FileSystem\NativeEncoder(); + $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + } + + public function testOptionEncoderAsString() + { + $driver = new FileSystem(); + $encoder = '\Stash\Driver\FileSystem\NativeEncoder'; + $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + } + public function testOptionKeyHashFunction() { From d92798311dcf39d19c06795fb15be3024813a342 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 18:13:59 -0700 Subject: [PATCH 57/92] Additional Utilities class testing --- tests/Stash/Test/UtilitiesTest.php | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/Stash/Test/UtilitiesTest.php b/tests/Stash/Test/UtilitiesTest.php index 1186a44b..202c22a5 100644 --- a/tests/Stash/Test/UtilitiesTest.php +++ b/tests/Stash/Test/UtilitiesTest.php @@ -120,6 +120,24 @@ public function testDeleteRecursive() $this->assertFileNotExists($tmp, 'deleteRecursive cleared out the empty parent directory'); } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testDeleteRecursiveRelativeException() + { + Utilities::deleteRecursive('../tests/fakename'); + } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testDeleteRecursiveRootException() + { + Utilities::deleteRecursive('/'); + } + + public function testCheckEmptyDirectory() { $tmp = sys_get_temp_dir() . '/stash/'; @@ -130,4 +148,41 @@ public function testCheckEmptyDirectory() $this->assertFalse(Utilities::checkForEmptyDirectory($tmp), 'Returns false for non-empty directories'); Utilities::deleteRecursive($tmp); } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testCheckFileSystemPermissionsNullException() + { + Utilities::checkFileSystemPermissions(null, '0644'); + } + + /** + * @expectedException Stash\Exception\InvalidArgumentException + */ + public function testCheckFileSystemPermissionsFileException() + { + $tmp = sys_get_temp_dir() . '/stash/'; + $dir2 = $tmp . 'emptytest/'; + @mkdir($dir2, 0770, true); + touch($dir2 . 'testfile'); + + Utilities::checkFileSystemPermissions($dir2 . 'testfile', '0644'); + } + + /** + * @expectedException Stash\Exception\InvalidArgumentException + */ + public function testCheckFileSystemPermissionsUnaccessibleException() + { + Utilities::checkFileSystemPermissions('/fakedir/cache', '0644'); + } + + /** + * @expectedException Stash\Exception\InvalidArgumentException + */ + public function testCheckFileSystemPermissionsUnwrittableException() + { + Utilities::checkFileSystemPermissions('/home', '0644'); + } } From bce7ac95dc559a79fcba2ab3114672bfb9b19a8f Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 18:24:29 -0700 Subject: [PATCH 58/92] Tightened up code paths --- src/Stash/Item.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index c6af5b01..ae346cf5 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -420,11 +420,7 @@ public function save() private function executeSet($data, $time) { - if ($this->isDisabled()) { - return false; - } - - if (!isset($this->key)) { + if ($this->isDisabled() || !isset($this->key)) { return false; } @@ -432,13 +428,9 @@ private function executeSet($data, $time) $store['return'] = $data; $store['createdOn'] = time(); - if (isset($time)) { - if ($time instanceof \DateTime) { - $expiration = $time->getTimestamp(); - $cacheTime = $expiration - $store['createdOn']; - } else { - $cacheTime = isset($time) && is_numeric($time) ? $time : self::$cacheTime; - } + if (isset($time) && ($time instanceof \DateTime)) { + $expiration = $time->getTimestamp(); + $cacheTime = $expiration - $store['createdOn']; } else { $cacheTime = self::$cacheTime; } @@ -581,6 +573,7 @@ protected function getRecord() */ protected function validateRecord($validation, &$record) { + $invalidation = Invalidation::PRECOMPUTE; if (is_array($validation)) { $argArray = $validation; $invalidation = isset($argArray[0]) ? $argArray[0] : Invalidation::PRECOMPUTE; @@ -592,8 +585,6 @@ protected function validateRecord($validation, &$record) if (isset($argArray[2])) { $arg2 = $argArray[2]; } - } else { - $invalidation = Invalidation::PRECOMPUTE; } $curTime = microtime(true); From fff6b59ff1825865ba5c3b46caf3b4923df97a8f Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 18:41:49 -0700 Subject: [PATCH 59/92] Tested driver filtering --- tests/Stash/Test/DriverListTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Stash/Test/DriverListTest.php b/tests/Stash/Test/DriverListTest.php index c1789e70..d39a1c57 100644 --- a/tests/Stash/Test/DriverListTest.php +++ b/tests/Stash/Test/DriverListTest.php @@ -31,6 +31,10 @@ public function testGetDrivers() $availableDrivers = DriverList::getAvailableDrivers(); $getDrivers = DriverList::getDrivers(); $this->assertEquals($availableDrivers, $getDrivers, 'getDrivers is an alias for getAvailableDrivers'); + + DriverList::registerDriver('TestBroken', 'stdClass'); + $drivers = DriverList::getDrivers(); + $this->assertArrayNotHasKey('TestBroken', $drivers, 'getDrivers doesn\'t return TestBroken driver'); } public function testRegisterDriver() From d56e636c7279d2356f53ac699d28a8a526c65671 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 18:48:01 -0700 Subject: [PATCH 60/92] Test UnavailableDriver exception in AbstractDriver --- .../Test/Driver/UnavailableDriverTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Stash/Test/Driver/UnavailableDriverTest.php diff --git a/tests/Stash/Test/Driver/UnavailableDriverTest.php b/tests/Stash/Test/Driver/UnavailableDriverTest.php new file mode 100644 index 00000000..a583b63b --- /dev/null +++ b/tests/Stash/Test/Driver/UnavailableDriverTest.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Stash\Test\Driver; + +use Stash\Test\Stubs\DriverUnavailableStub; + +/** + * @package Stash + * @author Robert Hafner + */ +class UnavailableDriverTest extends \PHPUnit_Framework_TestCase +{ + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testUnavailableDriver() + { + new DriverUnavailableStub(); + } + +} From 768d30a62f1ed7bdf3c531a0cada545aef4a7c3e Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 19:04:40 -0700 Subject: [PATCH 61/92] Improved composite driver testing. --- src/Stash/Driver/AbstractDriver.php | 4 ++- src/Stash/Driver/Composite.php | 30 +++++++++++++---------- tests/Stash/Test/Driver/CompositeTest.php | 26 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/Stash/Driver/AbstractDriver.php b/src/Stash/Driver/AbstractDriver.php index 9fa75e96..9f2adc60 100644 --- a/src/Stash/Driver/AbstractDriver.php +++ b/src/Stash/Driver/AbstractDriver.php @@ -36,7 +36,9 @@ public function __construct(array $options = array()) throw new RuntimeException(__CLASS__ . ' is not available.'); } - $this->setOptions($options); + if(count($options) > 0) { + $this->setOptions($options); + } } /** diff --git a/src/Stash/Driver/Composite.php b/src/Stash/Driver/Composite.php index bc1bdf74..d5e89e34 100644 --- a/src/Stash/Driver/Composite.php +++ b/src/Stash/Driver/Composite.php @@ -13,6 +13,7 @@ use Stash; use Stash\Exception\RuntimeException; +use Stash\Exception\InvalidArgumentException; use Stash\Interfaces\DriverInterface; /** @@ -43,23 +44,26 @@ public function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); - if (isset($options['drivers'])) { - if (count($options['drivers']) < 1) { - throw new RuntimeException('One or more secondary drivers are required.'); - } - $this->drivers = array(); + if (!isset($options['drivers']) || (count($options['drivers']) < 1)) { + throw new RuntimeException('One or more secondary drivers are required.'); + } - foreach ($options['drivers'] as $driver) { - if (!(is_object($driver) && $driver instanceof DriverInterface)) { - continue; - } - $this->drivers[] = $driver; - } + if(!is_array($options['drivers'])) { + throw new InvalidArgumentException('Drivers option requires an array.'); + } - if (count($this->drivers) < 1) { - throw new RuntimeException('None of the secondary drivers can be enabled.'); + $this->drivers = array(); + foreach ($options['drivers'] as $driver) { + if (!(is_object($driver) && $driver instanceof DriverInterface)) { + continue; } + $this->drivers[] = $driver; + } + + if (count($this->drivers) < 1) { + throw new RuntimeException('None of the secondary drivers can be enabled.'); } + } /** diff --git a/tests/Stash/Test/Driver/CompositeTest.php b/tests/Stash/Test/Driver/CompositeTest.php index f2cdeff0..ebac724c 100644 --- a/tests/Stash/Test/Driver/CompositeTest.php +++ b/tests/Stash/Test/Driver/CompositeTest.php @@ -112,4 +112,30 @@ public function testIsPersistent() $driver = new Composite(array('drivers' => $drivers)); $this->assertFalse($driver->isPersistent()); } + + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testWithoutDriversException() + { + $driver = new Composite(array('drivers' => null)); + } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testWithFakeDriversException() + { + $driver = new Composite(array('drivers' => array('fakedriver'))); + } + + /** + * @expectedException Stash\Exception\InvalidArgumentException + */ + public function testWithBadDriverArgumentException() + { + $driver = new Composite(array('drivers' => 'fakedriver')); + } + } From 0b85b735114caf03f720d63f67f5bb82cbaf66a8 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 19:05:59 -0700 Subject: [PATCH 62/92] Formatting --- src/Stash/Driver/AbstractDriver.php | 2 +- src/Stash/Driver/Composite.php | 3 +-- tests/Stash/Test/Driver/CompositeTest.php | 1 - tests/Stash/Test/Driver/UnavailableDriverTest.php | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Stash/Driver/AbstractDriver.php b/src/Stash/Driver/AbstractDriver.php index 9f2adc60..fbb7dc70 100644 --- a/src/Stash/Driver/AbstractDriver.php +++ b/src/Stash/Driver/AbstractDriver.php @@ -36,7 +36,7 @@ public function __construct(array $options = array()) throw new RuntimeException(__CLASS__ . ' is not available.'); } - if(count($options) > 0) { + if (count($options) > 0) { $this->setOptions($options); } } diff --git a/src/Stash/Driver/Composite.php b/src/Stash/Driver/Composite.php index d5e89e34..d743ed34 100644 --- a/src/Stash/Driver/Composite.php +++ b/src/Stash/Driver/Composite.php @@ -48,7 +48,7 @@ public function setOptions(array $options = array()) throw new RuntimeException('One or more secondary drivers are required.'); } - if(!is_array($options['drivers'])) { + if (!is_array($options['drivers'])) { throw new InvalidArgumentException('Drivers option requires an array.'); } @@ -63,7 +63,6 @@ public function setOptions(array $options = array()) if (count($this->drivers) < 1) { throw new RuntimeException('None of the secondary drivers can be enabled.'); } - } /** diff --git a/tests/Stash/Test/Driver/CompositeTest.php b/tests/Stash/Test/Driver/CompositeTest.php index ebac724c..c1bcbf2b 100644 --- a/tests/Stash/Test/Driver/CompositeTest.php +++ b/tests/Stash/Test/Driver/CompositeTest.php @@ -137,5 +137,4 @@ public function testWithBadDriverArgumentException() { $driver = new Composite(array('drivers' => 'fakedriver')); } - } diff --git a/tests/Stash/Test/Driver/UnavailableDriverTest.php b/tests/Stash/Test/Driver/UnavailableDriverTest.php index a583b63b..6988392c 100644 --- a/tests/Stash/Test/Driver/UnavailableDriverTest.php +++ b/tests/Stash/Test/Driver/UnavailableDriverTest.php @@ -26,5 +26,4 @@ public function testUnavailableDriver() { new DriverUnavailableStub(); } - } From 29262c30f5e0ff5295866f3463c1b15c4ba2412c Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 19:44:16 -0700 Subject: [PATCH 63/92] Removed dead code --- src/Stash/Utilities.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Stash/Utilities.php b/src/Stash/Utilities.php index 637121cd..35a09517 100644 --- a/src/Stash/Utilities.php +++ b/src/Stash/Utilities.php @@ -158,13 +158,7 @@ public static function deleteRecursive($file, $cleanParent = false) } if (file_exists($filename)) { - if ($file->isDir()) { - if (file_exists($filename)) { - @rmdir($filename); - } - } else { - unlink($filename); - } + unlink($filename); } } From bd717b56c02426fa065471d7b2bbb8ba128844f6 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 20:11:23 -0700 Subject: [PATCH 64/92] Introduced numeric encoding return to streamline filesystem driver --- src/Stash/Driver/FileSystem/NativeEncoder.php | 18 +++++++----------- src/Stash/Utilities.php | 8 ++++++-- tests/Stash/Test/UtilitiesTest.php | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Stash/Driver/FileSystem/NativeEncoder.php b/src/Stash/Driver/FileSystem/NativeEncoder.php index 0cb379a5..6d8565d1 100644 --- a/src/Stash/Driver/FileSystem/NativeEncoder.php +++ b/src/Stash/Driver/FileSystem/NativeEncoder.php @@ -92,22 +92,18 @@ protected function encode($data) $dataString = (bool) $data ? 'true' : 'false'; break; - case 'serialize': - $dataString = 'unserialize(base64_decode(\'' . base64_encode(serialize($data)) . '\'))'; - break; - case 'string': $dataString = sprintf('"%s"', addcslashes($data, "\t\"\$\\")); break; - case 'none': - default : - if (is_numeric($data)) { - $dataString = (string) $data; - } else { - $dataString = 'base64_decode(\'' . base64_encode($data) . '\')'; - } + case 'numeric': + $dataString = (string) $data; break; + + default : + case 'serialize': + $dataString = 'unserialize(base64_decode(\'' . base64_encode(serialize($data)) . '\'))'; + break; } return $dataString; diff --git a/src/Stash/Utilities.php b/src/Stash/Utilities.php index 35a09517..7eaadfa2 100644 --- a/src/Stash/Utilities.php +++ b/src/Stash/Utilities.php @@ -34,8 +34,12 @@ public static function encoding($data) return 'bool'; } - if (is_numeric($data) && ($data >= 2147483648 || $data < -2147483648)) { - return 'serialize'; + if (is_numeric($data)) { + if (is_numeric($data) && ($data >= 2147483648 || $data < -2147483648)) { + return 'serialize'; + } else { + return 'numeric'; + } } if (is_string($data)) { diff --git a/tests/Stash/Test/UtilitiesTest.php b/tests/Stash/Test/UtilitiesTest.php index 202c22a5..54a238a6 100644 --- a/tests/Stash/Test/UtilitiesTest.php +++ b/tests/Stash/Test/UtilitiesTest.php @@ -27,11 +27,11 @@ public function testEncoding() $this->assertEquals(Utilities::encoding('String of doom!'), 'string', 'encoding recognized string scalar'); - $this->assertEquals(Utilities::encoding(234), 'none', 'encoding recognized integer scalar'); - $this->assertEquals(Utilities::encoding(1.432), 'none', 'encoding recognized float scalar'); + $this->assertEquals(Utilities::encoding(234), 'numeric', 'encoding recognized integer scalar'); + $this->assertEquals(Utilities::encoding(1.432), 'numeric', 'encoding recognized float scalar'); $this->assertEquals(Utilities::encoding(pow(2, 31)), 'serialize', 'encoding recognized large number'); - $this->assertEquals(Utilities::encoding(pow(2, 31) - 1), 'none', 'encoding recognized small number'); + $this->assertEquals(Utilities::encoding(pow(2, 31) - 1), 'numeric', 'encoding recognized small number'); $std = new \stdClass(); $this->assertEquals(Utilities::encoding($std), 'serialize', 'encoding recognized object'); From 2c103fd3a726a1516391f1c4d97fe2752a03b111 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 20:14:32 -0700 Subject: [PATCH 65/92] Preset the expiration variable --- src/Stash/Driver/FileSystem/NativeEncoder.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Stash/Driver/FileSystem/NativeEncoder.php b/src/Stash/Driver/FileSystem/NativeEncoder.php index 6d8565d1..aee5c3df 100644 --- a/src/Stash/Driver/FileSystem/NativeEncoder.php +++ b/src/Stash/Driver/FileSystem/NativeEncoder.php @@ -21,16 +21,13 @@ public function deserialize($path) return false; } + $expiration = null; include($path); if (!isset($loaded)) { return false; } - if (!isset($expiration)) { - $expiration = null; - } - if (!isset($data)) { $data = null; } From 5244e312ffa79141c2407aad3f38201a9bfb5c97 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 21:06:16 -0700 Subject: [PATCH 66/92] Set SQLite driver to throw errors on failed driver creation --- src/Stash/Driver/Sub/SqlitePdo.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Stash/Driver/Sub/SqlitePdo.php b/src/Stash/Driver/Sub/SqlitePdo.php index 216bf78e..ba4b0b23 100644 --- a/src/Stash/Driver/Sub/SqlitePdo.php +++ b/src/Stash/Driver/Sub/SqlitePdo.php @@ -116,10 +116,7 @@ public function __destruct() */ public function get($key) { - if (!($driver = $this->getDriver())) { - return false; - } - + $driver = $this->getDriver(); $query = $driver->query("SELECT * FROM cacheStore WHERE key LIKE '{$key}'"); if ($query === false) { return false; @@ -142,10 +139,7 @@ public function get($key) */ public function set($key, $value, $expiration) { - if (!($driver = $this->getDriver())) { - return false; - } - + $driver = $this->getDriver(); $data = base64_encode(serialize($value)); $contentLength = strlen($data); @@ -169,7 +163,9 @@ public function set($key, $value, $expiration) public function clear($key = null) { // return true if the cache is already empty - if (!($driver = $this->getDriver())) { + try { + $driver = $this->getDriver(); + } catch (RuntimeException $e) { return true; } @@ -192,10 +188,7 @@ public function clear($key = null) */ public function purge() { - if (!($driver = $this->getDriver())) { - return false; - } - + $driver = $this->getDriver(); $driver->query('DELETE FROM cacheStore WHERE expiration < ' . time()); $driver->query('VACUUM'); @@ -243,10 +236,7 @@ public static function isAvailable() */ protected function setTimeout($milliseconds) { - if (!($driver = $this->getDriver())) { - return false; - } - + $driver = $this->getDriver(); $timeout = ceil($milliseconds / 1000); $driver->setAttribute(\PDO::ATTR_TIMEOUT, $timeout); } @@ -290,6 +280,11 @@ protected function getDriver() unlink($this->path); throw new RuntimeException('Unable to set SQLite: structure'); } + + if (!$db) { + throw new RuntimeException('SQLite driver failed to load'); + } + $this->driver = $db; // prevent the cache from getting hungup waiting on a return From 6e0dda68856af4cd6b803ca3314de911a4b8bab5 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 21:46:46 -0700 Subject: [PATCH 67/92] Improved testing of invalid memcache options --- tests/Stash/Test/Driver/MemcachedTest.php | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/Stash/Test/Driver/MemcachedTest.php b/tests/Stash/Test/Driver/MemcachedTest.php index 014c296b..0cb7693a 100644 --- a/tests/Stash/Test/Driver/MemcachedTest.php +++ b/tests/Stash/Test/Driver/MemcachedTest.php @@ -32,4 +32,69 @@ protected function getOptions() return array_merge($options, $memcachedOptions); } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testSetHashException() + { + $options = array(); + $options['servers'][] = array('127.0.0.1', '11211', '50'); + $options['servers'][] = array('127.0.0.1', '11211'); + $options['hash'] = 'InvalidOption'; + $driver = new Memcache(); + $driver->setOptions($options); + } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testSetDistributionException() + { + $options = array(); + $options['servers'][] = array('127.0.0.1', '11211', '50'); + $options['servers'][] = array('127.0.0.1', '11211'); + $options['distribution'] = 'InvalidOption'; + $driver = new Memcache(); + $driver->setOptions($options); + } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testSetSerializerException() + { + $options = array(); + $options['servers'][] = array('127.0.0.1', '11211', '50'); + $options['servers'][] = array('127.0.0.1', '11211'); + $options['serializer'] = 'InvalidOption'; + $driver = new Memcache(); + $driver->setOptions($options); + } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testSetNumberedValueException() + { + $options = array(); + $options['servers'][] = array('127.0.0.1', '11211', '50'); + $options['servers'][] = array('127.0.0.1', '11211'); + $options['connect_timeout'] = 'InvalidOption'; + $driver = new Memcache(); + $driver->setOptions($options); + } + + /** + * @expectedException Stash\Exception\RuntimeException + */ + public function testSetBooleanValueException() + { + $options = array(); + $options['servers'][] = array('127.0.0.1', '11211', '50'); + $options['servers'][] = array('127.0.0.1', '11211'); + $options['cache_lookup'] = 'InvalidOption'; + $driver = new Memcache(); + $driver->setOptions($options); + } } From 1cc631303cbeabe3a630c1786ee124c61121ff83 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 21:50:59 -0700 Subject: [PATCH 68/92] Added "use" statement for Memcache driver --- tests/Stash/Test/Driver/MemcachedTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Stash/Test/Driver/MemcachedTest.php b/tests/Stash/Test/Driver/MemcachedTest.php index 0cb7693a..d7e10855 100644 --- a/tests/Stash/Test/Driver/MemcachedTest.php +++ b/tests/Stash/Test/Driver/MemcachedTest.php @@ -11,6 +11,8 @@ namespace Stash\Test\Driver; +use Stash\Driver\Memcache; + /** * @package Stash * @author Robert Hafner From 292f78d11a71cb84549f35f2f41e9160a46f0423 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 21:55:47 -0700 Subject: [PATCH 69/92] Fixed option name --- tests/Stash/Test/Driver/MemcachedTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Stash/Test/Driver/MemcachedTest.php b/tests/Stash/Test/Driver/MemcachedTest.php index d7e10855..6487d5f0 100644 --- a/tests/Stash/Test/Driver/MemcachedTest.php +++ b/tests/Stash/Test/Driver/MemcachedTest.php @@ -11,7 +11,7 @@ namespace Stash\Test\Driver; -use Stash\Driver\Memcache; +use \Stash\Driver\Memcache; /** * @package Stash @@ -95,7 +95,7 @@ public function testSetBooleanValueException() $options = array(); $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); - $options['cache_lookup'] = 'InvalidOption'; + $options['cache_lookups'] = 'InvalidOption'; $driver = new Memcache(); $driver->setOptions($options); } From 1d615c9b761037046911a0b9bfdef4c928384aef Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 22:38:13 -0700 Subject: [PATCH 70/92] Removed deprecated constants --- src/Stash/Item.php | 25 ------------------------- tests/Stash/Test/AbstractItemTest.php | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/Stash/Item.php b/src/Stash/Item.php index ae346cf5..dce41506 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -27,31 +27,6 @@ */ class Item implements ItemInterface { - /** - * @deprecated - */ - const SP_NONE = 0; - - /** - * @deprecated - */ - const SP_OLD = 1; - - /** - * @deprecated - */ - const SP_VALUE = 2; - - /** - * @deprecated - */ - const SP_SLEEP = 3; - - /** - * @deprecated - */ - const SP_PRECOMPUTE = 4; - /** * This is the default time, in seconds, that objects are cached for. * diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 990e6b7a..0cd86a0f 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -12,6 +12,7 @@ namespace Stash\Test; use Stash\Item; +use Stash\Invalidation; use Stash\Utilities; use Stash\Driver\Ephemeral; use Stash\Test\Stubs\PoolGetDriverStub; @@ -188,7 +189,7 @@ public function testInvalidation() // Test without stampede $controlStash = $this->testConstruct($key); - $controlStash->setInvalidationMethod(Item::SP_VALUE, $newValue); + $controlStash->setInvalidationMethod(Invalidation::VALUE, $newValue); $return = $controlStash->get(); $this->assertEquals($oldValue, $return, 'Old value is returned'); $this->assertTrue($controlStash->isMiss()); @@ -200,23 +201,23 @@ public function testInvalidation() // Old $oldStash = $this->testConstruct($key); - $oldStash->setInvalidationMethod(Item::SP_OLD); - $return = $oldStash->get(Item::SP_OLD); + $oldStash->setInvalidationMethod(Invalidation::OLD); + $return = $oldStash->get(Invalidation::OLD); $this->assertEquals($oldValue, $return, 'Old value is returned'); $this->assertFalse($oldStash->isMiss()); unset($oldStash); // Value $valueStash = $this->testConstruct($key); - $valueStash->setInvalidationMethod(Item::SP_VALUE, $newValue); - $return = $valueStash->get(Item::SP_VALUE, $newValue); + $valueStash->setInvalidationMethod(Invalidation::VALUE, $newValue); + $return = $valueStash->get(Invalidation::VALUE, $newValue); $this->assertEquals($newValue, $return, 'New value is returned'); $this->assertFalse($valueStash->isMiss()); unset($valueStash); // Sleep $sleepStash = $this->testConstruct($key); - $sleepStash->setInvalidationMethod(Item::SP_SLEEP, 250, 2); + $sleepStash->setInvalidationMethod(Invalidation::SLEEP, 250, 2); $start = microtime(true); $return = $sleepStash->get(); $end = microtime(true); @@ -244,14 +245,14 @@ public function testInvalidation() // Precompute - test outside limit $precomputeStash = $this->testConstruct($key); - $precomputeStash->setInvalidationMethod(Item::SP_PRECOMPUTE, 10); - $return = $precomputeStash->get(Item::SP_PRECOMPUTE, 10); + $precomputeStash->setInvalidationMethod(Invalidation::PRECOMPUTE, 10); + $return = $precomputeStash->get(Invalidation::PRECOMPUTE, 10); $this->assertFalse($precomputeStash->isMiss(), 'Cache is marked as hit'); unset($precomputeStash); // Precompute - test inside limit $precomputeStash = $this->testConstruct($key); - $precomputeStash->setInvalidationMethod(Item::SP_PRECOMPUTE, 35); + $precomputeStash->setInvalidationMethod(Invalidation::PRECOMPUTE, 35); $return = $precomputeStash->get(); $this->assertTrue($precomputeStash->isMiss(), 'Cache is marked as miss'); unset($precomputeStash); @@ -259,7 +260,7 @@ public function testInvalidation() // Test Stampede Flag Expiration $key = array('stampede', 'expire'); $Item_SPtest = $this->testConstruct($key); - $Item_SPtest->setInvalidationMethod(Item::SP_VALUE, $newValue); + $Item_SPtest->setInvalidationMethod(Invalidation::VALUE, $newValue); $Item_SPtest->set($oldValue)->expiresAfter(-300)->save(); $Item_SPtest->lock(-5); $this->assertEquals($oldValue, $Item_SPtest->get(), 'Expired lock is ignored'); From 4e17819d4c4c50f8116e2751c369a4d3ea996c76 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 9 Aug 2015 22:46:25 -0700 Subject: [PATCH 71/92] Removed deprecated DriverList::getDrivers function. --- src/Stash/DriverList.php | 11 ----------- tests/Stash/Test/DriverListTest.php | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Stash/DriverList.php b/src/Stash/DriverList.php index 5bd53abc..60689b82 100644 --- a/src/Stash/DriverList.php +++ b/src/Stash/DriverList.php @@ -99,15 +99,4 @@ public static function getDriverClass($name) return self::$drivers[$name]; } - - /** - * Returns a list of cache drivers that are also supported by this system. - * - * @deprecated Deprecated in favor of getAvailableDrivers. - * @return array - */ - public static function getDrivers() - { - return self::getAvailableDrivers(); - } } diff --git a/tests/Stash/Test/DriverListTest.php b/tests/Stash/Test/DriverListTest.php index d39a1c57..bf11f054 100644 --- a/tests/Stash/Test/DriverListTest.php +++ b/tests/Stash/Test/DriverListTest.php @@ -24,24 +24,28 @@ public function testGetAvailableDrivers() $drivers = DriverList::getAvailableDrivers(); $this->assertArrayHasKey('FileSystem', $drivers, 'getDrivers returns FileSystem driver'); $this->assertArrayNotHasKey('Array', $drivers, 'getDrivers doesn\'t return Array driver'); + + DriverList::registerDriver('TestUnavailable_getAvailable', '\Stash\Test\Stubs\DriverUnavailableStub'); + $drivers = DriverList::getAvailableDrivers(); + $this->assertArrayNotHasKey('TestUnavailable_getAvailable', $drivers, 'getAllDrivers doesn\'t return TestBroken driver'); } - public function testGetDrivers() + public function testGetAllDrivers() { - $availableDrivers = DriverList::getAvailableDrivers(); - $getDrivers = DriverList::getDrivers(); - $this->assertEquals($availableDrivers, $getDrivers, 'getDrivers is an alias for getAvailableDrivers'); + DriverList::registerDriver('TestBroken_getAll', 'stdClass'); + $drivers = DriverList::getAllDrivers(); + $this->assertArrayNotHasKey('TestBroken_getAll', $drivers, 'getAllDrivers doesn\'t return TestBroken driver'); - DriverList::registerDriver('TestBroken', 'stdClass'); - $drivers = DriverList::getDrivers(); - $this->assertArrayNotHasKey('TestBroken', $drivers, 'getDrivers doesn\'t return TestBroken driver'); + DriverList::registerDriver('TestUnavailable_getAll', '\Stash\Test\Stubs\DriverUnavailableStub'); + $drivers = DriverList::getAllDrivers(); + $this->assertArrayHasKey('TestUnavailable_getAll', $drivers, 'getAllDrivers doesn\'t return TestBroken driver'); } public function testRegisterDriver() { DriverList::registerDriver('Array', 'Stash\Driver\Ephemeral'); - $drivers = DriverList::getDrivers(); + $drivers = DriverList::getAvailableDrivers(); $this->assertArrayHasKey('Array', $drivers, 'getDrivers returns Array driver'); } From 04441c445a2f1a01c1fadc822a4f80d781300892 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Tue, 11 Aug 2015 00:28:45 -0700 Subject: [PATCH 72/92] Added deprecation notices to changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a65d975..05c08f5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### v1.0.0 +* Removed deprecated DriverList::getDrivers function. + +* Removed deprecated invalidation constants in the Item class. + * Removed SQLite Extension support (SQLite3 is still available). * The `set` function no longer persists data. From 18f191202880931d6f7595f973f1e0d9b1196591 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 17 Oct 2015 20:54:07 -0700 Subject: [PATCH 73/92] Brought Stash up to date with the latest PSR-6 draft --- CHANGELOG.md | 4 +--- src/Stash/Interfaces/ItemInterface.php | 8 +------ src/Stash/Interfaces/PoolInterface.php | 4 ++-- src/Stash/Item.php | 23 +------------------- src/Stash/Pool.php | 2 +- tests/Stash/Test/AbstractItemTest.php | 18 +-------------- tests/Stash/Test/AbstractPoolTest.php | 14 ++++++------ tests/Stash/Test/Stubs/PoolGetDriverStub.php | 2 +- 8 files changed, 15 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c08f5b..31bb255a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,7 @@ * Added `isHit` function to ItemInterface. -* Added the `exists` function to ItemInterface, which should mostly be avoided. - -* Added the `exists` function to the Pool, which should mostly be avoided. +* Added the `hasItem` function to the Pool, which should mostly be avoided. ## Stash v0.13 Changelog diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 44f7465d..be0bdf0a 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -97,7 +97,7 @@ public function lock($ttl = null); * unable to be serialized. * * @param mixed $data bool - * @return bool Returns whether the object was successfully stored or not. + * @return static The invoked object */ public function set($data); @@ -164,10 +164,4 @@ public function expiresAt($expiration); * @return bool */ public function save(); - - - /** - * @return boolean True if item exists in the cache, false otherwise. - */ - public function exists(); } diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 19c85df6..296cebcc 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -162,8 +162,8 @@ public function deleteItems(array $keys); /** * Checks for the existance of an item in the cache. * - * @param array|string $key + * @param string $key * @return boolean True if item exists in the cache, false otherwise. */ - public function exists($key); + public function hasItem($key); } diff --git a/src/Stash/Item.php b/src/Stash/Item.php index dce41506..3d7aaaf4 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -329,7 +329,7 @@ public function set($data) } if ($this->isDisabled()) { - return false; + return $this; } $this->data = $data; @@ -439,27 +439,6 @@ public function extend($ttl = null) return $this->set($this->get(), $ttl); } - /** - * {@inheritdoc} - */ - public function exists() - { - if ($this->isDisabled()) { - return false; - } - $storedData = $this->driver->getData($this->key); - - if ($storedData === false) { - return false; - } - - if (!is_array($storedData)) { - return false; - } - - return isset($storedData['data']); - } - /** * {@inheritdoc} */ diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 600e4c48..5d606de3 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -166,7 +166,7 @@ public function getItems($keys) /** * {@inheritdoc} */ - public function exists($key) + public function hasItem($key) { return $this->getItem($key)->isHit(); } diff --git a/tests/Stash/Test/AbstractItemTest.php b/tests/Stash/Test/AbstractItemTest.php index 0cd86a0f..2de7db4b 100644 --- a/tests/Stash/Test/AbstractItemTest.php +++ b/tests/Stash/Test/AbstractItemTest.php @@ -437,22 +437,6 @@ public function testIsHit() $this->assertTrue($stash->isHit(), 'isHit returns true for valid data'); } - public function testExists() - { - $stash = $this->testConstruct(array('This', 'Should', 'Fail')); - $this->assertFalse($stash->exists(), 'exists returns false for missing data'); - $data = $stash->get(); - $this->assertNull($data, 'getData returns null for missing data'); - - $key = array('isHit', 'test'); - - $stash = $this->testConstruct($key); - $stash->set('testString')->save(); - - $stash = $this->testConstruct($key); - $this->assertTrue($stash->exists(), 'exists returns true for valid data'); - } - public function testClear() { // repopulate @@ -580,7 +564,7 @@ private function getMockedDriver() private function assertDisabledStash(\Stash\Interfaces\ItemInterface $item) { - $this->assertFalse($item->set('true'), 'storeData returns false for disabled cache'); + $this->assertEquals($item, $item->set('true'), 'storeData returns self for disabled cache'); $this->assertNull($item->get(), 'getData returns null for disabled cache'); $this->assertFalse($item->clear(), 'clear returns false for disabled cache'); $this->assertTrue($item->isMiss(), 'isMiss returns true for disabled cache'); diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index 2f99f964..a52836dc 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -101,7 +101,7 @@ public function testSaveItem() { $pool = $this->getTestPool(); - $this->assertFalse($pool->exists('base/one'), 'Pool->exists() returns false for item without stored data.'); + $this->assertFalse($pool->hasItem('base/one'), 'Pool->hasItem() returns false for item without stored data.'); $item = $pool->getItem('base', 'one'); $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); @@ -117,7 +117,7 @@ public function testSaveItem() $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); - $this->assertTrue($pool->exists('base/one'), 'Pool->exists() returns true for item with stored data.'); + $this->assertTrue($pool->hasItem('base/one'), 'Pool->hasItem() returns true for item with stored data.'); $pool->setNamespace('TestNamespace'); $item = $pool->getItem(array('test', 'item')); @@ -130,7 +130,7 @@ public function testSaveDeferredItem() { $pool = $this->getTestPool(); - $this->assertFalse($pool->exists('base/one'), 'Pool->exists() returns false for item without stored data.'); + $this->assertFalse($pool->hasItem('base/one'), 'Pool->hasItem() returns false for item without stored data.'); $item = $pool->getItem('base', 'one'); $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); @@ -146,7 +146,7 @@ public function testSaveDeferredItem() $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); - $this->assertTrue($pool->exists('base/one'), 'Pool->exists() returns true for item with stored data.'); + $this->assertTrue($pool->hasItem('base/one'), 'Pool->hasItem() returns true for item with stored data.'); $pool->setNamespace('TestNamespace'); $item = $pool->getItem(array('test', 'item')); @@ -154,14 +154,14 @@ public function testSaveDeferredItem() $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } - public function testExists() + public function testHasItem() { $pool = $this->getTestPool(); - $this->assertFalse($pool->exists('base/one'), 'Pool->exists() returns false for item without stored data.'); + $this->assertFalse($pool->hasItem('base/one'), 'Pool->hasItem() returns false for item without stored data.'); $item = $pool->getItem('base', 'one'); $item->set($this->data); $pool->save($item); - $this->assertTrue($pool->exists('base/one'), 'Pool->exists() returns true for item with stored data.'); + $this->assertTrue($pool->hasItem('base/one'), 'Pool->hasItem() returns true for item with stored data.'); } public function testCommit() diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index a7392e57..d8123a62 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -73,7 +73,7 @@ public function setLogger($logger) return false; } - public function exists($key) + public function hasItem($key) { return false; } From 9e98a36d0bc84c74377bb026c97ebd1edf91d983 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 17 Oct 2015 21:35:28 -0700 Subject: [PATCH 74/92] Fixed documentation and signatures --- src/Stash/Interfaces/PoolInterface.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 296cebcc..13c0ba95 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -64,9 +64,9 @@ public function getItem(); * each key passed, but is not required to maintain an order. * * @param array $keys - * @return \Iterator + * @return array|\Traversable */ - public function getItems($keys); + public function getItems(array $keys = array()); /** * Empties the entire cache pool of all Items. @@ -162,7 +162,7 @@ public function deleteItems(array $keys); /** * Checks for the existance of an item in the cache. * - * @param string $key + * @param string $key * @return boolean True if item exists in the cache, false otherwise. */ public function hasItem($key); From 07a6a826838e0f1fbf968563c8edec849d89c777 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 17 Oct 2015 22:00:31 -0700 Subject: [PATCH 75/92] Fixed signature. --- src/Stash/Pool.php | 2 +- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 5d606de3..51a8abdf 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -150,7 +150,7 @@ public function getItem() /** * {@inheritdoc} */ - public function getItems($keys) + public function getItems(array $keys = array()) { // temporarily cheating here by wrapping around single calls. diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index d8123a62..7a51ec68 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -43,7 +43,7 @@ public function getItem() return false; } - public function getItems($keys) + public function getItems(array $keys = array()) { return false; } From ad873c2c4a3814baf118856a2e0cb115267dac12 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 17 Oct 2015 23:34:46 -0700 Subject: [PATCH 76/92] simplified options check --- src/Stash/Driver/AbstractDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stash/Driver/AbstractDriver.php b/src/Stash/Driver/AbstractDriver.php index 4601c13d..9cf1fcf4 100644 --- a/src/Stash/Driver/AbstractDriver.php +++ b/src/Stash/Driver/AbstractDriver.php @@ -36,7 +36,7 @@ public function __construct(array $options = array()) throw new RuntimeException(get_class($this) . ' is not available.'); } - if (count($options) > 0) { + if (!empty($options)) { $this->setOptions($options); } } From 5ebe4bc1a43f893fb48b00b38ad0a40bcfca41e6 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 7 Dec 2015 22:24:41 -0800 Subject: [PATCH 77/92] Updated with PSR-6 changes --- CHANGELOG.md | 7 ++++++- composer.json | 4 +++- src/Stash/Interfaces/ItemInterface.php | 8 ++++---- src/Stash/Interfaces/PoolInterface.php | 19 +++++++++++++----- src/Stash/Item.php | 4 ++-- src/Stash/Pool.php | 21 ++++++++++++++------ tests/Stash/Test/AbstractPoolTest.php | 16 +++++++-------- tests/Stash/Test/CacheExceptionTest.php | 6 +++--- tests/Stash/Test/PoolNamespaceTest.php | 16 +++++++-------- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 8 +++++++- 10 files changed, 70 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d20efc..908e8326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ * `getExpiration` to return current datetime when no record exists. -* Added `save` function to ItemInterface. +* Added `save` function to PoolInterface. * Changed `getItemIterator` to `getItems` @@ -26,6 +26,11 @@ * Added the `hasItem` function to the Pool, which should mostly be avoided. +* Renamed `Pool::purge` to `Pool::clear`. + +* Added `Pool::deleteItem` and `Pool::deleteItems`. + + ## Stash v0.13 Changelog diff --git a/composer.json b/composer.json index d7bac29e..19c52c0c 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,9 @@ "sessions", "memcached", "redis", - "apc" + "apc", + "psr-6", + "psr6" ], "homepage": "http://github.com/tedious/Stash", "type": "library", diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index be0bdf0a..180f6148 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -44,7 +44,7 @@ public function disable(); * Returns the key as a string. This is particularly useful when the Item is * returned as a group of Items in an Iterator. * - * @return string|bool Returns false if no key is set. + * @return string */ public function getKey(); @@ -63,7 +63,7 @@ public function clear(); * function after call this one. If no value is stored at all then this * function will return null. * - * @return mixed|null + * @return mixed */ public function get(); @@ -96,10 +96,10 @@ public function lock($ttl = null); * including arrays and object, except resources and objects which are * unable to be serialized. * - * @param mixed $data bool + * @param mixed $value bool * @return static The invoked object */ - public function set($data); + public function set($value); /** * Extends the expiration on the current cached item. For some engines this diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 13c0ba95..f2e1a2ff 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -51,7 +51,7 @@ public function setItemClass($class); * @example $item = $pool->getItem(array('permissions', 'user', '4', '2')); * @example $item = $pool->getItem('permissions', 'user', '4', '2'); * - * @param array|string $key + * @param string $key * @return ItemInterface * @throws \InvalidArgumentException */ @@ -75,7 +75,7 @@ public function getItems(array $keys = array()); * * @return bool True on success */ - public function flush(); + public function clear(); /** * The Purge function allows drivers to perform basic maintenance tasks, such as removing stale or expired items @@ -130,6 +130,8 @@ public function setLogger($logger); /** * Forces any save-deferred objects to get flushed to the backend drivers. + * + * @return bool */ public function commit(); @@ -146,18 +148,25 @@ public function saveDeferred($item); * Sets an Item to be saved immediately. * * @param CacheItemInterface $item - * @return static The invoked object. + * @return bool */ public function save($item); /** - * Removes multiple items from the pool. + * Removes multiple items from the pool by their key. * * @param array $keys - * @return static The invoked object. + * @return bool */ public function deleteItems(array $keys); + /** + * Removes multiple items from the pool by their key. + * + * @param array $keys + * @return bool + */ + public function deleteItem($key); /** * Checks for the existance of an item in the cache. diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 3d7aaaf4..171b521c 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -322,7 +322,7 @@ public function lock($ttl = null) /** * {@inheritdoc} */ - public function set($data) + public function set($value) { if (!isset($this->key)) { return false; @@ -332,7 +332,7 @@ public function set($data) return $this; } - $this->data = $data; + $this->data = $value; return $this; } diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 51a8abdf..622d8c00 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -176,8 +176,7 @@ public function hasItem($key) */ public function save($item) { - $item->save(); - return $this; + return $item->save(); } /** @@ -203,19 +202,29 @@ public function commit() public function deleteItems(array $keys) { // temporarily cheating here by wrapping around single calls. - $items = array(); + $results = true; foreach ($keys as $key) { - $this->getItem($key)->clear(); + $results = $this->deleteItem($key) && $results; } - return $this; + return $results; + } + + + /** + * {@inheritdoc} + */ + public function deleteItem($key) + { + return $this->getItem($key)->clear(); } + /** * {@inheritdoc} */ - public function flush() + public function clear() { if ($this->isDisabled) { return false; diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index a52836dc..ac5cbc25 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -109,7 +109,7 @@ public function testSaveItem() $this->assertEquals('base/one', $key, 'Pool sets proper Item key.'); $item->set($this->data); - $this->assertEquals($pool, $pool->save($item), 'Pool->save() returns pool instance.'); + $this->assertTrue($pool->save($item), 'Pool->save() returns true.'); $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on passed Item.'); @@ -138,7 +138,7 @@ public function testSaveDeferredItem() $this->assertEquals('base/one', $key, 'Pool sets proper Item key.'); $item->set($this->data); - $this->assertEquals($pool, $pool->saveDeferred($item), 'Pool->save() returns pool instance.'); + $this->assertTrue($pool->saveDeferred($item), 'Pool->save() returns true.'); $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on passed Item.'); @@ -237,7 +237,7 @@ public function testDeleteItems() $this->assertEquals($this->multiData[$key], $data, 'data put into the pool comes back the same through iterators.'); } - $this->assertEquals($pool, $pool->deleteItems($keys), 'deleteItems returns Pool class.'); + $this->assertTrue($pool->deleteItems($keys), 'deleteItems returns true.'); $cacheIterator = $pool->getItems($keys); foreach ($cacheIterator as $item) { $this->assertTrue($item->isMiss(), 'data cleared using deleteItems is removed from the cache.'); @@ -246,17 +246,17 @@ public function testDeleteItems() - public function testFlushCache() + public function testClearCache() { $pool = $this->getTestPool(); $stash = $pool->getItem('base', 'one'); $stash->set($this->data)->save(); - $this->assertTrue($pool->flush(), 'flush returns true'); + $this->assertTrue($pool->clear(), 'clear returns true'); $stash = $pool->getItem('base', 'one'); $this->assertNull($stash->get(), 'clear removes item'); - $this->assertTrue($stash->isMiss(), 'flush causes cache miss'); + $this->assertTrue($stash->isMiss(), 'clear causes cache miss'); } public function testPurgeCache() @@ -320,7 +320,7 @@ public function testSetLogger() $this->assertAttributeInstanceOf('Stash\Test\Stubs\LoggerStub', 'logger', $item, 'setLogger injects logger into Pool.'); } - public function testLoggerFlush() + public function testLoggerClear() { $pool = $this->getTestPool(); @@ -331,7 +331,7 @@ public function testLoggerFlush() $pool->setLogger($logger); // triggerlogging - $pool->flush(); + $pool->clear(); $this->assertInstanceOf('Stash\Test\Exception\TestException', $logger->lastContext['exception'], 'Logger was passed exception in event context.'); diff --git a/tests/Stash/Test/CacheExceptionTest.php b/tests/Stash/Test/CacheExceptionTest.php index ef10fb77..e770e9c9 100644 --- a/tests/Stash/Test/CacheExceptionTest.php +++ b/tests/Stash/Test/CacheExceptionTest.php @@ -75,17 +75,17 @@ public function testPurge() $this->assertFalse($pool->purge()); } - public function testFlush() + public function testPoolClear() { $pool = new Pool(); $pool->setDriver(new DriverExceptionStub()); $item = $pool->getItem('test'); $this->assertFalse($item->isDisabled()); - $this->assertFalse($pool->flush()); + $this->assertFalse($pool->clear()); $item = $pool->getItem('test'); $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver'); - $this->assertFalse($pool->flush()); + $this->assertFalse($pool->clear()); } } diff --git a/tests/Stash/Test/PoolNamespaceTest.php b/tests/Stash/Test/PoolNamespaceTest.php index b4c0b30a..a6084f03 100644 --- a/tests/Stash/Test/PoolNamespaceTest.php +++ b/tests/Stash/Test/PoolNamespaceTest.php @@ -30,7 +30,7 @@ protected function getTestPool($skipNametest = false) return $pool; } - public function testFlushNamespacedCache() + public function testClearNamespacedCache() { $pool = $this->getTestPool(true); @@ -48,23 +48,23 @@ public function testFlushNamespacedCache() $item = $pool->getItem(array('test', 'one')); $item->set($this->data)->save(); - // Flush TestNamespace + // Clear TestNamespace $pool->setNamespace('TestNamespace'); - $this->assertTrue($pool->flush(), 'Flush succeeds with namespace selected.'); + $this->assertTrue($pool->clear(), 'Clear succeeds with namespace selected.'); // Return to No Namespace $pool->setNamespace(); $item = $pool->getItem(array('base', 'one')); - $this->assertFalse($item->isMiss(), 'Base item exists after other namespace was flushed.'); - $this->assertEquals($this->data, $item->get(), 'Base item returns data after other namespace was flushed.'); + $this->assertFalse($item->isMiss(), 'Base item exists after other namespace was cleared.'); + $this->assertEquals($this->data, $item->get(), 'Base item returns data after other namespace was cleared.'); - // Flush All - $this->assertTrue($pool->flush(), 'Flush succeeds with no namespace.'); + // Clear All + $this->assertTrue($pool->clear(), 'Clear succeeds with no namespace.'); // Return to TestNamespace2 $pool->setNamespace('TestNamespace2'); $item = $pool->getItem(array('base', 'one')); - $this->assertTrue($item->isMiss(), 'Namespaced item disappears after complete flush.'); + $this->assertTrue($item->isMiss(), 'Namespaced item disappears after complete clear.'); } public function testNamespacing() diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index 7a51ec68..c4ade01d 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -48,7 +48,7 @@ public function getItems(array $keys = array()) return false; } - public function flush() + public function clear() { return false; } @@ -97,4 +97,10 @@ public function deleteItems(array $keys) { return false; } + + + public function deleteItem($key) + { + return false; + } } From 874a8e421409ba1836d039144356310bce5ab27a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 7 Dec 2015 22:34:13 -0800 Subject: [PATCH 78/92] Added pecl support for php7 testing --- .travis.yml | 2 -- tests/travis/php_extensions_7.0.ini | 5 ++++ tests/travis/php_setup.sh | 37 +++++++++++++++++++---------- 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 tests/travis/php_extensions_7.0.ini diff --git a/.travis.yml b/.travis.yml index 8803b6c9..d138ca5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,5 +28,3 @@ services: matrix: fast_finish: true - allow_failures: - - php: 7.0 diff --git a/tests/travis/php_extensions_7.0.ini b/tests/travis/php_extensions_7.0.ini new file mode 100644 index 00000000..70e7e30f --- /dev/null +++ b/tests/travis/php_extensions_7.0.ini @@ -0,0 +1,5 @@ +extension="memcache.so" +extension="memcached.so" + +apc.enabled=1 +apc.enable_cli=1 diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 707746bb..131bc5e2 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -9,9 +9,21 @@ echo "**************************" echo "" echo "PHP Version: $TRAVIS_PHP_VERSION" -if [ "$TRAVIS_PHP_VERSION" = "hhvm" ] || [ "$TRAVIS_PHP_VERSION" = "hhvm-nightly" ] || [ "$TRAVIS_PHP_VERSION" = "7.0" ]; then +if [ "$TRAVIS_PHP_VERSION" = "hhvm" ] || [ "$TRAVIS_PHP_VERSION" = "hhvm-nightly" ]; then echo "Unable to install php extensions on current system" +elif [ "$TRAVIS_PHP_VERSION" = "7.0" ]; then + + echo "" + echo "******************************" + echo "Installing apcu-beta extension" + echo "******************************" + set +e + pecl config-set preferred_state beta + printf "yes\n" | pecl install apcu + set -e + echo "Finished installing apcu-beta extension." + else echo "" @@ -56,14 +68,15 @@ else echo "Finished installing apcu-beta extension." fi - if [ -f "tests/travis/php_extensions_${TRAVIS_PHP_VERSION}.ini" ] - then - echo "" - echo "*********************" - echo "Updating php.ini file" - echo "*********************" - echo "" - echo "" - phpenv config-add "tests/travis/php_extensions_${TRAVIS_PHP_VERSION}.ini" - fi -fi \ No newline at end of file +fi + +if [ -f "tests/travis/php_extensions_${TRAVIS_PHP_VERSION}.ini" ] +then + echo "" + echo "*********************" + echo "Updating php.ini file" + echo "*********************" + echo "" + echo "" + phpenv config-add "tests/travis/php_extensions_${TRAVIS_PHP_VERSION}.ini" +fi From 05586c6703975e9a7ca0f3a756ac6d6295d3e449 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 7 Dec 2015 22:56:35 -0800 Subject: [PATCH 79/92] Lock apache version for php < 7 --- tests/travis/php_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index 131bc5e2..e469357c 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -63,7 +63,7 @@ else echo "******************************" set +e pecl config-set preferred_state beta - printf "yes\n" | pecl install apcu + printf "yes\n" | pecl install apcu-4.0.10 set -e echo "Finished installing apcu-beta extension." fi From 5b59455473d358b1b6eaffcba81600435c91a0f9 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 7 Dec 2015 23:11:29 -0800 Subject: [PATCH 80/92] Removed "beta" preference for apcu --- tests/travis/php_setup.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index e469357c..ad314954 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -19,7 +19,6 @@ elif [ "$TRAVIS_PHP_VERSION" = "7.0" ]; then echo "Installing apcu-beta extension" echo "******************************" set +e - pecl config-set preferred_state beta printf "yes\n" | pecl install apcu set -e echo "Finished installing apcu-beta extension." @@ -62,8 +61,7 @@ else echo "Installing apcu-beta extension" echo "******************************" set +e - pecl config-set preferred_state beta - printf "yes\n" | pecl install apcu-4.0.10 + printf "yes\n" | pecl install apcu-4.0.8 set -e echo "Finished installing apcu-beta extension." fi From 555b41052ccde72b320bedae2947dad88f318688 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 7 Dec 2015 23:17:46 -0800 Subject: [PATCH 81/92] Removed "beta" label from apcu install --- tests/travis/php_setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/travis/php_setup.sh b/tests/travis/php_setup.sh index ad314954..547813b8 100755 --- a/tests/travis/php_setup.sh +++ b/tests/travis/php_setup.sh @@ -16,7 +16,7 @@ elif [ "$TRAVIS_PHP_VERSION" = "7.0" ]; then echo "" echo "******************************" - echo "Installing apcu-beta extension" + echo "Installing apcu extension" echo "******************************" set +e printf "yes\n" | pecl install apcu @@ -58,7 +58,7 @@ else then echo "" echo "******************************" - echo "Installing apcu-beta extension" + echo "Installing apcu extension" echo "******************************" set +e printf "yes\n" | pecl install apcu-4.0.8 From 40ee61f5bf1ce51d6270bd4d6f1795299225036a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 13 Dec 2015 23:30:50 -0800 Subject: [PATCH 82/92] Removed legacy key styles (array, arbitrary arguments) --- CHANGELOG.md | 1 + src/Stash/Pool.php | 23 +++-------------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 908e8326..4e0ef138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * Added `Pool::deleteItem` and `Pool::deleteItems`. +* Removed legacy methods for defining keys- keys must be defined as strings. ## Stash v0.13 Changelog diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 622d8c00..bf32f5c7 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -100,27 +100,10 @@ public function setItemClass($class) /** * {@inheritdoc} */ - public function getItem() + public function getItem($key) { - $args = func_get_args(); - - if (!isset($args[0])) { - throw new \InvalidArgumentException('Item constructor requires a key.'); - } - - // check to see if a single array was used instead of multiple arguments - if (!isset($args[1]) && is_array($args[0])) { - $args = $args[0]; - } - - // if only one item treat as key string - if (!isset($args[1])) { - $keyString = trim($args[0], '/'); - $key = explode('/', $keyString); - } else { - $key = $args; - } - + $keyString = trim($key, '/'); + $key = explode('/', $keyString); $namespace = empty($this->namespace) ? 'stash_default' : $this->namespace; array_unshift($key, $namespace); From 6b8c33d8a56929ef880fbf6a06061f9a924f2ea3 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 13 Dec 2015 23:32:04 -0800 Subject: [PATCH 83/92] Implimented from PSR-6 interfaces --- CHANGELOG.md | 2 + composer.json | 6 ++- src/Stash/Exception/Exception.php | 4 +- .../Exception/InvalidArgumentException.php | 5 ++- src/Stash/Interfaces/ItemInterface.php | 4 +- src/Stash/Interfaces/PoolInterface.php | 11 +++-- src/Stash/Pool.php | 10 +++-- tests/Stash/Test/AbstractPoolTest.php | 43 ++++++------------- tests/Stash/Test/PoolNamespaceTest.php | 10 ++--- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 7 +-- 10 files changed, 52 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e0ef138..13b057a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### v1.0.0 +* Implemented PSR-6 interfaces. + * Removed deprecated DriverList::getDrivers function. * Removed deprecated invalidation constants in the Item class. diff --git a/composer.json b/composer.json index 19c52c0c..44eda7b4 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ } ], "require": { - "php": ">=5.4.0" + "php": ">=5.4.0", + "psr/cache": "~1.0" }, "require-dev": { "fabpot/php-cs-fixer": "^1.9", @@ -36,5 +37,8 @@ "psr-4": { "Stash\\": "src/Stash/" } + }, + "provide": { + "psr/cache-implementation": "1.0.0" } } diff --git a/src/Stash/Exception/Exception.php b/src/Stash/Exception/Exception.php index cea596a6..9148daeb 100644 --- a/src/Stash/Exception/Exception.php +++ b/src/Stash/Exception/Exception.php @@ -11,12 +11,14 @@ namespace Stash\Exception; +use \Psr\Cache\CacheException; + /** * Interface for the Stash exceptions. * * @package Stash * @author Robert Hafner */ -interface Exception +interface Exception extends CacheException { } diff --git a/src/Stash/Exception/InvalidArgumentException.php b/src/Stash/Exception/InvalidArgumentException.php index 1e2dc4f2..3f06ad2b 100644 --- a/src/Stash/Exception/InvalidArgumentException.php +++ b/src/Stash/Exception/InvalidArgumentException.php @@ -11,12 +11,15 @@ namespace Stash\Exception; +//use \Psr\Cache\InvalidArgumentException; + + /** * Exception thrown if an argument does not match with the expected value. * * @package Stash * @author Robert Hafner */ -class InvalidArgumentException extends \InvalidArgumentException implements Exception +class InvalidArgumentException extends \InvalidArgumentException implements Exception, \Psr\Cache\InvalidArgumentException { } diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 180f6148..612a1143 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -11,7 +11,9 @@ namespace Stash\Interfaces; -interface ItemInterface +use \Psr\Cache\CacheItemInterface; + +interface ItemInterface extends CacheItemInterface { /** * Sets the Parent Pool for the Item class to use. diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index f2e1a2ff..ca2a23a9 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -11,13 +11,16 @@ namespace Stash\Interfaces; +use \Psr\Cache\CacheItemPoolInterface; +use \Psr\Cache\CacheItemInterface; + /** * * * @package Stash * @author Robert Hafner */ -interface PoolInterface +interface PoolInterface extends CacheItemPoolInterface { /** * Changes the specific Item class generated by the Pool object. @@ -55,7 +58,7 @@ public function setItemClass($class); * @return ItemInterface * @throws \InvalidArgumentException */ - public function getItem(); + public function getItem($key); /** * Returns a group of cache objects in an \Iterator @@ -142,7 +145,7 @@ public function commit(); * @param CacheItemInterface $item * @return static The invoked object. */ - public function saveDeferred($item); + public function saveDeferred(CacheItemInterface $item); /** * Sets an Item to be saved immediately. @@ -150,7 +153,7 @@ public function saveDeferred($item); * @param CacheItemInterface $item * @return bool */ - public function save($item); + public function save(CacheItemInterface $item); /** * Removes multiple items from the pool by their key. diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index bf32f5c7..07cfa102 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -11,6 +11,8 @@ namespace Stash; +use PSR\Cache\CacheItemInterface; +use Stash\Exception\InvalidArgumentException; use Stash\Driver\Ephemeral; use Stash\Interfaces\DriverInterface; use Stash\Interfaces\ItemInterface; @@ -83,7 +85,7 @@ public function __construct(DriverInterface $driver = null) public function setItemClass($class) { if (!class_exists($class)) { - throw new \InvalidArgumentException('Item class ' . $class . ' does not exist'); + throw new InvalidArgumentException('Item class ' . $class . ' does not exist'); } $interfaces = class_implements($class, true); @@ -110,7 +112,7 @@ public function getItem($key) foreach ($key as $node) { if (!isset($node[1]) && strlen($node) < 1) { - throw new \InvalidArgumentException('Invalid or Empty Node passed to getItem constructor.'); + throw new InvalidArgumentException('Invalid or Empty Node passed to getItem constructor.'); } } @@ -157,7 +159,7 @@ public function hasItem($key) /** * {@inheritdoc} */ - public function save($item) + public function save(CacheItemInterface $item) { return $item->save(); } @@ -165,7 +167,7 @@ public function save($item) /** * {@inheritdoc} */ - public function saveDeferred($item) + public function saveDeferred(CacheItemInterface $item) { return $this->save($item); } diff --git a/tests/Stash/Test/AbstractPoolTest.php b/tests/Stash/Test/AbstractPoolTest.php index ac5cbc25..da36e52d 100644 --- a/tests/Stash/Test/AbstractPoolTest.php +++ b/tests/Stash/Test/AbstractPoolTest.php @@ -81,7 +81,7 @@ public function testGetItem() { $pool = $this->getTestPool(); - $stash = $pool->getItem('base', 'one'); + $stash = $pool->getItem('base/one'); $this->assertInstanceOf('Stash\Item', $stash, 'getItem returns a Stash\Item object'); $stash->set($this->data)->save(); @@ -92,7 +92,7 @@ public function testGetItem() $this->assertEquals('base/one', $key, 'Pool sets proper Item key.'); $pool->setNamespace('TestNamespace'); - $item = $pool->getItem(array('test', 'item')); + $item = $pool->getItem('test/item'); $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } @@ -102,7 +102,7 @@ public function testSaveItem() $pool = $this->getTestPool(); $this->assertFalse($pool->hasItem('base/one'), 'Pool->hasItem() returns false for item without stored data.'); - $item = $pool->getItem('base', 'one'); + $item = $pool->getItem('base/one'); $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); $key = $item->getKey(); @@ -113,14 +113,14 @@ public function testSaveItem() $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on passed Item.'); - $item = $pool->getItem('base', 'one'); + $item = $pool->getItem('base/one'); $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); $this->assertTrue($pool->hasItem('base/one'), 'Pool->hasItem() returns true for item with stored data.'); $pool->setNamespace('TestNamespace'); - $item = $pool->getItem(array('test', 'item')); + $item = $pool->getItem('test/item'); $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } @@ -131,7 +131,7 @@ public function testSaveDeferredItem() $pool = $this->getTestPool(); $this->assertFalse($pool->hasItem('base/one'), 'Pool->hasItem() returns false for item without stored data.'); - $item = $pool->getItem('base', 'one'); + $item = $pool->getItem('base/one'); $this->assertInstanceOf('Stash\Item', $item, 'getItem returns a Stash\Item object'); $key = $item->getKey(); @@ -142,14 +142,14 @@ public function testSaveDeferredItem() $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on passed Item.'); - $item = $pool->getItem('base', 'one'); + $item = $pool->getItem('base/one'); $storedData = $item->get(); $this->assertEquals($this->data, $storedData, 'Pool->save() returns proper data on new Item instance.'); $this->assertTrue($pool->hasItem('base/one'), 'Pool->hasItem() returns true for item with stored data.'); $pool->setNamespace('TestNamespace'); - $item = $pool->getItem(array('test', 'item')); + $item = $pool->getItem('test/item'); $this->assertAttributeEquals('TestNamespace', 'namespace', $item, 'Pool sets Item namespace.'); } @@ -158,7 +158,7 @@ public function testHasItem() { $pool = $this->getTestPool(); $this->assertFalse($pool->hasItem('base/one'), 'Pool->hasItem() returns false for item without stored data.'); - $item = $pool->getItem('base', 'one'); + $item = $pool->getItem('base/one'); $item->set($this->data); $pool->save($item); $this->assertTrue($pool->hasItem('base/one'), 'Pool->hasItem() returns true for item with stored data.'); @@ -171,16 +171,6 @@ public function testCommit() } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Item constructor requires a key. - */ - public function testGetItemInvalidKey() - { - $pool = $this->getTestPool(); - $item = $pool->getItem(); - } - /** * @expectedException InvalidArgumentException * @expectedExceptionMessage Invalid or Empty Node passed to getItem constructor. @@ -250,11 +240,11 @@ public function testClearCache() { $pool = $this->getTestPool(); - $stash = $pool->getItem('base', 'one'); + $stash = $pool->getItem('base/one'); $stash->set($this->data)->save(); $this->assertTrue($pool->clear(), 'clear returns true'); - $stash = $pool->getItem('base', 'one'); + $stash = $pool->getItem('base/one'); $this->assertNull($stash->get(), 'clear removes item'); $this->assertTrue($stash->isMiss(), 'clear causes cache miss'); } @@ -263,11 +253,11 @@ public function testPurgeCache() { $pool = $this->getTestPool(); - $stash = $pool->getItem('base', 'one'); + $stash = $pool->getItem('base/one'); $stash->set($this->data)->expiresAfter(-600)->save(); $this->assertTrue($pool->purge(), 'purge returns true'); - $stash = $pool->getItem('base', 'one'); + $stash = $pool->getItem('base/one'); $this->assertNull($stash->get(), 'purge removes item'); $this->assertTrue($stash->isMiss(), 'purge causes cache miss'); } @@ -296,13 +286,6 @@ public function testInvalidNamespace() $pool->setNamespace('!@#$%^&*('); } - public function testgetItemArrayConversion() - { - $pool = $this->getTestPool(); - - $cache = $pool->getItem(array('base', 'one')); - $this->assertEquals($cache->getKey(), 'base/one'); - } public function testSetLogger() { diff --git a/tests/Stash/Test/PoolNamespaceTest.php b/tests/Stash/Test/PoolNamespaceTest.php index a6084f03..e8fb5866 100644 --- a/tests/Stash/Test/PoolNamespaceTest.php +++ b/tests/Stash/Test/PoolNamespaceTest.php @@ -35,17 +35,17 @@ public function testClearNamespacedCache() $pool = $this->getTestPool(true); // No Namespace - $item = $pool->getItem(array('base', 'one')); + $item = $pool->getItem('base/one'); $item->set($this->data)->save(); // TestNamespace $pool->setNamespace('TestNamespace'); - $item = $pool->getItem(array('test', 'one')); + $item = $pool->getItem('test/one'); $item->set($this->data)->save(); // TestNamespace2 $pool->setNamespace('TestNamespace2'); - $item = $pool->getItem(array('test', 'one')); + $item = $pool->getItem('test/one'); $item->set($this->data)->save(); // Clear TestNamespace @@ -54,7 +54,7 @@ public function testClearNamespacedCache() // Return to No Namespace $pool->setNamespace(); - $item = $pool->getItem(array('base', 'one')); + $item = $pool->getItem('base/one'); $this->assertFalse($item->isMiss(), 'Base item exists after other namespace was cleared.'); $this->assertEquals($this->data, $item->get(), 'Base item returns data after other namespace was cleared.'); @@ -63,7 +63,7 @@ public function testClearNamespacedCache() // Return to TestNamespace2 $pool->setNamespace('TestNamespace2'); - $item = $pool->getItem(array('base', 'one')); + $item = $pool->getItem('base/one'); $this->assertTrue($item->isMiss(), 'Namespaced item disappears after complete clear.'); } diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index c4ade01d..d4398c82 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -11,6 +11,7 @@ namespace Stash\Test\Stubs; +use Psr\Cache\CacheItemInterface; use Stash\Interfaces\PoolInterface; /** @@ -38,7 +39,7 @@ public function setItemClass($class) return true; } - public function getItem() + public function getItem($key) { return false; } @@ -83,12 +84,12 @@ public function commit() return false; } - public function saveDeferred($item) + public function saveDeferred(CacheItemInterface $item) { return false; } - public function save($item) + public function save(CacheItemInterface $item) { return false; } From 00bcc6bd4b85031241301411b4f8155b60b52819 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 13 Dec 2015 23:56:41 -0800 Subject: [PATCH 84/92] Added APCU support. This should solve ##274. --- CHANGELOG.md | 4 +++- src/Stash/Driver/Apc.php | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13b057a8..f607ef28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### v1.0.0 -* Implemented PSR-6 interfaces. +* Implemented PSR-6 interfaces. * Removed deprecated DriverList::getDrivers function. @@ -34,6 +34,8 @@ * Removed legacy methods for defining keys- keys must be defined as strings. +* Added support for "APCU" functions. + ## Stash v0.13 Changelog diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index 7fb9e93e..5ec0eb6f 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -36,6 +36,14 @@ class Apc extends AbstractDriver */ protected $apcNamespace; + /** + * Whether to use the APCu functions or the original APC ones. + * + * @var string + */ + protected $apcu = false; + + /** * The number of records \ApcIterator will grab at once. * @@ -51,6 +59,10 @@ public function getDefaultOptions() return array( 'ttl' => 300, 'namespace' => md5(__FILE__), + + // Test using the APCUIterator, as some versions of APCU have the + // custom functions but not the iterator class. + 'apcu' => class_exists('\APCUIterator') ); } @@ -68,6 +80,7 @@ public function setOptions(array $options = array()) $this->ttl = (int) $options['ttl']; $this->apcNamespace = $options['namespace']; + $this->apcu = $options['apcu']; } /** @@ -77,7 +90,7 @@ public function getData($key) { $keyString = self::makeKey($key); $success = null; - $data = apc_fetch($keyString, $success); + $data = $this->apcu ? apcu_fetch($keyString, $success) : apc_fetch($keyString, $success); return $success ? $data : false; } @@ -88,8 +101,11 @@ public function getData($key) public function storeData($key, $data, $expiration) { $life = $this->getCacheTime($expiration); + $apckey = $this->makeKey($key); + $store = array('data' => $data, 'expiration' => $expiration); - return apc_store($this->makeKey($key), array('data' => $data, 'expiration' => $expiration), $life); + + return $this->apcu ? apcu_store($apckey, $store, $life) : apc_store($apckey, $store, $life); } /** @@ -98,17 +114,19 @@ public function storeData($key, $data, $expiration) public function clear($key = null) { if (!isset($key)) { - return apc_clear_cache('user'); + return $this->apcu ? apcu_clear_cache('user') : apc_clear_cache('user'); } else { $keyRegex = '[' . $this->makeKey($key) . '*]'; $chunkSize = isset($this->chunkSize) && is_numeric($this->chunkSize) ? $this->chunkSize : 100; do { $emptyIterator = true; - $it = new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize); + $iteratorClass = $this->apcu ? '\APCUIterator' : '\APCIterator'; + $it = new $iteratorClass('user', $keyRegex, \APC_ITER_KEY, $chunkSize); + foreach ($it as $item) { $emptyIterator = false; - apc_delete($item['key']); + $this->apcu ? apcu_delete($item['key']) : apc_delete($item['key']); } } while (!$emptyIterator); } @@ -128,10 +146,10 @@ public function purge() $it = new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize); foreach ($it as $item) { $success = null; - $data = apc_fetch($item['key'], $success); + $data = $this->apcu ? apcu_fetch($item['key'], $success): apc_fetch($item['key'], $success); if ($success && is_array($data) && $data['expiration'] <= $now) { - apc_delete($item['key']); + $this->apcu ? apcu_delete($item['key']) : apc_delete($item['key']); } } @@ -145,12 +163,12 @@ public function purge() */ public static function isAvailable() { - // HHVM has some of the APC extension, but not all of it. - if (!class_exists('\APCIterator')) { + // Some versions of HHVM are missing the APCIterator + if (!class_exists('\APCIterator') && !class_exists('\APCUIterator')) { return false; } - return function_exists('apc_fetch'); + return function_exists('apcu_fetch') || function_exists('apc_fetch'); } /** From 0976fabb4e6b5221a0c5d35197ae7a66c24d6168 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sun, 13 Dec 2015 23:58:47 -0800 Subject: [PATCH 85/92] Fixed iterator class --- src/Stash/Driver/Apc.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index 5ec0eb6f..bb4b8d54 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -104,7 +104,6 @@ public function storeData($key, $data, $expiration) $apckey = $this->makeKey($key); $store = array('data' => $data, 'expiration' => $expiration); - return $this->apcu ? apcu_store($apckey, $store, $life) : apc_store($apckey, $store, $life); } @@ -142,8 +141,8 @@ public function purge() $now = time(); $keyRegex = '[' . $this->makeKey(array()) . '*]'; $chunkSize = isset($this->chunkSize) && is_numeric($this->chunkSize) ? $this->chunkSize : 100; - - $it = new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize); + $iteratorClass = $this->apcu ? '\APCUIterator' : '\APCIterator'; + $it = new $iteratorClass('user', $keyRegex, \APC_ITER_KEY, $chunkSize); foreach ($it as $item) { $success = null; $data = $this->apcu ? apcu_fetch($item['key'], $success): apc_fetch($item['key'], $success); From 1a9c7557f928ffa00168fe607725d6cb4e4763da Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 14 Dec 2015 00:14:23 -0800 Subject: [PATCH 86/92] Removed `Driver::setOptions($options)` in favor of `Driver::constructor($options)` --- CHANGELOG.md | 2 ++ src/Stash/Driver/AbstractDriver.php | 6 ++--- src/Stash/Driver/Apc.php | 2 +- src/Stash/Driver/Composite.php | 2 +- src/Stash/Driver/FileSystem.php | 2 +- src/Stash/Driver/Memcache.php | 2 +- src/Stash/Driver/Redis.php | 2 +- src/Stash/Driver/Sqlite.php | 2 +- src/Stash/Interfaces/DriverInterface.php | 9 ------- .../Stash/Test/Driver/AbstractDriverTest.php | 3 +-- tests/Stash/Test/Driver/ApcTest.php | 3 +-- tests/Stash/Test/Driver/FileSystemTest.php | 25 ++++++------------- tests/Stash/Test/Driver/SqliteAnyTest.php | 16 ++++++------ 13 files changed, 27 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f607ef28..8cf9ee98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * Implemented PSR-6 interfaces. +* Removed `Driver::setOptions($options)` in favor of `Driver::constructor($options)` + * Removed deprecated DriverList::getDrivers function. * Removed deprecated invalidation constants in the Item class. diff --git a/src/Stash/Driver/AbstractDriver.php b/src/Stash/Driver/AbstractDriver.php index 9cf1fcf4..68b7150f 100644 --- a/src/Stash/Driver/AbstractDriver.php +++ b/src/Stash/Driver/AbstractDriver.php @@ -36,9 +36,7 @@ public function __construct(array $options = array()) throw new RuntimeException(get_class($this) . ' is not available.'); } - if (!empty($options)) { - $this->setOptions($options); - } + $this->setOptions($options); } /** @@ -52,7 +50,7 @@ public function getDefaultOptions() /** * {@inheritdoc} */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { // empty } diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index bb4b8d54..fc0bc70f 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -74,7 +74,7 @@ public function getDefaultOptions() * * @param array $options */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); diff --git a/src/Stash/Driver/Composite.php b/src/Stash/Driver/Composite.php index d743ed34..3875522e 100644 --- a/src/Stash/Driver/Composite.php +++ b/src/Stash/Driver/Composite.php @@ -40,7 +40,7 @@ class Composite extends AbstractDriver * * @throws \Stash\Exception\RuntimeException */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); diff --git a/src/Stash/Driver/FileSystem.php b/src/Stash/Driver/FileSystem.php index fcaad3d2..442b7907 100644 --- a/src/Stash/Driver/FileSystem.php +++ b/src/Stash/Driver/FileSystem.php @@ -129,7 +129,7 @@ public function getDefaultOptions() * * @throws \Stash\Exception\RuntimeException */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); if (!isset($options['path'])) { diff --git a/src/Stash/Driver/Memcache.php b/src/Stash/Driver/Memcache.php index 7ad61f80..bd407ea1 100644 --- a/src/Stash/Driver/Memcache.php +++ b/src/Stash/Driver/Memcache.php @@ -81,7 +81,7 @@ public function getDefaultOptions() * * @throws RuntimeException */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); diff --git a/src/Stash/Driver/Redis.php b/src/Stash/Driver/Redis.php index 063fc7dd..214a55e7 100644 --- a/src/Stash/Driver/Redis.php +++ b/src/Stash/Driver/Redis.php @@ -61,7 +61,7 @@ class Redis extends AbstractDriver * * @param array $options */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); diff --git a/src/Stash/Driver/Sqlite.php b/src/Stash/Driver/Sqlite.php index b5f453dd..098c1087 100644 --- a/src/Stash/Driver/Sqlite.php +++ b/src/Stash/Driver/Sqlite.php @@ -55,7 +55,7 @@ public function getDefaultOptions() * * @throws \Stash\Exception\RuntimeException */ - public function setOptions(array $options = array()) + protected function setOptions(array $options = array()) { $options += $this->getDefaultOptions(); diff --git a/src/Stash/Interfaces/DriverInterface.php b/src/Stash/Interfaces/DriverInterface.php index 8c1e8955..1ee44824 100644 --- a/src/Stash/Interfaces/DriverInterface.php +++ b/src/Stash/Interfaces/DriverInterface.php @@ -42,15 +42,6 @@ interface DriverInterface { - /** - * Takes an array which is used to pass option values to the driver. As this is the only required function that is - * used specifically by the developer is where any engine specific options should go. An engine that requires - * authentication information, as an example, should get them here. - * - * @param array $options - */ - public function setOptions(array $options = array()); - /** * Returns the previously stored data as well as its expiration date in an associative array. This array contains * two keys - a 'data' key and an 'expiration' key. The 'data' key should be exactly the same as the value passed to diff --git a/tests/Stash/Test/Driver/AbstractDriverTest.php b/tests/Stash/Test/Driver/AbstractDriverTest.php index e35b6391..10fee4e6 100644 --- a/tests/Stash/Test/Driver/AbstractDriverTest.php +++ b/tests/Stash/Test/Driver/AbstractDriverTest.php @@ -87,8 +87,7 @@ public function testSetOptions() { $driverType = $this->driverClass; $options = $this->getOptions(); - $driver = new $driverType(); - $driver->setOptions($options); + $driver = new $driverType($options); $this->assertTrue(is_a($driver, $driverType), 'Driver is an instance of ' . $driverType); $this->assertTrue(is_a($driver, '\Stash\Interfaces\DriverInterface'), 'Driver implments the Stash\Driver\DriverInterface interface'); diff --git a/tests/Stash/Test/Driver/ApcTest.php b/tests/Stash/Test/Driver/ApcTest.php index 2785b377..c3437752 100644 --- a/tests/Stash/Test/Driver/ApcTest.php +++ b/tests/Stash/Test/Driver/ApcTest.php @@ -26,8 +26,7 @@ public function testSetOptions() $options = $this->getOptions(); $options['namespace'] = 'namespace_test'; $options['ttl'] = 15; - $driver = new $driverType(); - $driver->setOptions($options); + $driver = new $driverType($options); $this->assertAttributeEquals('namespace_test', 'apcNamespace', $driver, 'APC is setting supplied namespace.'); $this->assertAttributeEquals(15, 'ttl', $driver, 'APC is setting supplied ttl.'); diff --git a/tests/Stash/Test/Driver/FileSystemTest.php b/tests/Stash/Test/Driver/FileSystemTest.php index 4b997149..7db79bed 100644 --- a/tests/Stash/Test/Driver/FileSystemTest.php +++ b/tests/Stash/Test/Driver/FileSystemTest.php @@ -40,8 +40,7 @@ protected function getOptions($options = array()) */ public function testOptionKeyHashFunctionException() { - $driver = new FileSystem(); - $driver->setOptions($this->getOptions(array('keyHashFunction' => 'foobar_'.mt_rand()))); + $driver = new FileSystem($this->getOptions(array('keyHashFunction' => 'foobar_'.mt_rand()))); } /** @@ -49,9 +48,8 @@ public function testOptionKeyHashFunctionException() */ public function testOptionEncoderObjectException() { - $driver = new FileSystem(); $encoder = new \stdClass(); - $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + $driver = new FileSystem($this->getOptions(array('encoder' => $encoder))); } /** @@ -59,30 +57,26 @@ public function testOptionEncoderObjectException() */ public function testOptionEncoderStringException() { - $driver = new FileSystem(); $encoder = 'stdClass'; - $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + $driver = new FileSystem($this->getOptions(array('encoder' => $encoder))); } public function testOptionEncoderAsObject() { - $driver = new FileSystem(); $encoder = new \Stash\Driver\FileSystem\NativeEncoder(); - $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + $driver = new FileSystem($this->getOptions(array('encoder' => $encoder))); } public function testOptionEncoderAsString() { - $driver = new FileSystem(); $encoder = '\Stash\Driver\FileSystem\NativeEncoder'; - $driver->setOptions($this->getOptions(array('encoder' => $encoder))); + $driver = new FileSystem($this->getOptions(array('encoder' => $encoder))); } public function testOptionKeyHashFunction() { $driver = new FileSystem(array('keyHashFunction' => 'md5')); - $driver->setOptions($this->getOptions(array('keyHashFunction' => 'md5'))); } /** @@ -96,8 +90,7 @@ public function testOptionKeyHashFunctionDirs() $paths = array('one', 'two', 'three', 'four'); foreach ($hashfunctions as $hashfunction) { - $driver = new FileSystem(); - $driver->setOptions($this->getOptions(array( + $driver = new FileSystem($this->getOptions(array( 'keyHashFunction' => $hashfunction, 'path' => sys_get_temp_dir().DIRECTORY_SEPARATOR.'stash', 'dirSplit' => 1 @@ -142,8 +135,7 @@ public function testLongPathFolderCreation() $cachePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'stash'; - $driver = new FileSystem(); - $driver->setOptions($this->getOptions(array( + $driver = new FileSystem($this->getOptions(array( 'keyHashFunction' => 'Stash\Test\Driver\strdup', 'path' => $cachePath, 'dirSplit' => 1 @@ -179,8 +171,7 @@ public function testLongPathFileCreation() $cachePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'stash'; - $driver = new FileSystem(); - $driver->setOptions($this->getOptions(array( + $driver = new FileSystem($this->getOptions(array( 'keyHashFunction' => 'Stash\Test\Driver\strdup', 'path' => $cachePath, 'dirSplit' => 1 diff --git a/tests/Stash/Test/Driver/SqliteAnyTest.php b/tests/Stash/Test/Driver/SqliteAnyTest.php index 91cb4e28..cbf7c2a8 100644 --- a/tests/Stash/Test/Driver/SqliteAnyTest.php +++ b/tests/Stash/Test/Driver/SqliteAnyTest.php @@ -14,6 +14,7 @@ use Stash\Test\Stubs\PoolGetDriverStub; use Stash\Driver\Sqlite; use Stash\Item; +use Stash\Pool; use Stash\Utilities; /** @@ -39,15 +40,12 @@ public function testConstruction() { $key = array('apple', 'sauce'); - $options = array(); - $driver = new Sqlite(); - $driver->setOptions($options); - $item = new Item(); - $poolSub = new PoolGetDriverStub(); - $poolSub->setDriver($driver); - $item->setPool($poolSub); - $item->setKey($key); - $this->assertTrue($item->set($key)->save(), 'Able to load and store with unconfigured extension.'); + $driver = new Sqlite(array()); + $pool = new Pool(); + $pool->setDriver($driver); + $item = $pool->getItem('testKey'); + $item->set($key); + $this->assertTrue($pool->save($item), 'Able to load and store with unconfigured extension.'); } public static function tearDownAfterClass() From 238658d5db9704ce8e74d81ed268f42bd4e15d3f Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 14 Dec 2015 00:27:30 -0800 Subject: [PATCH 87/92] Removed more setOptions calls --- tests/Stash/Test/Driver/MemcacheAnyTest.php | 3 +-- tests/Stash/Test/Driver/MemcacheTest.php | 6 ++---- tests/Stash/Test/Driver/MemcachedTest.php | 15 +++++---------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/Stash/Test/Driver/MemcacheAnyTest.php b/tests/Stash/Test/Driver/MemcacheAnyTest.php index 697a8eff..02258404 100644 --- a/tests/Stash/Test/Driver/MemcacheAnyTest.php +++ b/tests/Stash/Test/Driver/MemcacheAnyTest.php @@ -50,8 +50,7 @@ public function testConstruction() $options = array(); $options['servers'][] = array('127.0.0.1', '11211', '50'); - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); $item = new Item(); $poolStub = new PoolGetDriverStub(); diff --git a/tests/Stash/Test/Driver/MemcacheTest.php b/tests/Stash/Test/Driver/MemcacheTest.php index 78362921..414e43c0 100644 --- a/tests/Stash/Test/Driver/MemcacheTest.php +++ b/tests/Stash/Test/Driver/MemcacheTest.php @@ -70,8 +70,7 @@ public function testConstructionOptions() $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['extension'] = $this->extension; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); $item = new Item(); $poolStub = new PoolGetDriverStub(); @@ -83,8 +82,7 @@ public function testConstructionOptions() $options = array(); $options['extension'] = $this->extension; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); $item = new Item(); $poolStub = new PoolGetDriverStub(); $poolStub->setDriver($driver); diff --git a/tests/Stash/Test/Driver/MemcachedTest.php b/tests/Stash/Test/Driver/MemcachedTest.php index 6487d5f0..11f4ae9e 100644 --- a/tests/Stash/Test/Driver/MemcachedTest.php +++ b/tests/Stash/Test/Driver/MemcachedTest.php @@ -44,8 +44,7 @@ public function testSetHashException() $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['hash'] = 'InvalidOption'; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); } /** @@ -57,8 +56,7 @@ public function testSetDistributionException() $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['distribution'] = 'InvalidOption'; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); } /** @@ -70,8 +68,7 @@ public function testSetSerializerException() $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['serializer'] = 'InvalidOption'; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); } /** @@ -83,8 +80,7 @@ public function testSetNumberedValueException() $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['connect_timeout'] = 'InvalidOption'; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); } /** @@ -96,7 +92,6 @@ public function testSetBooleanValueException() $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['cache_lookups'] = 'InvalidOption'; - $driver = new Memcache(); - $driver->setOptions($options); + $driver = new Memcache($options); } } From 6a51789c4b2a3ae418e9e9ae9ae5feb929b99844 Mon Sep 17 00:00:00 2001 From: Linus Metzler Date: Mon, 14 Dec 2015 11:34:22 +0100 Subject: [PATCH 88/92] fix issue with different constructor for APCu --- src/Stash/Driver/Apc.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index fc0bc70f..b7e508f2 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -120,8 +120,7 @@ public function clear($key = null) do { $emptyIterator = true; - $iteratorClass = $this->apcu ? '\APCUIterator' : '\APCIterator'; - $it = new $iteratorClass('user', $keyRegex, \APC_ITER_KEY, $chunkSize); + $it = $this->apcu ? new \APCUIterator($keyRegex, \APC_ITER_KEY, $chunkSize) : new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize); foreach ($it as $item) { $emptyIterator = false; @@ -141,8 +140,7 @@ public function purge() $now = time(); $keyRegex = '[' . $this->makeKey(array()) . '*]'; $chunkSize = isset($this->chunkSize) && is_numeric($this->chunkSize) ? $this->chunkSize : 100; - $iteratorClass = $this->apcu ? '\APCUIterator' : '\APCIterator'; - $it = new $iteratorClass('user', $keyRegex, \APC_ITER_KEY, $chunkSize); + $it = $this->apcu ? new \APCUIterator($keyRegex, \APC_ITER_KEY, $chunkSize) : new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize); foreach ($it as $item) { $success = null; $data = $this->apcu ? apcu_fetch($item['key'], $success): apc_fetch($item['key'], $success); From 1a4d65044d8f32fb05014ad6dd8179cabb1912d5 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Tue, 15 Dec 2015 11:10:10 -0800 Subject: [PATCH 89/92] Add apcu extension to testing ini files --- tests/travis/php_extensions_5.6.ini | 1 + tests/travis/php_extensions_7.0.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/travis/php_extensions_5.6.ini b/tests/travis/php_extensions_5.6.ini index 62d061f6..5a33e8a1 100644 --- a/tests/travis/php_extensions_5.6.ini +++ b/tests/travis/php_extensions_5.6.ini @@ -1,3 +1,4 @@ +extension="apcu.so" extension="memcache.so" extension="memcached.so" extension="redis.so" diff --git a/tests/travis/php_extensions_7.0.ini b/tests/travis/php_extensions_7.0.ini index 70e7e30f..91f18930 100644 --- a/tests/travis/php_extensions_7.0.ini +++ b/tests/travis/php_extensions_7.0.ini @@ -1,3 +1,4 @@ +extension="apcu.so" extension="memcache.so" extension="memcached.so" From 209c213a5dccd849f6d819688ea1e195fe64324c Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Tue, 15 Dec 2015 11:53:23 -0800 Subject: [PATCH 90/92] Fixed apcu function parameters --- src/Stash/Driver/Apc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stash/Driver/Apc.php b/src/Stash/Driver/Apc.php index b7e508f2..208da4c4 100644 --- a/src/Stash/Driver/Apc.php +++ b/src/Stash/Driver/Apc.php @@ -113,7 +113,7 @@ public function storeData($key, $data, $expiration) public function clear($key = null) { if (!isset($key)) { - return $this->apcu ? apcu_clear_cache('user') : apc_clear_cache('user'); + return $this->apcu ? apcu_clear_cache() : apc_clear_cache('user'); } else { $keyRegex = '[' . $this->makeKey($key) . '*]'; $chunkSize = isset($this->chunkSize) && is_numeric($this->chunkSize) ? $this->chunkSize : 100; From 5b4ecaa078b4b33b1bec5dfe3b12a21550519bd7 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Tue, 15 Dec 2015 16:08:57 -0800 Subject: [PATCH 91/92] Removed sqlite2 support --- CHANGELOG.md | 2 + src/Stash/Driver/Sqlite.php | 48 +++---------------- src/Stash/Driver/Sub/SqlitePdo2.php | 29 ----------- .../Test/Driver/SqlitePdoSqlite2Test.php | 47 ------------------ 4 files changed, 9 insertions(+), 117 deletions(-) delete mode 100644 src/Stash/Driver/Sub/SqlitePdo2.php delete mode 100644 tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cf9ee98..f0de658e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ * Added support for "APCU" functions. +* Removed sqlite2 support (sqlite3 is still supported). + ## Stash v0.13 Changelog diff --git a/src/Stash/Driver/Sqlite.php b/src/Stash/Driver/Sqlite.php index 098c1087..5e6f3086 100644 --- a/src/Stash/Driver/Sqlite.php +++ b/src/Stash/Driver/Sqlite.php @@ -67,29 +67,16 @@ protected function setOptions(array $options = array()) Utilities::checkFileSystemPermissions($this->cachePath, $this->dirPermissions); - $extension = isset($options['extension']) ? strtolower($options['extension']) : 'any'; - $version = isset($options['version']) ? $options['version'] : 'any'; - - $subdrivers = array(); - if (Sub\SqlitePdo::isAvailable()) { - $subdrivers['pdo'] = '\Stash\Driver\Sub\SqlitePdo'; - } - if (Sub\SqlitePdo2::isAvailable()) { - $subdrivers['pdo2'] = '\Stash\Driver\Sub\SqlitePdo2'; - } - - if ($extension == 'pdo' && $version != '2' && isset($subdrivers['pdo'])) { - $driver = $subdrivers['pdo']; - } elseif ($extension == 'pdo' && $version != '3' && isset($subdrivers['pdo2'])) { - $driver = $subdrivers['pdo2']; - } elseif (count($subdrivers) > 0 && $extension == 'any') { - $driver = reset($subdrivers); + if (static::isAvailable() && Sub\SqlitePdo::isAvailable()) { + $this->driverClass = '\Stash\Driver\Sub\SqlitePdo'; } else { throw new RuntimeException('No sqlite extension available.'); } - $this->driverClass = $driver; - $this->checkStatus(); + $driver = $this->getSqliteDriver(array('_none')); + if (!$driver) { + throw new RuntimeException('No Sqlite driver could be loaded.'); + } } /** @@ -250,33 +237,12 @@ protected function getCacheList() return count($caches) > 0 ? $caches : false; } - /** - * Checks availability of the specified subdriver. - * - * @throws \Stash\Exception\RuntimeException - * @return bool - */ - protected function checkStatus() - { - if (!static::isAvailable()) { - throw new RuntimeException('No Sqlite extension is available.'); - } - - $driver = $this->getSqliteDriver(array('_none')); - - if (!$driver) { - throw new RuntimeException('No Sqlite driver could be loaded.'); - } - - $driver->checkFileSystemPermissions(); - } - /** * {@inheritdoc} */ public static function isAvailable() { - return (Sub\SqlitePdo::isAvailable()) || (Sub\SqlitePdo2::isAvailable()); + return Sub\SqlitePdo::isAvailable(); } /** diff --git a/src/Stash/Driver/Sub/SqlitePdo2.php b/src/Stash/Driver/Sub/SqlitePdo2.php deleted file mode 100644 index 8197de00..00000000 --- a/src/Stash/Driver/Sub/SqlitePdo2.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Stash\Driver\Sub; - -/** - * Class SqlitePDO2 - * - * This SQLite subdriver uses PDO and SQLite2. - * - * @internal - * @package Stash - * @author Robert Hafner - */ -class SqlitePdo2 extends SqlitePdo -{ - /** - * {@inheritdoc} - */ - protected static $pdoDriver = 'sqlite2'; -} diff --git a/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php b/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php deleted file mode 100644 index a5d5b84a..00000000 --- a/tests/Stash/Test/Driver/SqlitePdoSqlite2Test.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Stash\Test\Driver; - -/** - * @package Stash - * @author Robert Hafner - */ -class SqlitePdoSqlite2Test extends AbstractDriverTest -{ - protected $driverClass = 'Stash\Driver\Sqlite'; - protected $subDriverClass = 'Stash\Driver\Sub\SqlitePdo2'; - protected $persistence = true; - - protected function setUp() - { - $driver = '\\' . $this->driverClass; - $subDriver = '\\' . $this->subDriverClass; - - if (!$driver::isAvailable() || !$subDriver::isAvailable()) { - $this->markTestSkipped('Driver class unsuited for current environment'); - - return; - } - - parent::setUp(); - } - - public function getOptions() - { - $options = parent::getOptions(); - $options['extension'] = 'pdo'; - $options['nesting'] = 2; - $options['version'] = 2; - - return $options; - } -} From 6415e06f5f2deee5ef7193d6975b6c260641cea7 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Tue, 15 Dec 2015 16:14:52 -0800 Subject: [PATCH 92/92] Moved filesystem checks to parent driver --- src/Stash/Driver/Sub/SqlitePdo.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/Stash/Driver/Sub/SqlitePdo.php b/src/Stash/Driver/Sub/SqlitePdo.php index ba4b0b23..36df7874 100644 --- a/src/Stash/Driver/Sub/SqlitePdo.php +++ b/src/Stash/Driver/Sub/SqlitePdo.php @@ -195,23 +195,6 @@ public function purge() return true; } - /** - * Filesystem integrity and permissions are checked and exceptions thrown for relevant issues. - * - * @throws \Stash\Exception\InvalidArgumentException - * @throws \Stash\Exception\RuntimeException - */ - public function checkFileSystemPermissions() - { - if (!isset($this->path)) { - throw new RuntimeException('No cache path is set.'); - } - - if (!is_writable($this->path) && !is_writable(dirname($this->path))) { - throw new InvalidArgumentException('The cache sqlite file is not writable.'); - } - } - /** * Checks that PDO extension is present and has the appropriate SQLite driver. * @@ -227,7 +210,6 @@ public static function isAvailable() return in_array(static::$pdoDriver, $drivers); } - /** * Tells the SQLite driver how long to wait for data to be written. *