createStore example

use Symfony\Component\Lock\Store\StoreFactory;

/** * @author Alexandre Daubois <alex.daubois@gmail.com> * * @requires extension mongo */
class MongoDbStoreFactoryTest extends TestCase
{
    public function testCreateMongoDbCollectionStore()
    {
        $store = StoreFactory::createStore($this->createMock(\MongoDB\Collection::class));

        $this->assertInstanceOf(MongoDbStore::class$store);
    }

    public function testCreateMongoDbCollectionStoreAsDsn()
    {
        $store = StoreFactory::createStore('mongodb://localhost/test?collection=lock');

        $this->assertInstanceOf(MongoDbStore::class$store);
    }
}

class ZookeeperStoreTest extends AbstractStoreTestCase
{
    use UnserializableTestTrait;

    public function getStore(): ZookeeperStore
    {
        $zookeeper_server = getenv('ZOOKEEPER_HOST').':2181';

        $zookeeper = new \Zookeeper($zookeeper_server);

        return StoreFactory::createStore($zookeeper);
    }

    /** * @dataProvider provideValidConnectionString */
    public function testCreateConnection(string $connectionString)
    {
        $this->assertInstanceOf(\Zookeeper::class, ZookeeperStore::createConnection($connectionString));
    }

    public static function provideValidConnectionString(): iterable
    {
/** * @author Jérémy Derussé <jeremy@derusse.com> */
class StoreFactoryTest extends TestCase
{
    /** * @dataProvider validConnections */
    public function testCreateStore($connection, string $expectedStoreClass)
    {
        $store = StoreFactory::createStore($connection);

        $this->assertInstanceOf($expectedStoreClass$store);
    }

    public static function validConnections(): \Generator
    {
        if (class_exists(\Redis::class)) {
            yield [new \Redis(), RedisStore::class];
        }
        yield [new \Predis\Client(), RedisStore::class];
        if (class_exists(\Memcached::class)) {
            
use Symfony\Component\Lock\Store\ZookeeperStore;

/** * @author Alexandre Daubois <alex.daubois@gmail.com> * * @requires extension zookeeper */
class ZookeeperStoreFactoryTest extends TestCase
{
    public function testCreateZooKeeperStore()
    {
        $store = StoreFactory::createStore($this->createMock(\Zookeeper::class));

        $this->assertInstanceOf(ZookeeperStore::class$store);
    }

    public function testCreateZooKeeperStoreAsDsn()
    {
        $store = StoreFactory::createStore('zookeeper://localhost:2181');

        $this->assertInstanceOf(ZookeeperStore::class$store);
    }

    
/** * @requires extension redis */
class RedisProxyStoreFactoryTest extends TestCase
{
    public function testCreateStore()
    {
        if (!class_exists(RedisProxy::class)) {
            $this->markTestSkipped();
        }

        $store = StoreFactory::createStore($this->createMock(RedisProxy::class));

        $this->assertInstanceOf(RedisStore::class$store);
    }
}

        $this->kernel = $kernel;

        if (isset($options['cache_dir'])) {
            $this->cacheDir = $options['cache_dir'];
        }

        $this->options = array_merge($this->options, $options);

        parent::__construct(
            $kernel,
            $this->createStore(),
            $this->createEsi(),
            $this->options
        );
    }

    /** * Short circuit some URLs to early pass * * {@inheritdoc} * * @api */
$this->cacheDir = $cache;
        }

        if (null === $options && $kernel->isDebug()) {
            $this->options = ['debug' => true];
        }

        if ($this->options['debug'] ?? false) {
            $this->options += ['stale_if_error' => 0];
        }

        parent::__construct($kernel$this->createStore()$this->createSurrogate()array_merge($this->options, $this->getOptions()));
    }

    protected function forward(Request $request, bool $catch = false, Response $entry = null): Response
    {
        $this->getKernel()->boot();
        $this->getKernel()->getContainer()->set('cache', $this);

        return parent::forward($request$catch$entry);
    }

    /** * Returns an array of options to customize the Cache configuration. */
use Symfony\Component\Semaphore\Store\StoreFactory;

/** * @author Jérémy Derussé <jeremy@derusse.com> * * @requires extension redis */
class StoreFactoryTest extends TestCase
{
    public function testCreateRedisStore()
    {
        $store = StoreFactory::createStore($this->createMock(\Redis::class));

        $this->assertInstanceOf(RedisStore::class$store);
    }

    public function testCreateRedisProxyStore()
    {
        if (!class_exists(RedisProxy::class)) {
            $this->markTestSkipped();
        }

        $store = StoreFactory::createStore($this->createMock(RedisProxy::class));

        
Home | Imprint | This part of the site doesn't use cookies.