Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: PHP Unit test in php 8.1 #29

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ TwigX Bundle
Symfony bundle extending Twig template engine with [JSX]-like markup.

## Requirements
- PHP 7.4 || 8.1
- Symfony 4.4+ || 5.4+ || ^6.1
- Twig >=1.44.6 || >=2.12.5 || 3+
- PHP ^8.1
- Symfony ^5.4 || ^6.4 || ^7.2
- Twig ^3

## Changelog
See [CHANGELOG](./CHANGELOG.md)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ext-simplexml": "*"
},
"require-dev": {
"phpunit/phpunit": "^11.5",
"phpunit/phpunit": "^10.5 ||^11.5",
"mockery/mockery": "^1.5",
"doctrine/cache": "^1.10",
"lmc/coding-standard": "^4.1",
Expand Down
4 changes: 4 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer;
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
Expand All @@ -18,6 +19,9 @@
directory: sys_get_temp_dir() . '/ecs_cached_files',
namespace: getcwd(),
)
->withSkip([
MbStrFunctionsFixer::class,
])
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
Expand Down
30 changes: 26 additions & 4 deletions src/Compiler/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ public function compile(): string
return $this->compileClosingTags($value);
}

private function trim(string $value, ?string $characters = null, ?string $encoding = null): string
{
if (PHP_VERSION_ID >= 80400 && function_exists('mb_trim')) {
return mb_trim($value, $characters, $encoding);
}

$characters = $characters ?: "\n\r\t\v\0\x0B\x0C ";

return trim($value, $characters);
}

private function rtrim(string $value, ?string $characters = null, ?string $encoding = null): string
{
if (PHP_VERSION_ID >= 80400 && function_exists('mb_rtrim')) {
return mb_rtrim($value, $characters, $encoding);
}

$characters = $characters ?: "\n\r\t\v\0\x0B\x0C ";

return rtrim($value, $characters);
}

/**
* Compile the opening tags within the given string.
*/
Expand Down Expand Up @@ -169,16 +191,16 @@ private function valueParser(?string $value, string $attribute): string
// `"{ value } "` -> `{ value }`
// `"{{value}} "` -> `{{value}}`
// `"{value} "` -> `{value}`
$valueWithoutQuotes = mb_trim($this->stripQuotes($value));
$valueWithoutQuotes = $this->trim($this->stripQuotes($value));

// `{{ value }}` or `{{value}}`
if (\str_starts_with($valueWithoutQuotes, '{{') && (mb_strpos($valueWithoutQuotes, '}}') === mb_strlen($valueWithoutQuotes) - 2)) {
return mb_trim(mb_substr($valueWithoutQuotes, 2, -2));
return $this->trim(mb_substr($valueWithoutQuotes, 2, -2));
}

// `{ value }` or `{value}`
if (\str_starts_with($valueWithoutQuotes, '{') && (mb_strpos($valueWithoutQuotes, '}') === mb_strlen($valueWithoutQuotes) - 1)) {
return mb_trim(mb_substr($valueWithoutQuotes, 1, -1));
return $this->trim(mb_substr($valueWithoutQuotes, 1, -1));
}

return $value;
Expand Down Expand Up @@ -231,7 +253,7 @@ protected function getAttributesFromAttributeString(string $attributeString): st
$out .= "$key: $value,";
}

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

/**
Expand Down
Loading