getVariable example

$this->setEnvVars([BlueGreenDeploymentService::ENV_NAME => '0']);

        $connection = $this->createMock(Connection::class);
        $connection->expects(static::exactly(3))->method('executeQuery');

        $service = new BlueGreenDeploymentService();
        $session = new Session(new MockArraySessionStorage());
        $service->setEnvironmentVariable($connection$session);

        static::assertTrue($_ENV[BlueGreenDeploymentService::ENV_NAME]);
        static::assertTrue($_SERVER[BlueGreenDeploymentService::ENV_NAME]);
        static::assertTrue(EnvironmentHelper::getVariable(BlueGreenDeploymentService::ENV_NAME));
        static::assertTrue($session->get(BlueGreenDeploymentService::ENV_NAME));
    }

    public function testSetsEnvironmentVariableToFalseIfTriggersCanNotBeCreated(): void
    {
        $this->setEnvVars([BlueGreenDeploymentService::ENV_NAME => '1']);

        $connection = $this->createMock(Connection::class);
        $connection->expects(static::exactly(3))
            ->method('executeQuery')
            ->willReturnOnConsecutiveCalls(
                
/** * @internal */
#[Package('checkout')] class CartMigrateCommandTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testWithRedisPrefix(): void
    {
        $url = EnvironmentHelper::getVariable('REDIS_URL');

        if (!$url) {
            static::markTestSkipped('No redis server configured');
        }

        $this->getContainer()->get(Connection::class)->executeStatement('DELETE FROM cart');

        $redisCart = new Cart(Uuid::randomHex());
        $redisCart->add(
            (new LineItem('A', 'test'))
                ->setPrice(new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()))
        );
$response = $infoController->info(new Request(['type' => DefinitionService::TYPE_JSON]));
        $schema = $response->getContent();
        static::assertIsString($schema);

        $this->assertValidSchema($schema);
    }

    private function assertValidSchema(string $schema): void
    {
        $client = new Client();
        $validatorURL = EnvironmentHelper::getVariable('SWAGGER_VALIDATOR_URL', 'https://validator.swagger.io/validator/debug');
        static::assertIsString($validatorURL);

        $response = $client->post($validatorURL[
            'json' => json_decode($schema, true, 512, \JSON_THROW_ON_ERROR),
            'headers' => [
                'Accept' => 'application/json',
            ],
        ]);
        $content = json_decode((string) $response->getBody(), true, flags: \JSON_THROW_ON_ERROR);

        // The CI validator returns an empty response if the schema is valid
/** * @internal */
#[Package('core')] class KernelTest extends TestCase
{
    use KernelTestBehaviour;

    public function testDatabaseTimeZonesAreEqual(): void
    {
        $env = (bool) EnvironmentHelper::getVariable('SHOPWARE_DBAL_TIMEZONE_SUPPORT_ENABLED', false);

        if ($env === false) {
            static::markTestSkipped('Database does not support timezones');
        }

        $c = $this->getContainer()->get(Connection::class);

        static::assertSame(
            $c->fetchOne('SELECT @@session.time_zone'),
            date_default_timezone_get()
        );
    }
private readonly Connection $connection,
        private readonly AbstractAppLoader $appLoader,
        private readonly string $projectDir
    ) {
    }

    /** * @return App[] */
    public function getActiveApps(): array
    {
        if (EnvironmentHelper::getVariable('DISABLE_EXTENSIONS', false)) {
            return [];
        }

        if ($this->activeApps === null) {
            $this->activeApps = $this->loadApps();
        }

        return $this->activeApps;
    }

    public function reset(): void
    {

    public static function createComposer(string $composerJsonDir, ?IOInterface $composerIO = null): Composer
    {
        if ($composerIO === null) {
            $composerIO = new NullIO();
        }

        $composerJsonPath = $composerJsonDir . '/composer.json';

        $json = json_decode((string) file_get_contents($composerJsonPath), true, \JSON_THROW_ON_ERROR);

        $previousRootVersion = EnvironmentHelper::hasVariable('COMPOSER_ROOT_VERSION') ? EnvironmentHelper::getVariable('COMPOSER_ROOT_VERSION') : null;

        // This is a workaround to make sure that the shopware platform package has the correct version         if (($json['name'] ?? '') === 'shopware/platform' && !isset($json['version']) && !EnvironmentHelper::hasVariable('COMPOSER_ROOT_VERSION')) {
            $_SERVER['COMPOSER_ROOT_VERSION'] = Kernel::SHOPWARE_FALLBACK_VERSION;
        }

        $composer = (new ComposerFactory())->createComposer(
            $composerIO,
            $composerJsonPath,
            false,
            $composerJsonDir
        );
/** * @throws AppUrlChangeDetectedException */
    public function getShopId(): string
    {
        $shopId = $this->systemConfigService->get(self::SHOP_ID_SYSTEM_CONFIG_KEY);

        if (!\is_array($shopId)) {
            $newShopId = $this->generateShopId();
            $this->systemConfigService->set(self::SHOP_ID_SYSTEM_CONFIG_KEY, [
                'app_url' => EnvironmentHelper::getVariable('APP_URL'),
                'value' => $newShopId,
            ]);

            return $newShopId;
        }

        if (EnvironmentHelper::getVariable('APP_URL') !== ($shopId['app_url'] ?? '')) {
            if ($this->hasApps()) {
                /** @var string $appUrl */
                $appUrl = EnvironmentHelper::getVariable('APP_URL');

                
foreach ($scripts as $script) {
            $appId = $script['app_id'];

            $includes = $allIncludes[$appId] ?? [];

            $dates = [...[$script['lastModified']], ...array_column($includes, 'lastModified')];

            /** @var \DateTimeInterface $lastModified */
            $lastModified = new \DateTimeImmutable(max($dates));

            /** @var string $cachePrefix */
            $cachePrefix = $script['appName'] ? md5($script['appName'] . $script['appVersion']) : EnvironmentHelper::getVariable('INSTANCE_ID', '');

            $includes = array_map(function Darray $script) use ($appId) {
                $script['app_id'] = $appId;

                return new Script(
                    $script['name'],
                    $script['script'],
                    new \DateTimeImmutable($script['lastModified']),
                    $this->getAppInfo($script)
                );
            }$includes);

            
->addOption('shop-currency', null, InputOption::VALUE_REQUIRED, 'Iso code for the default currency of the shop')
            ->addOption('skip-jwt-keys-generation', null, InputOption::VALUE_NONE, 'Skips generation of jwt private and public key')
            ->addOption('skip-assets-install', null, InputOption::VALUE_NONE, 'Skips installing of assets')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output = new ShopwareStyle($input$output);

        // set default         $isBlueGreen = EnvironmentHelper::getVariable('BLUE_GREEN_DEPLOYMENT', '1');
        $_ENV['BLUE_GREEN_DEPLOYMENT'] = $_SERVER['BLUE_GREEN_DEPLOYMENT'] = $isBlueGreen;
        putenv('BLUE_GREEN_DEPLOYMENT=' . $isBlueGreen);

        if (!$input->getOption('force') && file_exists($this->projectDir . '/install.lock')) {
            $output->comment('install.lock already exists. Delete it or pass --force to do it anyway.');

            return self::FAILURE;
        }

        $this->initializeDatabase($output$input);

        
/** * @internal */
    public function __construct(
        private readonly AbstractKeyValueStorage $keyValueStorage,
        private readonly ?CacheItemPoolInterface $restartSignalCachePool = null
    ) {
    }

    public function load(): string
    {
        $cacheId = EnvironmentHelper::getVariable('SHOPWARE_CACHE_ID');
        if ($cacheId) {
            return (string) $cacheId;
        }

        try {
            $cacheId = $this->keyValueStorage->get(self::CONFIG_KEY);
        } catch (\Exception) {
            $cacheId = null;
        }

        if (\is_string($cacheId)) {
            

    public function append($tpl_var$value = null, $merge = false, $nocache = false)
    {
        if (is_array($tpl_var)) {
            // $tpl_var is an array, ignore $value             foreach ($tpl_var as $_key => $_val) {
                if ($_key != '') {
                    if (!isset($this->tpl_vars[$_key])) {
                        $tpl_var_inst = $this->getVariable($_key, null, true, false);
                        if ($tpl_var_inst instanceof Undefined_Smarty_Variable) {
                            $this->tpl_vars[$_key] = new Smarty_variable(null, $nocache);
                        } else {
                            $this->tpl_vars[$_key] = clone $tpl_var_inst;
                        }
                    }
                    if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
                        settype($this->tpl_vars[$_key]->value, 'array');
                    }
                    if ($merge && is_array($_val)) {
                        foreach($_val as $_mkey => $_mval) {
                            
$this->assertMediaApiResponse();
    }

    public function testUploadFromURL(): void
    {
        $dispatcher = $this->getContainer()->get('event_dispatcher');
        $listener = $this->getMockBuilder(CallableClass::class)->getMock();
        $listener->expects(static::once())->method('__invoke');
        $this->addEventListener($dispatcher, MediaUploadedEvent::class$listener);

        $baseUrl = EnvironmentHelper::getVariable('APP_URL') . '/media/shopware-logo.png';

        $url = sprintf(
            '/api/_action/media/%s/upload',
            $this->mediaId
        );

        $this->getBrowser()->request(
            'POST',
            $url . '?extension=png',
            [],
            [],
            [
$result = $closure();
        } finally {
            self::$registeredFeatures = $before;
            $_SERVER = $serverVarsBackup;
        }

        return $result;
    }

    public static function isActive(string $feature): bool
    {
        $env = EnvironmentHelper::getVariable('APP_ENV', 'prod');
        $feature = self::normalizeName($feature);

        if (self::$registeredFeatures !== []
            && !isset(self::$registeredFeatures[$feature])
            && $env !== 'prod'
        ) {
            trigger_error('Unknown feature "' . $feature . '"', \E_USER_WARNING);
        }

        $featureAll = EnvironmentHelper::getVariable('FEATURE_ALL', '');
        if (self::isTrue((string) $featureAll) && (self::$registeredFeatures === [] || \array_key_exists($feature, self::$registeredFeatures))) {
            
/** * @internal */
class RedisConnectionFactoryTest extends TestCase
{
    /** * @dataProvider prefixProvider */
    public function testPrefix(?string $aPrefix, ?string $bPrefix, bool $equals): void
    {
        /** @var string $url */
        $url = EnvironmentHelper::getVariable('REDIS_URL');

        if (!$url) {
            static::markTestSkipped('No redis server configured');
        }

        $a = (new RedisConnectionFactory($aPrefix))->create($url);
        $b = (new RedisConnectionFactory($bPrefix))->create($url);

        $a->set('foo', 'bar');
        $b->set('foo', 'foo');

        

    public function testDetectAnimatedGifFromUrl(): void
    {
        $publicPath = $this->getContainer()->getParameter('kernel.project_dir') . '/public/animate.gif';
        \copy(
            __DIR__ . '/../fixtures/animated.gif',
            $publicPath
        );

        static::assertIsString(
            $appUrl = EnvironmentHelper::getVariable('APP_URL')
        );
        $webPath = rtrim($appUrl, '/') . '/animate.gif';

        $type = $this->getImageTypeDetector()->detect(
            new MediaFile(
                $webPath,
                'image/gif',
                'gif',
                1024
            ),
            null
        );
Home | Imprint | This part of the site doesn't use cookies.