MySQLKeyValueStorage example


    /** * @var Connection&MockObject */
    private Connection $connectionMock;

    private MySQLKeyValueStorage $keyValueStorage;

    protected function setUp(): void
    {
        $this->connectionMock = $this->createMock(Connection::class);
        $this->keyValueStorage = new MySQLKeyValueStorage($this->connectionMock);
    }

    public function testHas(): void
    {
        $this->connectionMock->expects(static::once())->method('fetchAllKeyValue')->willReturn([
            'key-1' => 'value-1',
            'key-2' => null,
        ]);

        static::assertTrue($this->keyValueStorage->has('key-1'));
        static::assertTrue($this->keyValueStorage->has('key-2'));
        


        $middlewares = [];
        if (\PHP_SAPI !== 'cli' && $this->environment !== 'prod' && InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
            $middlewares = [new ProfilingMiddleware()];
        }

        $connection = self::getConnection($middlewares);

        $pluginLoader = $this->createPluginLoader($connection);

        $storage = new MySQLKeyValueStorage($connection);
        $cacheId = (new CacheIdLoader($storage))->load();

        return $this->kernel = new static::$kernelClass(
            $this->environment,
            $this->debug,
            $pluginLoader,
            $cacheId,
            $shopwareVersion,
            $connection,
            $this->getProjectDir()
        );
    }
class MySQLKeyValueStorageTest extends TestCase
{
    use IntegrationTestBehaviour;

    private Connection $connection;

    private AbstractKeyValueStorage $keyValueStorage;

    protected function setUp(): void
    {
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->keyValueStorage = new MySQLKeyValueStorage($this->connection);
    }

    public function testSet(): void
    {
        $this->keyValueStorage->set('key-1', 'value-1');
        $this->keyValueStorage->set('key-2', null);
        $this->keyValueStorage->set('key-3', ['a' => 'b']);

        $value = $this->connection->fetchAllKeyValue('SELECT `key`, `value` FROM `app_config` WHERE `key` IN (:keys) ORDER BY `key` ASC', [
            'keys' => ['key-1', 'key-2', 'key-3'],
        ][
            
Home | Imprint | This part of the site doesn't use cookies.