From 6ec75f182b371100d030287b2d1069279b51b6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Jani=CC=81c=CC=8Cek?= Date: Mon, 23 Dec 2024 10:45:25 +0100 Subject: [PATCH] BREAKING CHANGE: Update all dependencies --- .github/workflows/tests.yaml | 6 +- CHANGELOG.md | 7 +++ composer.json | 36 ++++++------ docker/Dockerfile | 2 +- docker/install-composer.sh | 2 +- ecs.php | 38 ++++++------ phpunit.xml.dist | 58 +++++++++---------- src/Compiler/ComponentLexer.php | 17 ++---- src/Compiler/ComponentTagCompiler.php | 25 ++++---- tests/Compiler/ComponentTagCompilerTest.php | 13 ++--- .../OverrideServiceCompilerPassTest.php | 6 +- .../DependencyInjection/ConfigurationTest.php | 8 +-- .../TwigXExtensionTest.php | 1 - 13 files changed, 105 insertions(+), 114 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4ff6f27..65e5ef6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,10 +12,10 @@ jobs: strategy: matrix: - php-version: ['7.4', '8.1', '8.2'] + php-version: ['8.1', '8.2', '8.3', '8.4'] dependencies: [''] include: - - { php-version: '7.4', dependencies: '--prefer-lowest --prefer-stable' } + - { php-version: '8.1', dependencies: '--prefer-lowest --prefer-stable' } name: Unit tests - PHP ${{ matrix.php-version }} ${{ matrix.dependencies }} @@ -65,7 +65,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.4' extensions: json, mbstring - name: Install dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 32f62be..5c039f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +- [BC]: Drop support Symfony `4.4` and not LTS versions `6.x` +- [BC]: Drop support PHP `^7.4` +- Feat: Add support for Symfony `^7.2` +- Feat: Introduce support PHP `^8.4` +- Deps: Drop old PHP polyfill packages +- Deps: Update dev dependencies +- Chore: Update docker container php version to `8.4` ## 3.3.0 - 2024-06-12 - Feat: Normalize template name using regex to allow capitalized prefixes diff --git a/composer.json b/composer.json index 6ada7fb..2c5b3da 100644 --- a/composer.json +++ b/composer.json @@ -20,34 +20,32 @@ } }, "require": { - "php": "^7.4 || ^8.1", - "symfony/config": "^4.4 || ^5.4 || ^6.1", - "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.1", - "symfony/http-foundation": "^4.4 || ^5.4 || ^6.1", - "symfony/http-kernel": "^4.4 || ^5.4 || ^6.1", - "symfony/polyfill-php80": "^1.23", - "symfony/polyfill-php81": "^1.26", - "twig/twig": "^1.44.6 || ^2.12.5 || ^3.0.0", + "php": "^8.1", + "symfony/config": " ^5.4 || ^6.4 || ^7.2", + "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.2", + "symfony/http-foundation": "^5.4 || ^6.4 || ^7.2", + "symfony/http-kernel": "^5.4 || ^6.4 || ^7.2", + "twig/twig": "^3.0.0", "ext-simplexml": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5.20", + "phpunit/phpunit": "^11.5", "mockery/mockery": "^1.5", "doctrine/cache": "^1.10", - "lmc/coding-standard": "^3.3", - "symfony/yaml": "^4.4 || ^5.4 || ^6.1", - "phpstan/phpstan": "^1.2", - "phpstan/phpstan-mockery": "^1.0", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-symfony": "^1.0", - "spatie/phpunit-snapshot-assertions": "^4.2.12" + "lmc/coding-standard": "^4.1", + "symfony/yaml": "^5.4 || ^6.4 || ^7.2", + "phpstan/phpstan": "^2", + "phpstan/phpstan-mockery": "^2.0", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan-symfony": "^2.0", + "spatie/phpunit-snapshot-assertions": "^5.1" }, "scripts": { "ecs": "vendor/bin/ecs check --no-progress-bar --ansi src/ tests/", "ecs:fix": "vendor/bin/ecs check --no-progress-bar --ansi --fix src/ tests/", - "phpunit": "vendor/bin/phpunit", - "phpunit:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit", - "phpstan": "vendor/bin/phpstan analyze", + "phpunit": "vendor/bin/phpunit --no-coverage", + "phpunit:coverage": "vendor/bin/phpunit", + "phpstan": "vendor/bin/phpstan analyze --memory-limit 4G", "tests": [ "@ecs", "@phpunit", diff --git a/docker/Dockerfile b/docker/Dockerfile index 4648bab..264cd19 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1 +FROM php:8.4 # Install unzip utility and libs needed by zip PHP extension RUN apt-get update && apt-get install -y \ diff --git a/docker/install-composer.sh b/docker/install-composer.sh index fd56d23..c546f26 100755 --- a/docker/install-composer.sh +++ b/docker/install-composer.sh @@ -12,7 +12,7 @@ then fi # fix composer version https://github.com/composer/composer/issues/10671 -php composer-setup.php --version=2.2.9 --quiet; +php composer-setup.php --version=2.8.4 --quiet; RESULT=$? rm composer-setup.php; diff --git a/ecs.php b/ecs.php index a8cd72d..acc2124 100644 --- a/ecs.php +++ b/ecs.php @@ -3,26 +3,28 @@ declare(strict_types=1); use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symplify\EasyCodingStandard\ValueObject\Option; +use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ContainerConfigurator $containerConfigurator): void { - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [ +return ECSConfig::configure() + ->withSets([ + __DIR__ . '/vendor/lmc/coding-standard/ecs.php', + ]) + ->withConfiguredRule( + ArraySyntaxFixer::class, + ['syntax' => 'short'], + ) + ->withCache( + directory: sys_get_temp_dir() . '/ecs_cached_files', + namespace: getcwd(), + ) + ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', + ]) + ->withSets([ + SetList::SPACES, + SetList::ARRAY, + SetList::DOCBLOCK, + SetList::PSR_12, ]); - - $services = $containerConfigurator->services(); - $services->set(ArraySyntaxFixer::class) - ->call('configure', [[ - 'syntax' => 'short', - ]]); - - // run and fix, one by one - $containerConfigurator->import(SetList::SPACES); - $containerConfigurator->import(SetList::ARRAY); - $containerConfigurator->import(SetList::DOCBLOCK); - $containerConfigurator->import(SetList::PSR_12); -}; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 80390bc..1b2c742 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,33 +1,31 @@ - - - - src - - - src/Logger/Logger.php - src/TwigXBundle.php - - - - - - - - - - - - - tests/ - - - - - + + + + + + + + + + + + + + tests/ + + + + + + + + src + + + src/Logger/Logger.php + src/TwigXBundle.php + + diff --git a/src/Compiler/ComponentLexer.php b/src/Compiler/ComponentLexer.php index c0d630b..2266c4c 100644 --- a/src/Compiler/ComponentLexer.php +++ b/src/Compiler/ComponentLexer.php @@ -11,24 +11,19 @@ class ComponentLexer extends Lexer { - private string $twigPathAlias; - /** * @param array $options */ - public function __construct(Environment $env, array $options, string $twigPathAlias) - { + public function __construct( + Environment $env, + array $options, + private string $twigPathAlias + ) { parent::__construct($env, $options); - $this->twigPathAlias = $twigPathAlias; } - /** - * @param Source $source - * @param string|null $name - */ - public function tokenize($source, $name = null): TokenStream + public function tokenize(Source $source, ?string $name = null): TokenStream { - assert($source instanceof Source); $preparsed = $this->preparse($source->getCode()); return parent::tokenize( diff --git a/src/Compiler/ComponentTagCompiler.php b/src/Compiler/ComponentTagCompiler.php index 97e3c14..97bae5d 100644 --- a/src/Compiler/ComponentTagCompiler.php +++ b/src/Compiler/ComponentTagCompiler.php @@ -10,15 +10,10 @@ */ class ComponentTagCompiler { - protected string $source; - - private string $twigPathAlias; - - public function __construct(string $source, string $twigPathAlias) - { - $this->source = $source; - $this->twigPathAlias = $twigPathAlias; - } + public function __construct( + protected string $source, + private string $twigPathAlias + ) {} public function compile(): string { @@ -85,7 +80,7 @@ protected function componentStartString(string $component, string $attributes): { return sprintf( // another `%` is used for escaping the `%`, e. g. `%%` -> `%` - "{%% embed \"@%s/%s.twig\" with { props: %s } %%}", + '{%% embed "@%s/%s.twig" with { props: %s } %%}', $this->twigPathAlias, $this->normalizeComponentPathName($component), $attributes @@ -155,7 +150,7 @@ function (array $matches) { private function normalizeComponentPathName(string $name): string { return preg_replace_callback('/^[A-Z]+_?/', function ($matches) { - return strtolower($matches[0]); + return mb_strtolower($matches[0]); }, $name) ?: $name; } @@ -174,16 +169,16 @@ private function valueParser(?string $value, string $attribute): string // `"{ value } "` -> `{ value }` // `"{{value}} "` -> `{{value}}` // `"{value} "` -> `{value}` - $valueWithoutQuotes = trim($this->stripQuotes($value)); + $valueWithoutQuotes = mb_trim($this->stripQuotes($value)); // `{{ value }}` or `{{value}}` if (\str_starts_with($valueWithoutQuotes, '{{') && (mb_strpos($valueWithoutQuotes, '}}') === mb_strlen($valueWithoutQuotes) - 2)) { - return trim(mb_substr($valueWithoutQuotes, 2, -2)); + return mb_trim(mb_substr($valueWithoutQuotes, 2, -2)); } // `{ value }` or `{value}` if (\str_starts_with($valueWithoutQuotes, '{') && (mb_strpos($valueWithoutQuotes, '}') === mb_strlen($valueWithoutQuotes) - 1)) { - return trim(mb_substr($valueWithoutQuotes, 1, -1)); + return mb_trim(mb_substr($valueWithoutQuotes, 1, -1)); } return $value; @@ -236,7 +231,7 @@ protected function getAttributesFromAttributeString(string $attributeString): st $out .= "$key: $value,"; } - return rtrim($out, ',') . '}'; + return mb_rtrim($out, ',') . '}'; } /** diff --git a/tests/Compiler/ComponentTagCompilerTest.php b/tests/Compiler/ComponentTagCompilerTest.php index bb86fa3..e6be7e1 100644 --- a/tests/Compiler/ComponentTagCompilerTest.php +++ b/tests/Compiler/ComponentTagCompilerTest.php @@ -4,6 +4,7 @@ namespace Lmc\TwigXBundle\Compiler; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ComponentTagCompilerTest extends TestCase @@ -57,9 +58,7 @@ public function testShouldCompileTwigConditions(): void $this->assertSame('{% embed "@alias/alert.twig" with { props: {\'number\': true ? 12 : 10} } %}{% endembed %}', $compiler->compile()); } - /** - * @dataProvider twigParenthesesDataProvider - */ + #[DataProvider('twigParenthesesDataProvider')] public function testShouldCompileTwigVariablesParentheses(string $component, string $expected): void { $compiler = new ComponentTagCompiler($component, 'alias'); @@ -70,7 +69,7 @@ public function testShouldCompileTwigVariablesParentheses(string $component, str /** * @return array */ - public function twigParenthesesDataProvider(): array + public static function twigParenthesesDataProvider(): array { return [ // component, expected @@ -93,9 +92,7 @@ public function twigParenthesesDataProvider(): array ]; } - /** - * @dataProvider twigCommentsDataProvider - */ + #[DataProvider('twigCommentsDataProvider')] public function testShouldCompileTwigVariablesWithTwigComment(string $component, string $expected): void { $compiler = new ComponentTagCompiler($component, 'alias'); @@ -106,7 +103,7 @@ public function testShouldCompileTwigVariablesWithTwigComment(string $component, /** * @return array */ - public function twigCommentsDataProvider(): array + public static function twigCommentsDataProvider(): array { return [ // component, expected diff --git a/tests/DependencyInjection/CompilerPass/OverrideServiceCompilerPassTest.php b/tests/DependencyInjection/CompilerPass/OverrideServiceCompilerPassTest.php index 766a019..c59bc63 100644 --- a/tests/DependencyInjection/CompilerPass/OverrideServiceCompilerPassTest.php +++ b/tests/DependencyInjection/CompilerPass/OverrideServiceCompilerPassTest.php @@ -6,8 +6,8 @@ use Lmc\TwigXBundle\DependencyInjection\TwigXExtension; use Lmc\TwigXBundle\Helper\DefinitionHelper; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Twig\Environment; @@ -34,9 +34,9 @@ protected function setUp(): void } /** - * @dataProvider registerTwigPathsDataProvider * @param array $paths */ + #[DataProvider('registerTwigPathsDataProvider')] public function testShouldRegisterTwigPaths(array $paths, int $expectedCalls): void { $this->builder->setParameter('twigx.paths', $paths); @@ -55,7 +55,7 @@ public function testShouldRegisterTwigPaths(array $paths, int $expectedCalls): v /** * @return array */ - public function registerTwigPathsDataProvider(): array + public static function registerTwigPathsDataProvider(): array { $defaultPath = realpath(__DIR__ . '/../../../src/DependencyInjection') . '/../Resources/components'; diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 658053f..fe81bcb 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -13,11 +13,11 @@ public function testConfigurationDefinition(): void { $dumper = new YamlReferenceDumper(); $reference = <<assertEquals($reference, $dumper->dump(new Configuration())); } diff --git a/tests/DependencyInjection/TwigXExtensionTest.php b/tests/DependencyInjection/TwigXExtensionTest.php index dbb0643..300f559 100644 --- a/tests/DependencyInjection/TwigXExtensionTest.php +++ b/tests/DependencyInjection/TwigXExtensionTest.php @@ -4,7 +4,6 @@ namespace Lmc\TwigXBundle\DependencyInjection; -use JetBrains\PhpStorm\ArrayShape; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder;