markTestSkipped( 'filepersistence tests require mikey179/vfsStream' ); } $this->root = vfsStream::setup('data'); } public function testGetPersistence() { $driver = common_persistence_Persistence::getPersistence('cache'); $this->assertInstanceOf('common_persistence_KeyValuePersistence', $driver); } public function testConnect() { $params = [ 'dir' => vfsStream::url('data'), 'humanReadable' => true ]; $driver = new common_persistence_PhpFileDriver(); $persistence = $driver->connect('test', $params); $this->assertInstanceOf('common_persistence_KeyValuePersistence', $persistence); return $persistence; } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testSetException($persistence) { $this->expectException(common_exception_NotImplemented::class); $persistence->set('empty', 'empty', 6); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testSet($persistence) { $return = $persistence->set('fakeKeyName', 'value'); $this->assertTrue($this->root->hasChild('fakeKeyName.php')); $content = $this->root->getChild('fakeKeyName.php')->getContent(); $this->assertEquals("assertTrue($return); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testGet($persistence) { $this->assertTrue($persistence->set('fakeKeyName', 'value')); $this->assertEquals('value', $persistence->get('fakeKeyName')); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testExists($persistence) { $this->assertFalse($persistence->exists('fakeKeyName')); $this->assertTrue($persistence->set('fakeKeyName', 'value')); $this->assertTrue($persistence->exists('fakeKeyName')); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testDel($persistence) { $this->assertTrue($persistence->set('fakeKeyName', 'value')); $this->assertTrue($persistence->exists('fakeKeyName')); $this->assertTrue($persistence->del('fakeKeyName')); $this->assertFalse($persistence->exists('fakeKeyName')); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testIncr($persistence) { $this->assertTrue($persistence->set('fakeKeyName', 0)); $this->assertTrue($persistence->incr('fakeKeyName')); $this->assertEquals(1, $persistence->get('fakeKeyName')); $this->assertTrue($persistence->incr('fakeKeyName')); $this->assertEquals(2, $persistence->get('fakeKeyName')); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testDecr($persistence) { $this->assertTrue($persistence->set('fakeKeyName', 10)); $this->assertTrue($persistence->decr('fakeKeyName')); $this->assertEquals(9, $persistence->get('fakeKeyName')); $this->assertTrue($persistence->decr('fakeKeyName')); $this->assertEquals(8, $persistence->get('fakeKeyName')); } /** * @depends testConnect * @author Lionel Lecaque, lionel@taotesting.com * @param common_persistence_KeyValuePersistence $persistence */ public function testPurge($persistence) { $this->assertTrue($persistence->set('fakeKeyName', 'value')); $this->assertTrue($persistence->set('fakeKeyName2', 'value')); $this->assertTrue($persistence->exists('fakeKeyName')); $this->assertTrue($persistence->exists('fakeKeyName2')); $this->assertTrue($persistence->purge()); $this->assertFalse($this->root->hasChildren()); } /** * * @author Lionel Lecaque, lionel@taotesting.com */ public function testNotHumanReadable() { $vfStream = vfsStream::setup('cache'); $params = [ 'dir' => vfsStream::url('cache'), ]; $driver = new common_persistence_PhpFileDriver(); $persistence = $driver->connect('test', $params); $persistence->set('fakeKeyName', 'value'); $this->assertEquals('value', $persistence->get('fakeKeyName')); } /** * Tests the ttl mode. * * @param \common_persistence_KeyValuePersistence $persistence * * @depends testConnect */ public function testTtlMode($persistence) { $this->assertFalse($persistence->getDriver()->isTtlMode()); } }