diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a0e931ab..b6c4e841 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -101,3 +101,17 @@ jobs: - name: Run PHPUnit (Twig Hooks) run: (cd src/TwigHooks/ && vendor/bin/phpunit) + + - name: "Restrict packages' versions (Twig Extra)" + run: | + (cd src/TwigExtra/ && composer global config --no-plugins allow-plugins.symfony/flex true) + (cd src/TwigExtra/ && composer global config --no-plugins allow-plugins.symfony/runtime true) + (cd src/TwigExtra/ && composer global require --no-progress --no-scripts --no-plugins "symfony/flex") + (cd src/TwigExtra/ && composer config extra.symfony.require "${{ matrix.symfony }}") + + - name: "Install dependencies (Twig Extra)" + run: (cd src/TwigExtra/ && composer update --no-interaction --no-scripts) + + - name: Run PHPUnit (Twig Extra) + run: (cd src/TwigExtra/ && vendor/bin/phpunit) + diff --git a/composer.json b/composer.json index ecb020e7..5d131fe4 100644 --- a/composer.json +++ b/composer.json @@ -72,6 +72,7 @@ "psr-4": { "App\\": "app/", "MainTests\\Sylius\\": "tests/", + "TestApplication\\Sylius\\TwigExtra\\": "src/TwigExtra/tests/Functional/.application/src/", "TestApplication\\Sylius\\TwigHooks\\": "src/TwigHooks/tests/Functional/.application/src/", "Tests\\Sylius\\AdminUi\\": "src/AdminUi/tests/", "Tests\\Sylius\\TwigExtra\\": "src/TwigExtra/tests/", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 19cf3e47..b76d6e49 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,6 +28,7 @@ src/TwigExtra/tests + src/TwigExtra/tests/Functional diff --git a/src/TwigExtra/composer.json b/src/TwigExtra/composer.json index 0a873f2f..bdde129d 100644 --- a/src/TwigExtra/composer.json +++ b/src/TwigExtra/composer.json @@ -15,7 +15,19 @@ "require": { "php": "^8.1", "symfony/http-kernel": "^6.4 || ^7.0", - "symfony/twig-bundle": "^6.4 || ^7.0" + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/ux-twig-component": "^2.17" + }, + "require-dev": { + "matthiasnoback/symfony-dependency-injection-test": "^5.1", + "phpunit/phpunit": "^9.6", + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/console": "^6.4 || ^7.0", + "symfony/css-selector": "^6.4 || ^7.0", + "symfony/dotenv": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/runtime": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0" }, "conflict": { "sylius/ui-bundle": "<2.0" @@ -27,7 +39,14 @@ }, "autoload-dev": { "psr-4": { + "TestApplication\\Sylius\\TwigExtra\\": "tests/Functional/.application/src/", "Tests\\Sylius\\TwigExtra\\": "tests/" } + }, + "config": { + "allow-plugins": { + "symfony/runtime": true + }, + "sort-packages": true } } diff --git a/src/TwigExtra/phpunit.xml.dist b/src/TwigExtra/phpunit.xml.dist new file mode 100644 index 00000000..3e90732a --- /dev/null +++ b/src/TwigExtra/phpunit.xml.dist @@ -0,0 +1,27 @@ + + + + + + + tests + + + + + + + + + + + + + + + diff --git a/src/TwigExtra/tests/Functional/.application/.env b/src/TwigExtra/tests/Functional/.application/.env new file mode 100644 index 00000000..62608011 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/.env @@ -0,0 +1,20 @@ +# In all environments, the following files are loaded if they exist, +# the latter taking precedence over the former: +# +# * .env contains default values for the environment variables needed by the app +# * .env.local uncommitted file with local overrides +# * .env.$APP_ENV committed environment-specific defaults +# * .env.$APP_ENV.local uncommitted environment-specific overrides +# +# Real environment variables win over .env files. +# +# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. +# https://symfony.com/doc/current/configuration/secrets.html +# +# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). +# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration + +###> symfony/framework-bundle ### +APP_ENV=dev +APP_SECRET=c9570eaa5cbfadf33ad1a93f95c2e42a +###< symfony/framework-bundle ### diff --git a/src/TwigExtra/tests/Functional/.application/.gitignore b/src/TwigExtra/tests/Functional/.application/.gitignore new file mode 100644 index 00000000..0bc4031f --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/.gitignore @@ -0,0 +1,12 @@ + +###> symfony/framework-bundle ### +/.env.local +/.env.local.php +/.env.*.local +/config/secrets/prod/prod.decrypt.private.php +/public/bundles/ +/var/ +/vendor/ +###< symfony/framework-bundle ### + +composer.lock diff --git a/src/TwigExtra/tests/Functional/.application/bin/console b/src/TwigExtra/tests/Functional/.application/bin/console new file mode 100755 index 00000000..66d38647 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/bin/console @@ -0,0 +1,21 @@ +#!/usr/bin/env php + dirname(__DIR__), +]; + +if (file_exists(dirname(__DIR__, 4).'/vendor/autoload_runtime.php')) { + require_once dirname(__DIR__, 4).'/vendor/autoload_runtime.php'; +} else { + require_once dirname(__DIR__, 6).'/vendor/autoload_runtime.php'; +} + +return function (array $context) { + $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); + + return new Application($kernel); +}; diff --git a/src/TwigExtra/tests/Functional/.application/config/bootstrap.php b/src/TwigExtra/tests/Functional/.application/config/bootstrap.php new file mode 100644 index 00000000..d9ed1c77 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/bootstrap.php @@ -0,0 +1,36 @@ +=1.2) +if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) { + $_SERVER += $env; + $_ENV += $env; +} elseif (!class_exists(Dotenv::class)) { + throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); +} else { + // load all the .env files + (new Dotenv())->loadEnv(dirname(__DIR__) . '/.env'); +} + +$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; +$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/src/TwigExtra/tests/Functional/.application/config/bundles.php b/src/TwigExtra/tests/Functional/.application/config/bundles.php new file mode 100644 index 00000000..461f017d --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/bundles.php @@ -0,0 +1,19 @@ + ['all' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true], + Sylius\TwigExtra\Symfony\SyliusTwigExtraBundle::class => ['all' => true], +]; diff --git a/src/TwigExtra/tests/Functional/.application/config/packages/cache.yaml b/src/TwigExtra/tests/Functional/.application/config/packages/cache.yaml new file mode 100644 index 00000000..6899b720 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/packages/cache.yaml @@ -0,0 +1,19 @@ +framework: + cache: + # Unique name of your app: used to compute stable namespaces for cache keys. + #prefix_seed: your_vendor_name/app_name + + # The "app" cache stores to the filesystem by default. + # The data in this cache should persist between deploys. + # Other options include: + + # Redis + #app: cache.adapter.redis + #default_redis_provider: redis://localhost + + # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) + #app: cache.adapter.apcu + + # Namespaced pools use the above "app" backend by default + #pools: + #my.dedicated.cache: null diff --git a/src/TwigExtra/tests/Functional/.application/config/packages/framework.php b/src/TwigExtra/tests/Functional/.application/config/packages/framework.php new file mode 100644 index 00000000..662a40f6 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/packages/framework.php @@ -0,0 +1,24 @@ += 6) { + $container->extension('framework', [ + 'handle_all_throwables' => true, + ]); + } +}; diff --git a/src/TwigExtra/tests/Functional/.application/config/packages/framework.yaml b/src/TwigExtra/tests/Functional/.application/config/packages/framework.yaml new file mode 100644 index 00000000..ea75d737 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/packages/framework.yaml @@ -0,0 +1,22 @@ +# see https://symfony.com/doc/current/reference/configuration/framework.html +framework: + secret: '%env(APP_SECRET)%' + #csrf_protection: true + http_method_override: false + + # Enables session support. Note that the session will ONLY be started if you read or write from it. + # Remove or comment this section to explicitly disable session support. + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + storage_factory_id: session.storage.factory.native + + #esi: true + #fragments: true + +when@test: + framework: + test: true + session: + storage_factory_id: session.storage.factory.mock_file diff --git a/src/TwigExtra/tests/Functional/.application/config/packages/routing.yaml b/src/TwigExtra/tests/Functional/.application/config/packages/routing.yaml new file mode 100644 index 00000000..4b766ce5 --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/packages/routing.yaml @@ -0,0 +1,12 @@ +framework: + router: + utf8: true + + # Configure how to generate URLs in non-HTTP contexts, such as CLI commands. + # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands + #default_uri: http://localhost + +when@prod: + framework: + router: + strict_requirements: null diff --git a/src/TwigExtra/tests/Functional/.application/config/preload.php b/src/TwigExtra/tests/Functional/.application/config/preload.php new file mode 100644 index 00000000..77c80b9e --- /dev/null +++ b/src/TwigExtra/tests/Functional/.application/config/preload.php @@ -0,0 +1,16 @@ +