MockArraySessionStorage example


    use EnvTestBehaviour;

    public function testSetsEnvironmentVariableToTrueIfTriggersCanBeCreated(): void
    {
        $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']);

        
->willThrowException(new ConstraintViolationException(new ConstraintViolationList()[]));

        $response = $this->controller->register($request$dataBag$context);

        static::assertSame(Response::HTTP_OK, $response->getStatusCode());
    }

    private function createRegisterRequest(): Request
    {
        $request = new Request();
        $request->attributes->set(RequestTransformer::STOREFRONT_URL, $_SERVER['APP_URL']);
        $request->setSession(new Session(new MockArraySessionStorage()));

        return $request;
    }
}

/** * @internal */
class RegisterControllerTestClass extends RegisterController
{
    use StorefrontControllerMockTrait;
}

class PhpConfigControllerTest extends TestCase
{
    public function testIndex(): void
    {
        $controller = new PhpConfigController($this->createMock(PhpBinaryFinder::class)$this->createMock(RecoveryManager::class));
        $controller->setContainer($this->getContainer());

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));

        $response = $controller->index($request);

        static::assertSame(Response::HTTP_OK, $response->getStatusCode());
    }

    public function testSetConfigOnUpdate(): void
    {
        $controller = new PhpConfigController($this->createMock(PhpBinaryFinder::class)$this->createMock(RecoveryManager::class));
        $controller->setContainer($this->getContainer());

        
HttpKernelInterface::MAIN_REQUEST
            )
        );

        static::assertSame($expectedLocale$request->attributes->get('_locale'));
        static::assertSame($expectedLocale$request->getLocale());
    }

    public static function installerLocaleProvider(): \Generator
    {
        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));

        yield 'falls back to en if no locale can be found' => [
            $request,
            'en',
        ];

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        $request->headers = new HeaderBag(['HTTP_ACCEPT_LANGUAGE' => 'es-ES']);

        yield 'falls back to en if browser header is not supported' => [
            
private const IS_VALID = true;
    private const IS_INVALID = false;
    private const BASIC_CAPTCHA_SESSION = 'kyln';

    private BasicCaptcha $captcha;

    protected function setUp(): void
    {
        $this->captcha = $this->getContainer()->get(BasicCaptcha::class);
        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        $this->getContainer()->get('request_stack')->push($request);

        $request->getSession()->set('basic_captcha_session', self::BASIC_CAPTCHA_SESSION);
    }

    public function testExtendsAbstractCaptcha(): void
    {
        static::assertInstanceOf(AbstractCaptcha::class$this->captcha);
    }

    /** * @dataProvider requestDataProvider */
use Symfony\Contracts\Translation\TranslatorInterface;

/** * @internal */
class CartMergedSubscriberTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testMergedHintIsAdded(): void
    {
        $session = new Session(new MockArraySessionStorage());
        $request = new Request();
        $request->setSession($session);
        $requestStack = new RequestStack();
        $requestStack->push($request);

        $translator = $this->createMock(TranslatorInterface::class);
        $translator->expects(static::once())
            ->method('trans')
            ->with('checkout.cart-merged-hint')
            ->willReturn('checkout.cart-merged-hint');

        
session_write_close();
            // The empty session id signals to `Enlight_Components_Session_Namespace::start()` that the session cookie             // should be used as session id.             session_id('');
        }

        $sessionOptions = $this->getSessionOptions();
        $saveHandler = $this->createSaveHandler(Shopware()->Container());
        $storage = new NativeSessionStorage($sessionOptions);

        if (!empty($sessionOptions['unitTestEnabled'])) {
            $storage = new MockArraySessionStorage();
        } elseif ($saveHandler) {
            session_set_save_handler($saveHandler);
        }

        if (isset($sessionOptions['save_path'])) {
            ini_set('session.save_path', (string) $sessionOptions['save_path']);
        }

        if (isset($sessionOptions['save_handler'])) {
            ini_set('session.save_handler', (string) $sessionOptions['save_handler']);
        }

        
$this->adminConfigService,
            $this->translator,
            ['de' => 'de-DE', 'en' => 'en-GB'],
            ['EUR', 'USD']
        );
        $this->controller->setContainer($this->getInstallerContainer($this->twig, ['router' => $this->router]));
    }

    public function testGetConfigurationRoute(): void
    {
        $request = new Request();
        $session = new Session(new MockArraySessionStorage());
        $session->set(DatabaseConnectionInformation::classnew DatabaseConnectionInformation());
        $session->set(BlueGreenDeploymentService::ENV_NAME, true);
        $request->setMethod('GET');
        $request->setSession($session);
        $request->attributes->set('_locale', 'de');

        $this->connection->expects(static::once())
            ->method('fetchAllAssociative')
            ->willReturn([
                ['iso3' => 'DEU', 'iso' => 'DE'],
                ['iso3' => 'GBR', 'iso' => 'GB'],
            ]);
'@Installer/installer/database-configuration.html.twig',
                array_merge($this->getDefaultViewParams()[
                    'connectionInfo' => new DatabaseConnectionInformation(),
                    'error' => null,
                ])
            )
            ->willReturn('config');

        $this->connectionFactory->expects(static::never())->method('getConnection');

        $request = Request::create('/installer/database-configuration');
        $session = new Session(new MockArraySessionStorage());
        $request->setSession($session);

        $response = $this->controller->databaseConfiguration($request);
        static::assertSame('config', $response->getContent());

        static::assertFalse($session->has(DatabaseConnectionInformation::class));
    }

    public function testDatabaseGetConfigurationRoutePostWithEmptyExistingDB(): void
    {
        $connection = $this->createMock(Connection::class);

        
'shippingAddressId' => null,
            ],
            \json_decode((string) $this->connection->fetchOne('SELECT payload FROM sales_channel_api_context WHERE token = "test"'), true, 512, \JSON_THROW_ON_ERROR)
        );
    }

    public function testCustomerTokenSubscriberStorefrontShouldStillBeLoggedIn(): void
    {
        $customerId = $this->createCustomer();

        $request = Request::create('/');
        $request->setSession(new Session(new MockArraySessionStorage()));

        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getToken')->willReturn('test');
        $context->method('getCustomer')->willReturn((new CustomerEntity())->assign(['id' => $customerId]));
        $request->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT, $context);

        $this->getContainer()->get('request_stack')->push($request);

        $newToken = null;

        $context->method('assign')->withAnyParameters()->willReturnCallback(function D$array) use ($context, &$newToken) {
            
HttpKernelInterface::MAIN_REQUEST
            )
        );

        static::assertSame($expectedLocale$request->attributes->get('_locale'));
        static::assertSame($expectedLocale$request->getLocale());
    }

    public static function installerLocaleProvider(): \Generator
    {
        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));

        yield 'falls back to en if no locale can be found' => [
            $request,
            'en',
        ];

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        $request->headers = new HeaderBag(['HTTP_ACCEPT_LANGUAGE' => 'es-ES']);

        yield 'falls back to en if browser header is not supported' => [
            
$fs->mkdir($tmpDir);
        $fs->dumpFile($tmpDir . '/symfony.lock', json_encode([], \JSON_THROW_ON_ERROR));

        static::assertTrue($recoveryManager->isFlexProject($tmpDir));
    }

    public function testGetPHPBinary(): void
    {
        $recoveryManager = new RecoveryManager();

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        $request->getSession()->set('phpBinary', 'php');

        static::assertSame('php', $recoveryManager->getPHPBinary($request));
    }

    private function prepareShopware(Filesystem $fs, string $tmpDir, string $version = '6.4.10.0'): void
    {
        $fs->mkdir($tmpDir);
        $fs->mkdir($tmpDir . '/public');

        $_SERVER['SCRIPT_FILENAME'] = $tmpDir . '/public/shopware-installer.phar.php';
        


    public function testImportDatabaseRedirectsToConfigPageWhenDatabaseConnectionWasNotConfigured(): void
    {
        $this->twig->expects(static::never())
            ->method('render');

        $this->router->expects(static::once())->method('generate')
            ->with('installer.database-configuration', [], UrlGeneratorInterface::ABSOLUTE_PATH)
            ->willReturn('/installer/database-configuration');

        $session = new Session(new MockArraySessionStorage());
        $request = Request::create('/installer/database-import');
        $request->setSession($session);

        $response = $this->controller->databaseImport($request);
        static::assertInstanceOf(RedirectResponse::class$response);
        static::assertSame('/installer/database-configuration', $response->getTargetUrl());
    }

    public function testImportDatabaseRoute(): void
    {
        $this->twig->expects(static::once())->method('render')
            
if (isset($sessionOptions['save_path'])) {
            ini_set('session.save_path', (string) $sessionOptions['save_path']);
        }

        if (isset($sessionOptions['save_handler'])) {
            ini_set('session.save_handler', (string) $sessionOptions['save_handler']);
        }

        $storage = new NativeSessionStorage($sessionOptions$saveHandler);

        if (!empty($sessionOptions['unitTestEnabled']) || session_status() === PHP_SESSION_ACTIVE) {
            $storage = new MockArraySessionStorage();
        }

        $attributeBag = new NamespacedAttributeBag('Shopware');

        $session = new Enlight_Components_Session_Namespace($storage$attributeBag);
        $session->start();
        $session->set('sessionId', $session->getId());

        $container->set('sessionid', $session->getId());

        $requestStack = $container->get('request_stack');

        
$controller = new UpdateController(
            $recoveryManager,
            $this->createMock(ReleaseInfoProvider::class),
            $this->createMock(FlexMigrator::class),
            $this->createMock(StreamedCommandResponseGenerator::class),
        );

        $controller->setContainer($this->getContainer());

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        $response = $controller->index($request);

        static::assertSame(Response::HTTP_FOUND, $response->getStatusCode());
        static::assertSame('configure', $response->headers->get('location'));
    }

    public function testRedirectToFinishWhenNoUpdateThere(): void
    {
        $recoveryManager = $this->createMock(RecoveryManager::class);

        $recoveryManager->method('getShopwareLocation')->willReturn('/path/to/shopware');
        
Home | Imprint | This part of the site doesn't use cookies.