From 0f77325da00d3c44939f83e72035e9a7c4fa77e5 Mon Sep 17 00:00:00 2001 From: jmsche Date: Sun, 31 Aug 2025 14:44:19 +0200 Subject: [PATCH] Maintenance: GitHub actions, ECS, PHPStan & PHPUnit updates --- .gitattributes | 2 +- .github/workflows/build-docs.yaml | 2 +- .github/workflows/coding-standards.yaml | 12 +- .github/workflows/continuous-integration.yaml | 2 +- .github/workflows/static-analysis.yaml | 2 +- .gitignore | 1 - .php-cs-fixer.dist.php | 47 ------- composer.json | 14 +- ecs.php | 28 ++++ phpstan-baseline.neon | 120 +++++++++++++++--- phpunit.xml.dist | 1 + src/Controller/FeedController.php | 3 +- src/Controller/SitemapController.php | 3 +- src/Datalist/Action/DatalistAction.php | 4 +- src/Datalist/Action/DatalistActionConfig.php | 4 +- src/Datalist/Action/Type/SimpleActionType.php | 4 +- src/Datalist/Config.php | 3 +- src/Datalist/Datalist.php | 4 +- src/Datalist/DatalistConfig.php | 4 +- src/Datalist/Datasource/ArrayDatasource.php | 4 +- .../Datasource/DoctrineORMDatasource.php | 4 +- src/Datalist/Field/DatalistField.php | 4 +- src/Datalist/Field/DatalistFieldConfig.php | 4 +- src/Datalist/Filter/DatalistFilter.php | 4 +- src/Datalist/Filter/DatalistFilterConfig.php | 4 +- .../Filter/Expression/ExpressionInterface.php | 4 +- src/Datalist/Type/AbstractDatalistType.php | 4 +- src/Doctrine/Mapping/File.php | 3 +- .../Field/Configurator/FileConfigurator.php | 4 +- src/Event/UploadedFileEvent.php | 3 +- src/File/CondemnedFile.php | 4 +- src/FileStorage/FileStorageManager.php | 3 +- src/FileStorage/FileUploadConfig.php | 3 +- src/FileStorage/FilesystemStorage.php | 4 +- src/FileStorage/FlysystemStorage.php | 4 +- src/Form/Extension/HoneypotExtension.php | 3 +- src/Form/Listener/HoneypotListener.php | 3 +- src/Listener/FileSubscriber.php | 4 +- src/Locale/LocaleResolver.php | 3 +- src/Navigation/NavigationRegistry.php | 4 +- src/Paginator/ArrayPaginator.php | 4 +- src/Twig/Extension/DateExtension.php | 4 +- src/Twig/Extension/FacebookExtension.php | 4 +- src/Twig/Extension/GoogleExtension.php | 4 +- src/Twig/Extension/NavigationExtension.php | 4 +- src/Util/StringUtil.php | 12 +- .../Constraints/PasswordStrength.php | 11 +- .../Constraints/RecaptchaValidator.php | 3 +- .../Field/Type/LabelFieldTypeEnumTest.php | 8 +- .../Field/Type/LabelFieldTypeTest.php | 5 +- .../Datalist/Field/Type/TextFieldTypeTest.php | 7 +- .../Filter/Type/BooleanFilterTypeTest.php | 5 +- .../Filter/Type/ChoiceFilterTypeTest.php | 5 +- .../Filter/Type/EnumFilterTypeTest.php | 8 +- .../Filter/Type/IsNullFilterTypeTest.php | 5 +- .../Filter/Type/SearchFilterTypeTest.php | 5 +- tests/Paginator/Fixtures/LoadPlayerData.php | 4 +- tests/Twig/Extension/DateExtensionTest.php | 5 +- tests/Twig/Extension/SiteExtensionTest.php | 5 +- .../PasswordStrengthValidatorTest.php | 9 +- tests/Validator/SlugValidatorTest.php | 9 +- tests/bootstrap.php | 2 + 62 files changed, 228 insertions(+), 237 deletions(-) delete mode 100644 .php-cs-fixer.dist.php create mode 100644 ecs.php diff --git a/.gitattributes b/.gitattributes index 2c8351d3..cda4dd56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,8 @@ .gitattributes export-ignore .gitignore export-ignore -.php-cs-fixer.dist.php export-ignore /.github export-ignore /tests export-ignore +ecs.php export-ignore Makefile export-ignore mkdocs.yml export-ignore phpstan.neon.dist export-ignore diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml index 33c85f4c..f34204c0 100644 --- a/.github/workflows/build-docs.yaml +++ b/.github/workflows/build-docs.yaml @@ -8,7 +8,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: actions/setup-python@v5 with: python-version: 3.x diff --git a/.github/workflows/coding-standards.yaml b/.github/workflows/coding-standards.yaml index f9ea996f..066c8362 100644 --- a/.github/workflows/coding-standards.yaml +++ b/.github/workflows/coding-standards.yaml @@ -7,8 +7,8 @@ on: branches: ['5.x', '4.x', '3.x'] jobs: - php-cs-fixer: - name: PHP CS Fixer (PHP ${{ matrix.php-version }}) + easy-coding-standard: + name: Easy Coding Standard (PHP ${{ matrix.php-version }}) runs-on: ubuntu-24.04 strategy: @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -30,7 +30,5 @@ jobs: - name: Install Composer dependencies uses: ramsey/composer-install@v3 - - name: Run PHP CS Fixer - run: 'vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr' - env: - PHP_CS_FIXER_IGNORE_ENV: 1 + - name: Run Easy Coding Standard + run: 'vendor/bin/ecs --output-format=checkstyle | cs2pr' diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 260f634f..c39f2875 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -26,7 +26,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: fetch-depth: 2 diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 067ed2f9..875373b7 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Install PHP uses: shivammathur/setup-php@v2 diff --git a/.gitignore b/.gitignore index 6593e7c4..e6a68a9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .idea .DS_Store -.php_cs.cache .phpunit.result.cache phpunit.xml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index d3145ee7..00000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,47 +0,0 @@ -in(__DIR__ . '/src') - ->in(__DIR__ . '/tests') -; - -return (new PhpCsFixer\Config()) - ->setRiskyAllowed(true) - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'no_unneeded_final_method' => false, - 'dir_constant' => true, - 'modernize_types_casting' => true, - 'echo_tag_syntax' => ['format' => 'short'], - 'no_useless_else' => true, - 'no_useless_return' => true, - 'native_function_invocation' => ['include' => ['@compiler_optimized']], - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_construct' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => [ - 'operators' => [ - '=>' => 'align_single_space', - ], - ], - 'concat_space' => ['spacing' => 'one'], - 'semicolon_after_instruction' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'yoda_style' => [ - 'always_move_variable' => true, - 'equal' => true, - 'identical' => true, - 'less_and_greater' => true, - ], - 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']], - 'declare_strict_types' => true, - ]) - ->setFinder($finder) - ->setCacheFile(__DIR__.'/.php_cs.cache') - ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) -; diff --git a/composer.json b/composer.json index c0be2050..b115ea20 100644 --- a/composer.json +++ b/composer.json @@ -45,14 +45,14 @@ "doctrine/persistence": "^3.2", "easycorp/easyadmin-bundle": "^4.8.5", "endroid/qr-code": "^4.8 || ^5.0 || ^6.0", - "friendsofphp/php-cs-fixer": "^3.49.0", "fakerphp/faker": "^1.23", "google/recaptcha": "^1.3", "league/flysystem-bundle": "^3.0", - "phpstan/phpstan": "^1.10.57", - "phpstan/phpstan-deprecation-rules": "^1.1.4", - "phpunit/phpunit": "^10.5.10", - "symfony/browser-kit": "^6.4 || ^7.0" + "phpstan/phpstan": "^2.1.22", + "phpstan/phpstan-deprecation-rules": "^2.0.3", + "phpunit/phpunit": "^11.5.35", + "symfony/browser-kit": "^6.4 || ^7.0", + "symplify/easy-coding-standard": "^12.5.24" }, "config": { "sort-packages": true @@ -63,8 +63,8 @@ "@phpstan", "@phpunit" ], - "cs:dry": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --diff --dry-run --no-interaction --ansi", - "cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --ansi", + "cs:dry": "vendor/bin/ecs", + "cs:fix": "vendor/bin/ecs --fix", "phpstan": "vendor/bin/phpstan analyse --ansi", "phpunit": "vendor/bin/phpunit --colors=auto" }, diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..df680e11 --- /dev/null +++ b/ecs.php @@ -0,0 +1,28 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withRootFiles() + ->withRules([ + NoUselessElseFixer::class, + NoUselessReturnFixer::class, + StrictComparisonFixer::class, + StrictParamFixer::class, + DeclareStrictTypesFixer::class, + NoUnusedImportsFixer::class, + ]) + ->withPhpCsFixerSets(perCS20: true, symfonyRisky: true) +; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d0db894d..0e28a787 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,77 +1,157 @@ parameters: ignoreErrors: - - message: "#^Property Leapt\\\\CoreBundle\\\\Datalist\\\\Datalist\\:\\:\\$iterator \\(Iterator\\) does not accept Traversable\\\\.$#" + message: '#^Property Leapt\\CoreBundle\\Datalist\\Datalist\:\:\$iterator \(Iterator\) does not accept Traversable\\.$#' + identifier: assign.propertyType count: 1 path: src/Datalist/Datalist.php - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, Iterator given\\.$#" + message: '#^Parameter \#1 \$value of function count expects array\|Countable, Iterator given\.$#' + identifier: argument.type count: 1 path: src/Datalist/Datasource/AbstractDatasource.php - - message: "#^Method Leapt\\\\CoreBundle\\\\Datalist\\\\Field\\\\DatalistField\\:\\:getType\\(\\) should return Leapt\\\\CoreBundle\\\\Datalist\\\\Field\\\\Type\\\\FieldTypeInterface but returns Leapt\\\\CoreBundle\\\\Datalist\\\\TypeInterface\\.$#" + message: '#^Method Leapt\\CoreBundle\\Datalist\\Field\\DatalistField\:\:getType\(\) should return Leapt\\CoreBundle\\Datalist\\Field\\Type\\FieldTypeInterface but returns Leapt\\CoreBundle\\Datalist\\TypeInterface\.$#' + identifier: return.type count: 1 path: src/Datalist/Field/DatalistField.php - - message: "#^Method Leapt\\\\CoreBundle\\\\Datalist\\\\Filter\\\\DatalistFilter\\:\\:getType\\(\\) should return Leapt\\\\CoreBundle\\\\Datalist\\\\Filter\\\\Type\\\\FilterTypeInterface but returns Leapt\\\\CoreBundle\\\\Datalist\\\\TypeInterface\\.$#" + message: '#^Method Leapt\\CoreBundle\\Datalist\\Filter\\DatalistFilter\:\:getType\(\) should return Leapt\\CoreBundle\\Datalist\\Filter\\Type\\FilterTypeInterface but returns Leapt\\CoreBundle\\Datalist\\TypeInterface\.$#' + identifier: return.type count: 1 path: src/Datalist/Filter/DatalistFilter.php - - message: "#^Method Leapt\\\\CoreBundle\\\\Paginator\\\\DoctrineORMPaginator\\:\\:getIterator\\(\\) should return ArrayIterator but returns Traversable\\<\\(int\\|string\\), mixed\\>\\.$#" + message: '#^Method Leapt\\CoreBundle\\Paginator\\DoctrineORMPaginator\:\:getIterator\(\) should return ArrayIterator but returns Traversable\<\(int\|string\), mixed\>\.$#' + identifier: return.type count: 1 path: src/Paginator/DoctrineORMPaginator.php - - message: "#^Call to function method_exists\\(\\) with 'Endroid\\\\\\\\QrCode\\\\\\\\Builder\\\\\\\\Builder' and 'create' will always evaluate to false\\.$#" + message: '#^Call to method getParent\(\) of internal class Twig\\Template from outside its root namespace Twig\.$#' + identifier: method.internalClass + count: 1 + path: src/Twig/Extension/DatalistExtension.php + + - + message: '#^Call to method hasBlock\(\) of internal class Twig\\Template from outside its root namespace Twig\.$#' + identifier: method.internalClass + count: 1 + path: src/Twig/Extension/DatalistExtension.php + + - + message: '#^Call to method renderBlock\(\) of internal class Twig\\Template from outside its root namespace Twig\.$#' + identifier: method.internalClass + count: 1 + path: src/Twig/Extension/DatalistExtension.php + + - + message: '#^Instanceof references internal class Twig\\Template\.$#' + identifier: instanceof.internalClass + count: 1 + path: src/Twig/Extension/DatalistExtension.php + + - + message: '#^Call to method getParent\(\) of internal class Twig\\Template from outside its root namespace Twig\.$#' + identifier: method.internalClass + count: 1 + path: src/Twig/Extension/PaginatorExtension.php + + - + message: '#^Call to method hasBlock\(\) of internal class Twig\\Template from outside its root namespace Twig\.$#' + identifier: method.internalClass + count: 1 + path: src/Twig/Extension/PaginatorExtension.php + + - + message: '#^Call to method renderBlock\(\) of internal class Twig\\Template from outside its root namespace Twig\.$#' + identifier: method.internalClass + count: 1 + path: src/Twig/Extension/PaginatorExtension.php + + - + message: '#^Instanceof references internal class Twig\\Template\.$#' + identifier: instanceof.internalClass + count: 1 + path: src/Twig/Extension/PaginatorExtension.php + + - + message: '#^Call to function method_exists\(\) with ''Endroid\\\\QrCode\\\\Builder\\\\Builder'' and ''create'' will always evaluate to false\.$#' + identifier: function.impossibleType count: 1 path: src/Twig/Extension/QrCodeExtension.php - - message: """ - #^Call to deprecated method getExpressionParser\\(\\) of class Twig\\\\Parser\\: - since Twig 3\\.21$# - """ + message: ''' + #^Call to deprecated method getExpressionParser\(\) of class Twig\\Parser\: + since Twig 3\.21$# + ''' + identifier: method.deprecated count: 3 path: src/Twig/TokenParser/DatalistThemeTokenParser.php - - message: "#^Call to function method_exists\\(\\) with Twig\\\\Parser and 'parseExpression' will always evaluate to true\\.$#" + message: '#^Call to function method_exists\(\) with Twig\\Parser and ''parseExpression'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType count: 3 path: src/Twig/TokenParser/DatalistThemeTokenParser.php - - message: """ - #^Call to deprecated method getExpressionParser\\(\\) of class Twig\\\\Parser\\: - since Twig 3\\.21$# - """ + message: ''' + #^Call to method parseExpression\(\) of deprecated class Twig\\ExpressionParser\: + since Twig 3\.21$# + ''' + identifier: method.deprecatedClass + count: 3 + path: src/Twig/TokenParser/DatalistThemeTokenParser.php + + - + message: ''' + #^Call to deprecated method getExpressionParser\(\) of class Twig\\Parser\: + since Twig 3\.21$# + ''' + identifier: method.deprecated + count: 3 + path: src/Twig/TokenParser/PaginatorThemeTokenParser.php + + - + message: '#^Call to function method_exists\(\) with Twig\\Parser and ''parseExpression'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType count: 3 path: src/Twig/TokenParser/PaginatorThemeTokenParser.php - - message: "#^Call to function method_exists\\(\\) with Twig\\\\Parser and 'parseExpression' will always evaluate to true\\.$#" + message: ''' + #^Call to method parseExpression\(\) of deprecated class Twig\\ExpressionParser\: + since Twig 3\.21$# + ''' + identifier: method.deprecatedClass count: 3 path: src/Twig/TokenParser/PaginatorThemeTokenParser.php - - message: "#^Method Leapt\\\\CoreBundle\\\\Tests\\\\LeaptCoreTestingKernel\\:\\:configureContainer\\(\\) is unused\\.$#" + message: '#^Method Leapt\\CoreBundle\\Tests\\LeaptCoreTestingKernel\:\:configureContainer\(\) is unused\.$#' + identifier: method.unused count: 1 path: tests/LeaptCoreTestingKernel.php - - message: "#^Method Leapt\\\\CoreBundle\\\\Tests\\\\LeaptCoreTestingKernel\\:\\:configureRoutes\\(\\) is unused\\.$#" + message: '#^Method Leapt\\CoreBundle\\Tests\\LeaptCoreTestingKernel\:\:configureRoutes\(\) is unused\.$#' + identifier: method.unused count: 1 path: tests/LeaptCoreTestingKernel.php - - message: "#^Property Leapt\\\\CoreBundle\\\\Tests\\\\Listener\\\\Fixtures\\\\Entity\\\\User\\:\\:\\$id is never written, only read\\.$#" + message: '#^Property Leapt\\CoreBundle\\Tests\\Listener\\Fixtures\\Entity\\User\:\:\$id is never written, only read\.$#' + identifier: property.onlyRead count: 1 path: tests/Listener/Fixtures/Entity/User.php - - message: "#^Property Leapt\\\\CoreBundle\\\\Tests\\\\Paginator\\\\Entity\\\\Player\\:\\:\\$id is never written, only read\\.$#" + message: '#^Property Leapt\\CoreBundle\\Tests\\Paginator\\Entity\\Player\:\:\$id is never written, only read\.$#' + identifier: property.onlyRead count: 1 path: tests/Paginator/Entity/Player.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 596e1957..42919f0d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,6 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnPhpunitDeprecations="true" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" > diff --git a/src/Controller/FeedController.php b/src/Controller/FeedController.php index 4bfe0234..9a22120a 100644 --- a/src/Controller/FeedController.php +++ b/src/Controller/FeedController.php @@ -17,8 +17,7 @@ public function __construct( private FeedManager $feedManager, private ValidatorInterface $validator, private Environment $twig, - ) { - } + ) {} public function indexAction(Request $request, string $feedName): Response { diff --git a/src/Controller/SitemapController.php b/src/Controller/SitemapController.php index f28be0b1..48b30a35 100644 --- a/src/Controller/SitemapController.php +++ b/src/Controller/SitemapController.php @@ -19,8 +19,7 @@ public function __construct( private RouterInterface $router, private Environment $twig, private HttpKernelInterface $httpKernel, - ) { - } + ) {} public function defaultAction(Request $request): Response { diff --git a/src/Datalist/Action/DatalistAction.php b/src/Datalist/Action/DatalistAction.php index 0f753cd2..2bfe1e22 100644 --- a/src/Datalist/Action/DatalistAction.php +++ b/src/Datalist/Action/DatalistAction.php @@ -11,9 +11,7 @@ class DatalistAction implements DatalistActionInterface { private DatalistInterface $datalist; - public function __construct(private DatalistActionConfig $config) - { - } + public function __construct(private DatalistActionConfig $config) {} public function getName(): string { diff --git a/src/Datalist/Action/DatalistActionConfig.php b/src/Datalist/Action/DatalistActionConfig.php index f5036bff..44e43633 100644 --- a/src/Datalist/Action/DatalistActionConfig.php +++ b/src/Datalist/Action/DatalistActionConfig.php @@ -6,6 +6,4 @@ use Leapt\CoreBundle\Datalist\Config; -class DatalistActionConfig extends Config -{ -} +class DatalistActionConfig extends Config {} diff --git a/src/Datalist/Action/Type/SimpleActionType.php b/src/Datalist/Action/Type/SimpleActionType.php index ac2afadf..941517c6 100644 --- a/src/Datalist/Action/Type/SimpleActionType.php +++ b/src/Datalist/Action/Type/SimpleActionType.php @@ -12,9 +12,7 @@ class SimpleActionType extends AbstractActionType { - public function __construct(protected RouterInterface $router) - { - } + public function __construct(protected RouterInterface $router) {} public function configureOptions(OptionsResolver $resolver): void { diff --git a/src/Datalist/Config.php b/src/Datalist/Config.php index 8dfdab1d..88978855 100644 --- a/src/Datalist/Config.php +++ b/src/Datalist/Config.php @@ -10,8 +10,7 @@ public function __construct( protected string $name, protected TypeInterface $type, protected array $options = [], - ) { - } + ) {} public function getName(): string { diff --git a/src/Datalist/Datalist.php b/src/Datalist/Datalist.php index 22333350..4e949178 100644 --- a/src/Datalist/Datalist.php +++ b/src/Datalist/Datalist.php @@ -47,9 +47,7 @@ class Datalist implements DatalistInterface, \Countable private array $routeParams = []; - public function __construct(private DatalistConfig $config) - { - } + public function __construct(private DatalistConfig $config) {} public function getType(): TypeInterface { diff --git a/src/Datalist/DatalistConfig.php b/src/Datalist/DatalistConfig.php index 091feb0c..404b3b35 100644 --- a/src/Datalist/DatalistConfig.php +++ b/src/Datalist/DatalistConfig.php @@ -4,6 +4,4 @@ namespace Leapt\CoreBundle\Datalist; -class DatalistConfig extends Config -{ -} +class DatalistConfig extends Config {} diff --git a/src/Datalist/Datasource/ArrayDatasource.php b/src/Datalist/Datasource/ArrayDatasource.php index b84da904..2fb71811 100644 --- a/src/Datalist/Datasource/ArrayDatasource.php +++ b/src/Datalist/Datasource/ArrayDatasource.php @@ -15,9 +15,7 @@ class ArrayDatasource extends AbstractDatasource { private bool $initialized = false; - public function __construct(private array $items = []) - { - } + public function __construct(private array $items = []) {} public function getPaginator(): ?PaginatorInterface { diff --git a/src/Datalist/Datasource/DoctrineORMDatasource.php b/src/Datalist/Datasource/DoctrineORMDatasource.php index 1934140b..0a44ec5f 100644 --- a/src/Datalist/Datasource/DoctrineORMDatasource.php +++ b/src/Datalist/Datasource/DoctrineORMDatasource.php @@ -19,9 +19,7 @@ class DoctrineORMDatasource extends AbstractDatasource { private bool $initialized = false; - public function __construct(private QueryBuilder $queryBuilder) - { - } + public function __construct(private QueryBuilder $queryBuilder) {} public function getPaginator(): ?PaginatorInterface { diff --git a/src/Datalist/Field/DatalistField.php b/src/Datalist/Field/DatalistField.php index 98e405df..014d10e0 100644 --- a/src/Datalist/Field/DatalistField.php +++ b/src/Datalist/Field/DatalistField.php @@ -14,9 +14,7 @@ class DatalistField implements DatalistFieldInterface { private DatalistInterface $datalist; - public function __construct(private DatalistFieldConfig $config) - { - } + public function __construct(private DatalistFieldConfig $config) {} public function getName(): string { diff --git a/src/Datalist/Field/DatalistFieldConfig.php b/src/Datalist/Field/DatalistFieldConfig.php index 07dcb6ad..06d6dd01 100644 --- a/src/Datalist/Field/DatalistFieldConfig.php +++ b/src/Datalist/Field/DatalistFieldConfig.php @@ -6,6 +6,4 @@ use Leapt\CoreBundle\Datalist\Config; -class DatalistFieldConfig extends Config -{ -} +class DatalistFieldConfig extends Config {} diff --git a/src/Datalist/Filter/DatalistFilter.php b/src/Datalist/Filter/DatalistFilter.php index 12ddf572..67006fd9 100644 --- a/src/Datalist/Filter/DatalistFilter.php +++ b/src/Datalist/Filter/DatalistFilter.php @@ -11,9 +11,7 @@ class DatalistFilter implements DatalistFilterInterface { private DatalistInterface $datalist; - public function __construct(private DatalistFilterConfig $config) - { - } + public function __construct(private DatalistFilterConfig $config) {} public function getName(): string { diff --git a/src/Datalist/Filter/DatalistFilterConfig.php b/src/Datalist/Filter/DatalistFilterConfig.php index 8a8e2be0..92fa459a 100644 --- a/src/Datalist/Filter/DatalistFilterConfig.php +++ b/src/Datalist/Filter/DatalistFilterConfig.php @@ -6,6 +6,4 @@ use Leapt\CoreBundle\Datalist\Config; -class DatalistFilterConfig extends Config -{ -} +class DatalistFilterConfig extends Config {} diff --git a/src/Datalist/Filter/Expression/ExpressionInterface.php b/src/Datalist/Filter/Expression/ExpressionInterface.php index ae73321c..5d5cac89 100644 --- a/src/Datalist/Filter/Expression/ExpressionInterface.php +++ b/src/Datalist/Filter/Expression/ExpressionInterface.php @@ -4,6 +4,4 @@ namespace Leapt\CoreBundle\Datalist\Filter\Expression; -interface ExpressionInterface -{ -} +interface ExpressionInterface {} diff --git a/src/Datalist/Type/AbstractDatalistType.php b/src/Datalist/Type/AbstractDatalistType.php index a2f60ad4..f907a7ef 100644 --- a/src/Datalist/Type/AbstractDatalistType.php +++ b/src/Datalist/Type/AbstractDatalistType.php @@ -33,9 +33,7 @@ public function configureOptions(OptionsResolver $resolver): void ]); } - public function buildDatalist(DatalistBuilder $builder, array $options): void - { - } + public function buildDatalist(DatalistBuilder $builder, array $options): void {} public function buildViewContext(ViewContext $viewContext, DatalistInterface $datalist, array $options): void { diff --git a/src/Doctrine/Mapping/File.php b/src/Doctrine/Mapping/File.php index 0b3f31d8..15190e48 100644 --- a/src/Doctrine/Mapping/File.php +++ b/src/Doctrine/Mapping/File.php @@ -14,6 +14,5 @@ public function __construct( public ?string $filename = null, public ?string $nameCallback = null, public ?string $flysystemConfig = null, - ) { - } + ) {} } diff --git a/src/EasyAdmin/Field/Configurator/FileConfigurator.php b/src/EasyAdmin/Field/Configurator/FileConfigurator.php index 69bd30aa..01a73e73 100644 --- a/src/EasyAdmin/Field/Configurator/FileConfigurator.php +++ b/src/EasyAdmin/Field/Configurator/FileConfigurator.php @@ -15,9 +15,7 @@ final class FileConfigurator implements FieldConfiguratorInterface { - public function __construct(private AssetExtension $assetExtension) - { - } + public function __construct(private AssetExtension $assetExtension) {} public function supports(FieldDto $field, EntityDto $entityDto): bool { diff --git a/src/Event/UploadedFileEvent.php b/src/Event/UploadedFileEvent.php index 3640cef8..79db3c83 100644 --- a/src/Event/UploadedFileEvent.php +++ b/src/Event/UploadedFileEvent.php @@ -12,6 +12,5 @@ final class UploadedFileEvent extends Event public function __construct( public \SplFileInfo $splFileInfo, public FileUploadConfig $fileUploadConfig, - ) { - } + ) {} } diff --git a/src/File/CondemnedFile.php b/src/File/CondemnedFile.php index 907caa69..9a989aab 100644 --- a/src/File/CondemnedFile.php +++ b/src/File/CondemnedFile.php @@ -16,9 +16,7 @@ class CondemnedFile extends UploadedFile /** * Override parent constructor. */ - public function __construct() - { - } + public function __construct() {} public function isValid(): bool { diff --git a/src/FileStorage/FileStorageManager.php b/src/FileStorage/FileStorageManager.php index d6a91260..a4b8bb56 100644 --- a/src/FileStorage/FileStorageManager.php +++ b/src/FileStorage/FileStorageManager.php @@ -14,8 +14,7 @@ public function __construct( private FilesystemStorage $filesystemStorage, private FlysystemStorage $flysystemStorage, private EventDispatcherInterface $eventDispatcher, - ) { - } + ) {} public function uploadFile(FileUploadConfig $fileUploadConfig, File $uploadedFile, string $path, string $filename): void { diff --git a/src/FileStorage/FileUploadConfig.php b/src/FileStorage/FileUploadConfig.php index 3345b358..e3f581d3 100644 --- a/src/FileStorage/FileUploadConfig.php +++ b/src/FileStorage/FileUploadConfig.php @@ -13,6 +13,5 @@ public function __construct( public \ReflectionProperty $property, public File $attribute, public ClassMetadata $classMetadata, - ) { - } + ) {} } diff --git a/src/FileStorage/FilesystemStorage.php b/src/FileStorage/FilesystemStorage.php index 837acadf..c9c94b10 100644 --- a/src/FileStorage/FilesystemStorage.php +++ b/src/FileStorage/FilesystemStorage.php @@ -8,9 +8,7 @@ final class FilesystemStorage implements StorageInterface { - public function __construct(private string $uploadDir) - { - } + public function __construct(private string $uploadDir) {} public function uploadFile(FileUploadConfig $fileUploadConfig, File $uploadedFile, string $path, string $filename): void { diff --git a/src/FileStorage/FlysystemStorage.php b/src/FileStorage/FlysystemStorage.php index 3340d01e..d573d9d9 100644 --- a/src/FileStorage/FlysystemStorage.php +++ b/src/FileStorage/FlysystemStorage.php @@ -12,9 +12,7 @@ final class FlysystemStorage implements StorageInterface /** * @param array $storages */ - public function __construct(private array $storages) - { - } + public function __construct(private array $storages) {} public function uploadFile(FileUploadConfig $fileUploadConfig, File $uploadedFile, string $path, string $filename): void { diff --git a/src/Form/Extension/HoneypotExtension.php b/src/Form/Extension/HoneypotExtension.php index 1e842895..4bc8413e 100644 --- a/src/Form/Extension/HoneypotExtension.php +++ b/src/Form/Extension/HoneypotExtension.php @@ -21,8 +21,7 @@ public function __construct( private bool $enableGlobally, private string $inputName, private string $cssClass, - ) { - } + ) {} public function buildForm(FormBuilderInterface $builder, array $options): void { diff --git a/src/Form/Listener/HoneypotListener.php b/src/Form/Listener/HoneypotListener.php index 4daa4e45..8de8fb68 100644 --- a/src/Form/Listener/HoneypotListener.php +++ b/src/Form/Listener/HoneypotListener.php @@ -15,8 +15,7 @@ final class HoneypotListener implements EventSubscriberInterface public function __construct( private TranslatorInterface $translator, private string $fieldName, - ) { - } + ) {} public static function getSubscribedEvents(): array { diff --git a/src/Listener/FileSubscriber.php b/src/Listener/FileSubscriber.php index 4d27bfb9..b1cf0127 100644 --- a/src/Listener/FileSubscriber.php +++ b/src/Listener/FileSubscriber.php @@ -28,9 +28,7 @@ class FileSubscriber private array $config = []; private array $unlinkQueue = []; - public function __construct(private FileStorageManager $fileStorageManager) - { - } + public function __construct(private FileStorageManager $fileStorageManager) {} public function preFlush(PreFlushEventArgs $ea): void { diff --git a/src/Locale/LocaleResolver.php b/src/Locale/LocaleResolver.php index a8c1eed0..762bdfb3 100644 --- a/src/Locale/LocaleResolver.php +++ b/src/Locale/LocaleResolver.php @@ -15,8 +15,7 @@ public function __construct( private string $defaultLocale, private bool $useLocaleFromRequest, private RequestStack $requestStack, - ) { - } + ) {} /** * @return string The resolved locale key, depending on configuration diff --git a/src/Navigation/NavigationRegistry.php b/src/Navigation/NavigationRegistry.php index 10dffce2..c5fdaaf9 100644 --- a/src/Navigation/NavigationRegistry.php +++ b/src/Navigation/NavigationRegistry.php @@ -12,9 +12,7 @@ class NavigationRegistry private array $breadcrumbsPaths = []; - public function __construct(private RequestStack $requestStack) - { - } + public function __construct(private RequestStack $requestStack) {} /** * Set the paths to be considered as active (navigation-wise). diff --git a/src/Paginator/ArrayPaginator.php b/src/Paginator/ArrayPaginator.php index fceef072..8d2c4ec9 100644 --- a/src/Paginator/ArrayPaginator.php +++ b/src/Paginator/ArrayPaginator.php @@ -6,9 +6,7 @@ class ArrayPaginator extends AbstractPaginator { - public function __construct(private array $items) - { - } + public function __construct(private array $items) {} public function setPage(int $page): PaginatorInterface { diff --git a/src/Twig/Extension/DateExtension.php b/src/Twig/Extension/DateExtension.php index bfb6a431..97877b81 100644 --- a/src/Twig/Extension/DateExtension.php +++ b/src/Twig/Extension/DateExtension.php @@ -10,9 +10,7 @@ class DateExtension extends AbstractExtension { - public function __construct(private TranslatorInterface $translator) - { - } + public function __construct(private TranslatorInterface $translator) {} public function getFilters(): array { diff --git a/src/Twig/Extension/FacebookExtension.php b/src/Twig/Extension/FacebookExtension.php index 6b4a8710..c3a23c78 100644 --- a/src/Twig/Extension/FacebookExtension.php +++ b/src/Twig/Extension/FacebookExtension.php @@ -10,9 +10,7 @@ class FacebookExtension extends AbstractExtension { - public function __construct(private ?string $appId) - { - } + public function __construct(private ?string $appId) {} public function getFunctions(): array { diff --git a/src/Twig/Extension/GoogleExtension.php b/src/Twig/Extension/GoogleExtension.php index ee9b75c4..19c8d6e1 100644 --- a/src/Twig/Extension/GoogleExtension.php +++ b/src/Twig/Extension/GoogleExtension.php @@ -18,9 +18,7 @@ class GoogleExtension extends AbstractExtension private ?string $tagsManagerId; - public function __construct(private ?string $accountId = null, private bool $debug = false) - { - } + public function __construct(private ?string $accountId = null, private bool $debug = false) {} /** * @codeCoverageIgnore diff --git a/src/Twig/Extension/NavigationExtension.php b/src/Twig/Extension/NavigationExtension.php index 0379cf0a..d85e6293 100644 --- a/src/Twig/Extension/NavigationExtension.php +++ b/src/Twig/Extension/NavigationExtension.php @@ -10,9 +10,7 @@ class NavigationExtension extends AbstractExtension { - public function __construct(private NavigationRegistry $registry) - { - } + public function __construct(private NavigationRegistry $registry) {} /** * @codeCoverageIgnore diff --git a/src/Util/StringUtil.php b/src/Util/StringUtil.php index ab6a328d..ea1b0f9e 100644 --- a/src/Util/StringUtil.php +++ b/src/Util/StringUtil.php @@ -69,9 +69,15 @@ public static function slugify(string $string): string $slug = preg_replace('/\W/', ' ', $slug); // More stripping. Replace spaces with dashes - $slug = strtolower(preg_replace('/[^A-Z^a-z^0-9^\/]+/', '-', - preg_replace('/([a-z\d])([A-Z])/', '\1_\2', - preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2', + $slug = strtolower(preg_replace( + '/[^A-Z^a-z^0-9^\/]+/', + '-', + preg_replace( + '/([a-z\d])([A-Z])/', + '\1_\2', + preg_replace( + '/([A-Z]+)([A-Z][a-z])/', + '\1_\2', preg_replace('/::/', '/', $slug), ), ), diff --git a/src/Validator/Constraints/PasswordStrength.php b/src/Validator/Constraints/PasswordStrength.php index 86e9d416..67328b19 100644 --- a/src/Validator/Constraints/PasswordStrength.php +++ b/src/Validator/Constraints/PasswordStrength.php @@ -17,8 +17,15 @@ class PasswordStrength extends Constraint public int $score = 50; public function __construct( - ?array $options = null, ?int $min = null, ?string $minMessage = null, ?int $max = null, ?string $maxMessage = null, - ?int $score = null, ?string $scoreMessage = null, ?array $groups = null, $payload = null, + ?array $options = null, + ?int $min = null, + ?string $minMessage = null, + ?int $max = null, + ?string $maxMessage = null, + ?int $score = null, + ?string $scoreMessage = null, + ?array $groups = null, + $payload = null, ) { trigger_deprecation('leapt/core-bundle', '5.3.0', 'The PasswordStrength constraint will be removed in leapt/core-bundle v6. You can replace it using e.g. Symfony\'s PasswordStrength constraint instead.'); parent::__construct($options ?? [], $groups, $payload); diff --git a/src/Validator/Constraints/RecaptchaValidator.php b/src/Validator/Constraints/RecaptchaValidator.php index 11173891..552d845a 100644 --- a/src/Validator/Constraints/RecaptchaValidator.php +++ b/src/Validator/Constraints/RecaptchaValidator.php @@ -22,8 +22,7 @@ public function __construct( protected RequestStack $requestStack, protected array $httpProxy, protected bool $verifyHost, - ) { - } + ) {} public function validate(mixed $value, Constraint $constraint): void { diff --git a/tests/Datalist/Field/Type/LabelFieldTypeEnumTest.php b/tests/Datalist/Field/Type/LabelFieldTypeEnumTest.php index be71b6d2..76594b74 100644 --- a/tests/Datalist/Field/Type/LabelFieldTypeEnumTest.php +++ b/tests/Datalist/Field/Type/LabelFieldTypeEnumTest.php @@ -12,16 +12,12 @@ use Leapt\CoreBundle\Datalist\Type\DatalistType; use Leapt\CoreBundle\Datalist\ViewContext; use Leapt\CoreBundle\Tests\Datalist\Field\Type\Enum\Status; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -/** - * @requires PHP 8.1 - */ final class LabelFieldTypeEnumTest extends WebTestCase { - /** - * @dataProvider buildViewContextProvider - */ + #[DataProvider('buildViewContextProvider')] public function testBuildViewContext(string $expectedValue, array $item, array $options = []): void { $fieldType = new LabelFieldType(); diff --git a/tests/Datalist/Field/Type/LabelFieldTypeTest.php b/tests/Datalist/Field/Type/LabelFieldTypeTest.php index 04df3cf3..f2a83390 100644 --- a/tests/Datalist/Field/Type/LabelFieldTypeTest.php +++ b/tests/Datalist/Field/Type/LabelFieldTypeTest.php @@ -11,13 +11,12 @@ use Leapt\CoreBundle\Datalist\Field\Type\LabelFieldType; use Leapt\CoreBundle\Datalist\Type\DatalistType; use Leapt\CoreBundle\Datalist\ViewContext; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; final class LabelFieldTypeTest extends WebTestCase { - /** - * @dataProvider buildViewContextProvider - */ + #[DataProvider('buildViewContextProvider')] public function testBuildViewContext(string $expectedValue, array $item, array $options = []): void { $fieldType = new LabelFieldType(); diff --git a/tests/Datalist/Field/Type/TextFieldTypeTest.php b/tests/Datalist/Field/Type/TextFieldTypeTest.php index 288a9ff3..d0dc6e4f 100644 --- a/tests/Datalist/Field/Type/TextFieldTypeTest.php +++ b/tests/Datalist/Field/Type/TextFieldTypeTest.php @@ -11,13 +11,12 @@ use Leapt\CoreBundle\Datalist\Field\Type\TextFieldType; use Leapt\CoreBundle\Datalist\Type\DatalistType; use Leapt\CoreBundle\Datalist\ViewContext; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class TextFieldTypeTest extends TestCase { - /** - * @dataProvider buildViewContextProvider - */ + #[DataProvider('buildViewContextProvider')] public function testBuildViewContext(string $expectedValue, array $item, array $options = []): void { $fieldType = new TextFieldType(); @@ -33,6 +32,6 @@ public function testBuildViewContext(string $expectedValue, array $item, array $ public static function buildViewContextProvider(): iterable { yield 'regular_text' => ['test', ['name' => 'test']]; - yield 'callback' => ['Here is the weight: 123', ['weight' => 123], ['callback' => fn (array $item): string => 'Here is the weight: ' . $item['weight']]]; + yield 'callback' => ['Here is the weight: 123', ['weight' => 123], ['callback' => fn(array $item): string => 'Here is the weight: ' . $item['weight']]]; } } diff --git a/tests/Datalist/Filter/Type/BooleanFilterTypeTest.php b/tests/Datalist/Filter/Type/BooleanFilterTypeTest.php index ea7fd897..66d38ff3 100644 --- a/tests/Datalist/Filter/Type/BooleanFilterTypeTest.php +++ b/tests/Datalist/Filter/Type/BooleanFilterTypeTest.php @@ -8,6 +8,7 @@ use Leapt\CoreBundle\Datalist\Datasource\ArrayDatasource; use Leapt\CoreBundle\Datalist\Filter\Type\BooleanFilterType; use Leapt\CoreBundle\Datalist\Type\DatalistType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; @@ -17,9 +18,7 @@ final class BooleanFilterTypeTest extends TestCase { - /** - * @dataProvider filterCasesProvider - */ + #[DataProvider('filterCasesProvider')] public function testFilter(string $property, bool|string $value, array $expectedResult): void { $datasource = new ArrayDatasource($this->getItems()); diff --git a/tests/Datalist/Filter/Type/ChoiceFilterTypeTest.php b/tests/Datalist/Filter/Type/ChoiceFilterTypeTest.php index abaecc45..374d23bf 100644 --- a/tests/Datalist/Filter/Type/ChoiceFilterTypeTest.php +++ b/tests/Datalist/Filter/Type/ChoiceFilterTypeTest.php @@ -8,6 +8,7 @@ use Leapt\CoreBundle\Datalist\Datasource\ArrayDatasource; use Leapt\CoreBundle\Datalist\Filter\Type\ChoiceFilterType; use Leapt\CoreBundle\Datalist\Type\DatalistType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; @@ -17,9 +18,7 @@ final class ChoiceFilterTypeTest extends TestCase { - /** - * @dataProvider filterCasesProvider - */ + #[DataProvider('filterCasesProvider')] public function testFilter(string|array|null $searchValue, bool $multiple, array $expectedResult): void { $datasource = new ArrayDatasource($this->getItems()); diff --git a/tests/Datalist/Filter/Type/EnumFilterTypeTest.php b/tests/Datalist/Filter/Type/EnumFilterTypeTest.php index a4fdd2b5..caa0b404 100644 --- a/tests/Datalist/Filter/Type/EnumFilterTypeTest.php +++ b/tests/Datalist/Filter/Type/EnumFilterTypeTest.php @@ -9,6 +9,7 @@ use Leapt\CoreBundle\Datalist\Filter\Type\EnumFilterType; use Leapt\CoreBundle\Datalist\Type\DatalistType; use Leapt\CoreBundle\Tests\Datalist\Filter\Type\Enums\Category; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; @@ -16,14 +17,9 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; -/** - * @requires PHP 8.1 - */ final class EnumFilterTypeTest extends TestCase { - /** - * @dataProvider filterCasesProvider - */ + #[DataProvider('filterCasesProvider')] public function testFilter(\BackedEnum|string|array|null $searchValue, bool $multiple, array $expectedResult): void { $datasource = new ArrayDatasource($this->getItems()); diff --git a/tests/Datalist/Filter/Type/IsNullFilterTypeTest.php b/tests/Datalist/Filter/Type/IsNullFilterTypeTest.php index 15f70b21..14e5e6e7 100644 --- a/tests/Datalist/Filter/Type/IsNullFilterTypeTest.php +++ b/tests/Datalist/Filter/Type/IsNullFilterTypeTest.php @@ -8,6 +8,7 @@ use Leapt\CoreBundle\Datalist\Datasource\ArrayDatasource; use Leapt\CoreBundle\Datalist\Filter\Type\IsNullFilterType; use Leapt\CoreBundle\Datalist\Type\DatalistType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; @@ -17,9 +18,7 @@ final class IsNullFilterTypeTest extends TestCase { - /** - * @dataProvider filterCasesProvider - */ + #[DataProvider('filterCasesProvider')] public function testFilter(?string $value, array $expectedResult): void { $datasource = new ArrayDatasource($this->getItems()); diff --git a/tests/Datalist/Filter/Type/SearchFilterTypeTest.php b/tests/Datalist/Filter/Type/SearchFilterTypeTest.php index 0a52d863..df5db8b3 100644 --- a/tests/Datalist/Filter/Type/SearchFilterTypeTest.php +++ b/tests/Datalist/Filter/Type/SearchFilterTypeTest.php @@ -8,6 +8,7 @@ use Leapt\CoreBundle\Datalist\Datasource\ArrayDatasource; use Leapt\CoreBundle\Datalist\Filter\Type\SearchFilterType; use Leapt\CoreBundle\Datalist\Type\DatalistType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; @@ -17,9 +18,7 @@ final class SearchFilterTypeTest extends TestCase { - /** - * @dataProvider filterCasesProvider - */ + #[DataProvider('filterCasesProvider')] public function testFilter(string|array $searchFields, string $searchValue, array $expectedResult): void { $datasource = new ArrayDatasource($this->getItems()); diff --git a/tests/Paginator/Fixtures/LoadPlayerData.php b/tests/Paginator/Fixtures/LoadPlayerData.php index 2746e751..7b4c761c 100644 --- a/tests/Paginator/Fixtures/LoadPlayerData.php +++ b/tests/Paginator/Fixtures/LoadPlayerData.php @@ -11,9 +11,7 @@ class LoadPlayerData extends AbstractFixture { - public function __construct(private int $limit) - { - } + public function __construct(private int $limit) {} public function load(ObjectManager $manager): void { diff --git a/tests/Twig/Extension/DateExtensionTest.php b/tests/Twig/Extension/DateExtensionTest.php index b1872492..29e77c5b 100644 --- a/tests/Twig/Extension/DateExtensionTest.php +++ b/tests/Twig/Extension/DateExtensionTest.php @@ -6,6 +6,7 @@ use Leapt\CoreBundle\Tests\Twig\Extension\Mocks\TranslatorMock; use Leapt\CoreBundle\Twig\Extension\DateExtension; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class DateExtensionTest extends TestCase @@ -24,9 +25,7 @@ public function testGetFilters(): void $this->assertSame('time_ago', $filters[0]->getName()); } - /** - * @dataProvider timeAgoData - */ + #[DataProvider('timeAgoData')] public function testTimeAgo(\DateTime|\DateTimeImmutable|string $ago, string $expected): void { $this->assertEquals($expected, $this->extension->timeAgo($ago, 'en')); diff --git a/tests/Twig/Extension/SiteExtensionTest.php b/tests/Twig/Extension/SiteExtensionTest.php index 56a860e8..8d151eb8 100644 --- a/tests/Twig/Extension/SiteExtensionTest.php +++ b/tests/Twig/Extension/SiteExtensionTest.php @@ -5,6 +5,7 @@ namespace Leapt\CoreBundle\Tests\Twig\Extension; use Leapt\CoreBundle\Twig\Extension\SiteExtension; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class SiteExtensionTest extends TestCase @@ -16,9 +17,7 @@ protected function setUp(): void $this->siteExtension = new SiteExtension(); } - /** - * @dataProvider provideFalseTestCases - */ + #[DataProvider('provideFalseTestCases')] public function testFalseTest(mixed $testData, bool $expectedResult): void { self::assertSame($expectedResult, $this->siteExtension->getTests()[0]->getCallable()($testData)); diff --git a/tests/Validator/PasswordStrengthValidatorTest.php b/tests/Validator/PasswordStrengthValidatorTest.php index c63d6a45..f9afaca0 100644 --- a/tests/Validator/PasswordStrengthValidatorTest.php +++ b/tests/Validator/PasswordStrengthValidatorTest.php @@ -6,6 +6,7 @@ use Leapt\CoreBundle\Validator\Constraints\PasswordStrength; use Leapt\CoreBundle\Validator\Constraints\PasswordStrengthValidator; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; final class PasswordStrengthValidatorTest extends ConstraintValidatorTestCase @@ -24,9 +25,7 @@ public function testEmptyStringIsValid(): void $this->assertNoViolation(); } - /** - * @dataProvider getValidPasswords - */ + #[DataProvider('getValidPasswords')] public function testValidPassword(string $password): void { $this->validator->validate($password, new PasswordStrength(['score' => 50, 'min' => 5, 'max' => 255])); @@ -46,9 +45,7 @@ public static function getValidPasswords(): iterable yield ['My password is f*cking awesome']; } - /** - * @dataProvider getInvalidPasswords - */ + #[DataProvider('getInvalidPasswords')] public function testInvalidPasswords(string $password): void { $constraint = new PasswordStrength([ diff --git a/tests/Validator/SlugValidatorTest.php b/tests/Validator/SlugValidatorTest.php index f4b5191c..fbb03279 100644 --- a/tests/Validator/SlugValidatorTest.php +++ b/tests/Validator/SlugValidatorTest.php @@ -6,6 +6,7 @@ use Composer\InstalledVersions; use Leapt\CoreBundle\Validator\Constraints\Slug; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\Validator\Constraints\RegexValidator; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; @@ -25,9 +26,7 @@ public function testEmptyStringIsValid(): void $this->assertNoViolation(); } - /** - * @dataProvider getValidSlugs - */ + #[DataProvider('getValidSlugs')] public function testValidSlug(string $slug): void { $this->validator->validate($slug, new Slug()); @@ -42,9 +41,7 @@ public static function getValidSlugs(): iterable yield ['valid-123-slug']; } - /** - * @dataProvider getInvalidSlugs - */ + #[DataProvider('getInvalidSlugs')] public function testInvalidSlugs(string $slug): void { $validatorVersion = InstalledVersions::getVersion('symfony/validator'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a075e1e8..cedd5896 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,3 +3,5 @@ declare(strict_types=1); require_once __DIR__ . '/../vendor/autoload.php'; + +set_exception_handler([new Symfony\Component\ErrorHandler\ErrorHandler(), 'handleException']);