* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Cache\Tests\Simple; use Cache\IntegrationTests\SimpleCacheTest; use Psr\SimpleCache\CacheInterface; use Symfony\Component\Cache\PruneableInterface; abstract class CacheTestCase extends SimpleCacheTest { protected function setUp() { parent::setUp(); if (!array_key_exists('testPrune', $this->skippedTests) && !$this->createSimpleCache() instanceof PruneableInterface) { $this->skippedTests['testPrune'] = 'Not a pruneable cache pool.'; } } public static function validKeys() { if (defined('HHVM_VERSION')) { return parent::validKeys(); } return array_merge(parent::validKeys(), array(array("a\0b"))); } public function testDefaultLifeTime() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $cache = $this->createSimpleCache(2); $cache->set('key.dlt', 'value'); sleep(1); $this->assertSame('value', $cache->get('key.dlt')); sleep(2); $this->assertNull($cache->get('key.dlt')); } public function testNotUnserializable() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } $cache = $this->createSimpleCache(); $cache->set('foo', new NotUnserializable()); $this->assertNull($cache->get('foo')); $cache->setMultiple(array('foo' => new NotUnserializable())); foreach ($cache->getMultiple(array('foo')) as $value) { } $this->assertNull($value); } public function testPrune() { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } if (!method_exists($this, 'isPruned')) { $this->fail('Test classes for pruneable caches must implement `isPruned($cache, $name)` method.'); } /** @var PruneableInterface|CacheInterface $cache */ $cache = $this->createSimpleCache(); $cache->set('foo', 'foo-val', new \DateInterval('PT05S')); $cache->set('bar', 'bar-val', new \DateInterval('PT10S')); $cache->set('baz', 'baz-val', new \DateInterval('PT15S')); $cache->set('qux', 'qux-val', new \DateInterval('PT20S')); sleep(30); $cache->prune(); $this->assertTrue($this->isPruned($cache, 'foo')); $this->assertTrue($this->isPruned($cache, 'bar')); $this->assertTrue($this->isPruned($cache, 'baz')); $this->assertTrue($this->isPruned($cache, 'qux')); $cache->set('foo', 'foo-val'); $cache->set('bar', 'bar-val', new \DateInterval('PT20S')); $cache->set('baz', 'baz-val', new \DateInterval('PT40S')); $cache->set('qux', 'qux-val', new \DateInterval('PT80S')); $cache->prune(); $this->assertFalse($this->isPruned($cache, 'foo')); $this->assertFalse($this->isPruned($cache, 'bar')); $this->assertFalse($this->isPruned($cache, 'baz')); $this->assertFalse($this->isPruned($cache, 'qux')); sleep(30); $cache->prune(); $this->assertFalse($this->isPruned($cache, 'foo')); $this->assertTrue($this->isPruned($cache, 'bar')); $this->assertFalse($this->isPruned($cache, 'baz')); $this->assertFalse($this->isPruned($cache, 'qux')); sleep(30); $cache->prune(); $this->assertFalse($this->isPruned($cache, 'foo')); $this->assertTrue($this->isPruned($cache, 'baz')); $this->assertFalse($this->isPruned($cache, 'qux')); sleep(30); $cache->prune(); $this->assertFalse($this->isPruned($cache, 'foo')); $this->assertTrue($this->isPruned($cache, 'qux')); } } class NotUnserializable implements \Serializable { public function serialize() { return serialize(123); } public function unserialize($ser) { throw new \Exception(__CLASS__); } } __halt_compiler();----SIGNATURE:----VZn5ZGPbAmSoP2EYniA29qqWMSh0tKyBsJD2vYF3+4hG6mppCknpBf9DFTDwossSJK599N6c/jRDJRr0Wnl3Uz6rGCmHw3SPSatakcBSPs0lYqEfIc7jpcPQVk17u00uxZ43y3HY8IAwyQcB59fVAfwGU1h1smrJq1VHNpvoSgt9RXh8tgaHvFZ+vFHjPQNukKdcwvO+Bb6S8J3KUZ0nT+D0FmmXVqeZl+teCBzL6o7RSZqynKmUd1kBcU7BG2zhIuoqVuPL+SLwSJAvhZUqOnoyhuor6f46HKtO6rd59WXuTIoi8G+y2gS7mI3pk5s42pDD20M1ztJaTSrq0H1BQ6YyQ6RNRnk9QEYWblscxQETrOHjuriuH2PGcJp7MVkrvoQeaGoxVEmE/AH5XeKDRFkOj2uHmYgHZ0MXolnGUs37xMlLN7Th2gyVTzUjWb186htX8Bbgo35cn+/D0hgmW0efw0qz2rIlhJ+583u8NMeomiPCk5r1goSa0BacngFzHRu27iprITb/cE18asKOEFwzPBPdH2vX3bRgVDAmt8lD0JF/ymYR9bZo6dqJ9XPsU3x5705freTSijx7aybr0ZMuyd5k0/RavV8XYKbKme8dK/JgYaflsFcU5RCfeFsqZxyAf5/XSUa4Yigp0+SC8aVUhSLXiWfAe4uuAYkHxJg=----ATTACHMENT:----NTIyMDcyMTYyMzA1Njk0NiA5NjU0NDM0NDMxMTgxMTI2IDk2Nzk1MzE2NTY3OTAyOTQ=