FeatureFlagExtension example


    private array $featureConfigBackup;

    private FeatureFlagExtension $extension;

    protected function setUp(): void
    {
        $this->serverVarsBackup = $_SERVER;
        $this->envVarsBackup = $_ENV;
        $this->featureConfigBackup = Feature::getRegisteredFeatures();
        $this->extension = new FeatureFlagExtension('Shopware\\Tests\\Unit\\', true);
    }

    protected function tearDown(): void
    {
        $_SERVER = $this->serverVarsBackup;
        $_ENV = $this->envVarsBackup;
        Feature::resetRegisteredFeatures();
        Feature::registerFeatures($this->featureConfigBackup);
    }

    public function testAllFeatureFlagsAreActivated(): void
    {
$configAfterRegistration = array_keys(Feature::getAll(false));
        static::assertEquals(\array_map(Feature::normalizeName(...)$featureFlags), \array_map(Feature::normalizeName(...)$configAfterRegistration));
    }

    public function testTwigFeatureFlag(): void
    {
        $this->setUpFixtures();
        $loader = new FilesystemLoader(__DIR__ . '/_fixture/');
        $twig = new Environment($loader[
            'cache' => false,
        ]);
        $twig->addExtension(new FeatureFlagExtension());
        $template = $twig->loadTemplate($twig->getTemplateClass('featuretest.html.twig'), 'featuretest.html.twig');
        $_SERVER['FEATURE_NEXT_101'] = '1';
        static::assertSame('FeatureIsActive', $template->render([]));
        $_SERVER['FEATURE_NEXT_101'] = '0';
        static::assertSame('FeatureIsInactive', $template->render([]));
    }

    public function testTwigFeatureFlagNotRegistered(): void
    {
        $_SERVER['APP_ENV'] = 'test';
        $_ENV['APP_ENV'] = 'test';
        
Home | Imprint | This part of the site doesn't use cookies.