Skip to content

Commit

Permalink
BREAKING CHANGE: Update all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasjanicek committed Dec 23, 2024
1 parent 45a647e commit 6ec75f1
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 114 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

<!-- There should always be "Unreleased" section at the beginning. -->
## 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
Expand Down
36 changes: 17 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion docker/install-composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 20 additions & 18 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
58 changes: 28 additions & 30 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<?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="vendor/autoload.php"
>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/Logger/Logger.php</file>
<file>src/TwigXBundle.php</file>
</exclude>
<report>
<clover outputFile="coverage/clover.xml"/>
<html outputDirectory="coverage" lowUpperBound="35" highLowerBound="90"/>
</report>
</coverage>
<php>
<!-- E_ALL = 30719 -->
<ini name="error_reporting" value="30719"/>
</php>
<testsuites>
<testsuite name="Bundle Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="coverage/junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<report>
<clover outputFile="coverage/clover.xml"/>
<html outputDirectory="coverage" lowUpperBound="35" highLowerBound="90"/>
</report>
</coverage>
<php>
<!-- E_ALL = 30719 -->
<ini name="error_reporting" value="30719"/>
</php>
<testsuites>
<testsuite name="Bundle Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="coverage/junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/Logger/Logger.php</file>
<file>src/TwigXBundle.php</file>
</exclude>
</source>
</phpunit>
17 changes: 6 additions & 11 deletions src/Compiler/ComponentLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@

class ComponentLexer extends Lexer
{
private string $twigPathAlias;

/**
* @param array<string, mixed> $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(
Expand Down
25 changes: 10 additions & 15 deletions src/Compiler/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -236,7 +231,7 @@ protected function getAttributesFromAttributeString(string $attributeString): st
$out .= "$key: $value,";
}

return rtrim($out, ',') . '}';
return mb_rtrim($out, ',') . '}';
}

/**
Expand Down
13 changes: 5 additions & 8 deletions tests/Compiler/ComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Lmc\TwigXBundle\Compiler;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ComponentTagCompilerTest extends TestCase
Expand Down Expand Up @@ -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');
Expand All @@ -70,7 +69,7 @@ public function testShouldCompileTwigVariablesParentheses(string $component, str
/**
* @return array<string, string[]>
*/
public function twigParenthesesDataProvider(): array
public static function twigParenthesesDataProvider(): array
{
return [
// component, expected
Expand All @@ -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');
Expand All @@ -106,7 +103,7 @@ public function testShouldCompileTwigVariablesWithTwigComment(string $component,
/**
* @return array<string, string[]>
*/
public function twigCommentsDataProvider(): array
public static function twigCommentsDataProvider(): array
{
return [
// component, expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,9 +34,9 @@ protected function setUp(): void
}

/**
* @dataProvider registerTwigPathsDataProvider
* @param array<string> $paths
*/
#[DataProvider('registerTwigPathsDataProvider')]
public function testShouldRegisterTwigPaths(array $paths, int $expectedCalls): void
{
$this->builder->setParameter('twigx.paths', $paths);
Expand All @@ -55,7 +55,7 @@ public function testShouldRegisterTwigPaths(array $paths, int $expectedCalls): v
/**
* @return array<string, mixed>
*/
public function registerTwigPathsDataProvider(): array
public static function registerTwigPathsDataProvider(): array
{
$defaultPath = realpath(__DIR__ . '/../../../src/DependencyInjection') . '/../Resources/components';

Expand Down
Loading

0 comments on commit 6ec75f1

Please sign in to comment.