Skip to content

Commit

Permalink
Improve Twig extra package
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Sep 19, 2024
1 parent bb7835e commit bf82088
Show file tree
Hide file tree
Showing 31 changed files with 527 additions and 26 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<testsuite name="TwigExtra Test Suite">
<directory>src/TwigExtra/tests</directory>
<exclude>src/TwigExtra/tests/Functional</exclude>
</testsuite>

<testsuite name="TwigHooks Test Suite">
Expand Down
21 changes: 20 additions & 1 deletion src/TwigExtra/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
}
27 changes: 27 additions & 0 deletions src/TwigExtra/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
colors="true"
bootstrap="tests/Functional/.application/config/bootstrap.php"
convertDeprecationsToExceptions="true"
>
<testsuites>
<testsuite name="twig_extra_tests">
<directory>tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />

<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_DEBUG" value="1"/>
<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1" />
<!-- ###- symfony/framework-bundle ### -->

<env name="KERNEL_CLASS" value="TestApplication\Sylius\TwigExtra\Kernel" />
</php>
</phpunit>
20 changes: 20 additions & 0 deletions src/TwigExtra/tests/Functional/.application/.env
Original file line number Diff line number Diff line change
@@ -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 ###
12 changes: 12 additions & 0 deletions src/TwigExtra/tests/Functional/.application/.gitignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions src/TwigExtra/tests/Functional/.application/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php

use Symfony\Bundle\FrameworkBundle\Console\Application;
use TestApplication\Sylius\TwigExtra\Kernel;

$_SERVER['APP_RUNTIME_OPTIONS'] = [
'project_dir' => dirname(__DIR__),
];

if (file_exists(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';
} elseif (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);
};
38 changes: 38 additions & 0 deletions src/TwigExtra/tests/Functional/.application/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
require_once dirname(__DIR__) . '/vendor/autoload.php';
} elseif (file_exists(dirname(__DIR__, 4) . '/vendor/autoload.php')) {
require_once dirname(__DIR__, 4) . '/vendor/autoload.php';
} else {
require_once dirname(__DIR__, 6) . '/vendor/autoload.php';
}

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=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';
19 changes: 19 additions & 0 deletions src/TwigExtra/tests/Functional/.application/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Sylius\TwigExtra\Symfony\SyliusTwigExtraBundle::class => ['all' => true],
];
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\HttpKernel\Kernel;

return static function (ContainerConfigurator $container): void {
if (Kernel::MAJOR_VERSION >= 6) {
$container->extension('framework', [
'handle_all_throwables' => true,
]);
}
};
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/TwigExtra/tests/Functional/.application/config/preload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

if (file_exists(dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php';
}
21 changes: 21 additions & 0 deletions src/TwigExtra/tests/Functional/.application/config/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#index:
# path: /
# controller: App\Controller\DefaultController::index

test_html_attribute:
path: /test_html_attribute
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: 'test_html_attribute.html.twig'

route_exists:
path: /route_exists
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: 'route_exists.html.twig'

sort_by:
path: /sort_by
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: 'sort_by.html.twig'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
when@dev:
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error
24 changes: 24 additions & 0 deletions src/TwigExtra/tests/Functional/.application/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:

services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
TestApplication\Sylius\TwigExtra\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
26 changes: 26 additions & 0 deletions src/TwigExtra/tests/Functional/.application/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use TestApplication\Sylius\TwigExtra\Kernel;

if (file_exists(dirname(__DIR__) . '/vendor/autoload_runtime.php')) {
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';
} elseif (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) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
Empty file.
Loading

0 comments on commit bf82088

Please sign in to comment.