From 7b756ab21a13431b68e8a26715183f9d3ec02561 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Fri, 1 May 2026 10:34:34 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20message=20customisation=20?= =?UTF-8?q?for=20sf=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yaml | 32 +++++++++---------- composer.json | 3 ++ phpstan-baseline.neon | 0 phpstan.neon | 2 -- src/DependencyInjection/Configuration.php | 2 +- src/Validator/Constraints/Recaptcha2.php | 16 ++++++++++ .../BeelabRecaptcha2ExtensionTest.php | 8 ++--- 7 files changed, 39 insertions(+), 24 deletions(-) delete mode 100644 phpstan-baseline.neon diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index af86422..bf88e54 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,9 +12,9 @@ jobs: name: PHPStan steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: PHPStan - uses: docker://oskarstark/phpstan-ga:1.8.0 + uses: docker://oskarstark/phpstan-ga env: REQUIRE_DEV: true with: @@ -24,7 +24,7 @@ jobs: name: PHP-CS-Fixer steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Fix CS uses: docker://oskarstark/php-cs-fixer-ga with: @@ -37,7 +37,8 @@ jobs: include: - description: 'Symfony 6.4' php: '8.1' - composer_option: '--prefer-lowest' + symfony: 6.4.* + dependencies: lowest max_deprecations: 0 - description: 'Symfony 6.4' php: '8.2' @@ -58,24 +59,21 @@ jobs: name: PHP ${{ matrix.php }} tests (${{ matrix.description }}) steps: - name: Checkout - uses: actions/checkout@v4 - - name: Cache - uses: actions/cache@v4 - with: - path: ~/.composer/cache/files - key: ${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }} + uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - - run: | - composer config minimum-stability dev - composer config prefer-stable true + tools: flex + - name: Allow dev dependencies + run: composer config minimum-stability dev && composer config prefer-stable true if: contains(matrix.symfony, '@dev') - - run: | - sed -ri 's/"symfony\/(config|dependency-injection|form|http-kernel|validator)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; - if: matrix.symfony - - run: composer update --no-interaction --no-progress --ansi ${{ matrix.composer_option }} + - name: Install dependencies + uses: ramsey/composer-install@v3 + with: + dependency-versions: ${{ matrix.dependencies }} + env: + SYMFONY_REQUIRE: ${{ matrix.symfony }} - name: Run tests run: vendor/bin/phpunit --colors=always --coverage-clover=clover.xml env: diff --git a/composer.json b/composer.json index 1a37065..73712c9 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,9 @@ "symfony/http-client-contracts": "^3.5", "symfony/phpunit-bridge": "^7.4" }, + "conflict": { + "google/recaptcha": "1.5.0" + }, "suggest": { "symfony/twig-bundle": "To render widget. Minimum supported Twig version is 2.4" }, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index e69de29..0000000 diff --git a/phpstan.neon b/phpstan.neon index 9365c9d..9108033 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,5 +4,3 @@ parameters: - config - src - tests -includes: - - phpstan-baseline.neon diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index dc27afd..714e24e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,7 +11,7 @@ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('beelab_recaptcha2'); $rootNode = $treeBuilder->getRootNode(); - $rootNode // @phpstan-ignore-line method.notFound + $rootNode ->children() ->enumNode('request_method') ->values(['curl_post', 'post', 'http_client']) diff --git a/src/Validator/Constraints/Recaptcha2.php b/src/Validator/Constraints/Recaptcha2.php index 9e3870b..4fd821a 100644 --- a/src/Validator/Constraints/Recaptcha2.php +++ b/src/Validator/Constraints/Recaptcha2.php @@ -17,6 +17,22 @@ final class Recaptcha2 extends Constraint public string $message = 'Invalid ReCaptcha.'; + public function __construct( + mixed $options = null, + ?array $groups = null, + mixed $payload = null, + ?string $message = null, + ) { + if (null !== $message) { + $this->message = $message; + } + if (\is_array($options)) { + trigger_deprecation('beelab/recaptcha2-bundle', '2.13', 'Passing options as an array is deprecated. Pass options as named arguments instead.'); + $options['message'] = $this->message; + } + parent::__construct($options, $groups, $payload); + } + public function validatedBy(): string { return 'recaptcha2'; diff --git a/tests/DependencyInjection/BeelabRecaptcha2ExtensionTest.php b/tests/DependencyInjection/BeelabRecaptcha2ExtensionTest.php index c48360b..671ec2e 100644 --- a/tests/DependencyInjection/BeelabRecaptcha2ExtensionTest.php +++ b/tests/DependencyInjection/BeelabRecaptcha2ExtensionTest.php @@ -14,9 +14,9 @@ final class BeelabRecaptcha2ExtensionTest extends TestCase { public function testLoadSetParameters(): void { - /** @var ContainerBuilder|\PHPUnit\Framework\MockObject\MockObject $container */ + /** @var ContainerBuilder&\PHPUnit\Framework\MockObject\MockObject $container */ $container = $this->createMock(ContainerBuilder::class); - /** @var ParameterBag|\PHPUnit\Framework\MockObject\MockObject $parameterBag */ + /** @var ParameterBag&\PHPUnit\Framework\MockObject\MockObject $parameterBag */ $parameterBag = $this->createMock(ParameterBag::class); $parameterBag->method('add'); @@ -35,9 +35,9 @@ public function testLoadSetParameters(): void public function testLoadSetParametersPost(): void { - /** @var ContainerBuilder|\PHPUnit\Framework\MockObject\MockObject $container */ + /** @var ContainerBuilder&\PHPUnit\Framework\MockObject\MockObject $container */ $container = $this->createMock(ContainerBuilder::class); - /** @var ParameterBag|\PHPUnit\Framework\MockObject\MockObject $parameterBag */ + /** @var ParameterBag&\PHPUnit\Framework\MockObject\MockObject $parameterBag */ $parameterBag = $this->createMock(ParameterBag::class); $parameterBag->method('add');