diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index adc132a..c352bc5 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -14,61 +14,68 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] - symfony: ['^3.4', '^4.0', '^5.0'] + php: ['7.1', '7.2', '7.4', '8.0', '8.1', '8.2', '8.3'] + symfony: ['^3.4', '^4.0', '^5.0', '^6.0', '^7.0'] exclude: + - symfony: ^3.4 + php: 8.1 + - symfony: ^3.4 + php: 8.2 + - symfony: ^3.4 + php: 8.3 + - symfony: ^4.0 + php: 8.1 + - symfony: ^4.0 + php: 8.2 + - symfony: ^4.0 + php: 8.3 - symfony: ^5.0 php: 7.1 - include: - symfony: ^6.0 - php: 8.0 + php: 7.1 - symfony: ^6.0 - php: 8.1 + php: 7.2 - symfony: ^6.0 - php: 8.2 + php: 7.4 + - symfony: ^6.0 + php: 8.3 + - symfony: ^7.0 + php: 7.1 + - symfony: ^7.0 + php: 7.2 + - symfony: ^7.0 + php: 7.4 + - symfony: ^7.0 + php: 8.0 + - symfony: ^7.0 + php: 8.1 fail-fast: false name: PHPUnit (PHP ${{ matrix.php }}) (Symfony ${{ matrix.symfony }}) steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + tools: flex coverage: none # disable xdebug, pcov - - name: Get Composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache Composer - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php-${{ matrix.php }}-composer- + - name: Validate composer.json + run: composer validate --ansi --strict - - name: Restrict Symfony version - if: matrix.symfony != '' - run: | - composer global require --no-progress --no-scripts --no-plugins "symfony/flex" - composer global config --no-plugins allow-plugins.symfony/flex true - composer config extra.symfony.require "${{ matrix.symfony }}" + - name: Install PHP dependencies + uses: ramsey/composer-install@v2 + env: + SYMFONY_REQUIRE: ${{ matrix.symfony }} # remove this after support for symfony 3 is dropped - name: Remove PhpUnit 10 support for old Symfony Versions if: matrix.symfony == '^3.4' || matrix.symfony == '^4.0' run: composer require --no-update "phpunit/phpunit:^7|^8|^9" - - name: Install PHP dependencies - run: composer install --no-interaction - - - name: Validate composer.json - run: composer validate --ansi --strict - - name: Run tests run: vendor/bin/phpunit diff --git a/README.md b/README.md index 7dac02c..fe3fba9 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Configuration without symfony/flex: ### 1. Register the bundle -**Symfony 4/5/6 Version :** +**Symfony 4/5/6/7 Version :** Register bundle into `config/bundles.php`: ```php return [ diff --git a/Tests/FunctionalTest.php b/Tests/FunctionalTest.php index 3edb889..e15cd90 100644 --- a/Tests/FunctionalTest.php +++ b/Tests/FunctionalTest.php @@ -38,7 +38,11 @@ public function testFormJavascriptPresent_ifEnabled() $view = $template->render(['form' => $form->createView()]); //THEN - self::assertStringContainsString('', $view); + if (TestKernel::VERSION_ID >= 60400) { + self::assertStringContainsString('', $view); + } else { + self::assertStringContainsString('', $view); + } self::assertStringContainsString('', $view); self::assertStringContainsString('var recaptchaCallback_form_captcha', $view); self::assertStringContainsString("document.getElementById('form_captcha').value = token;", $view); @@ -55,7 +59,11 @@ public function testHyphenConvertedToUnderscore() $view = $template->render(['form' => $form->createView()]); //THEN - self::assertStringContainsString('', $view); + if (TestKernel::VERSION_ID >= 60400) { + self::assertStringContainsString('', $view); + } else { + self::assertStringContainsString('', $view); + } self::assertStringContainsString('', $view); self::assertStringContainsString('var recaptchaCallback_form_capt_cha', $view); self::assertStringContainsString("document.getElementById('form_capt-cha').value = token;", $view); @@ -72,7 +80,11 @@ public function testFormJavascriptAbsent_ifDisabled() $view = $template->render(['form' => $form->createView()]); //THEN - self::assertStringContainsString('', $view); + if (TestKernel::VERSION_ID >= 60400) { + self::assertStringContainsString('', $view); + } else { + self::assertStringContainsString('', $view); + } self::assertStringNotContainsString('', $view); self::assertStringNotContainsString("document.getElementById('form_captcha').value = token;", $view); } @@ -193,7 +205,11 @@ public function testFormJavascriptNoncePresent_ifSet() $view = $template->render(['form' => $form->createView()]); //THEN - self::assertStringContainsString('', $view); + if (TestKernel::VERSION_ID >= 60400) { + self::assertStringContainsString('', $view); + } else { + self::assertStringContainsString('', $view); + } self::assertStringContainsString('', $view); self::assertStringContainsString('var recaptchaCallback_form_captcha', $view); diff --git a/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php b/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php index 2f96554..140a76c 100644 --- a/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php +++ b/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php @@ -8,6 +8,7 @@ use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3Validator; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; @@ -20,11 +21,12 @@ class Recaptcha3ValidatorTest extends ConstraintValidatorTestCase public function setUp(): void { - $this->resolver = $this->getMockBuilder(IpResolverInterface::class)->getMock(); + $this->resolver = $this->createMock(IpResolverInterface::class); + parent::setUp(); } - protected function createValidator() + protected function createValidator(): ConstraintValidatorInterface { $this->recaptcha = new RecaptchaMock(); return new Recaptcha3Validator($this->recaptcha, $enabled = true, $this->resolver); diff --git a/Tests/fixtures/config/symfony6.yml b/Tests/fixtures/config/symfony6.yml index bef2769..db60068 100644 --- a/Tests/fixtures/config/symfony6.yml +++ b/Tests/fixtures/config/symfony6.yml @@ -1,3 +1,4 @@ framework: + http_method_override: false session: storage_factory_id: session.storage.factory.mock_file diff --git a/Validator/Constraints/Recaptcha3.php b/Validator/Constraints/Recaptcha3.php index 2444159..25c82ae 100644 --- a/Validator/Constraints/Recaptcha3.php +++ b/Validator/Constraints/Recaptcha3.php @@ -13,10 +13,12 @@ final class Recaptcha3 extends Constraint { const INVALID_FORMAT_ERROR = '7147ffdb-0af4-4f7a-bd5e-e9dcfa6d7a2d'; - protected static $errorNames = [ + protected const ERROR_NAMES = [ self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR', ]; + protected static $errorNames = self::ERROR_NAMES; + public $message = 'Your computer or network may be sending automated queries'; public $messageMissingValue = 'The captcha value is missing'; diff --git a/composer.json b/composer.json index 8b00187..00c9ccf 100644 --- a/composer.json +++ b/composer.json @@ -37,17 +37,17 @@ "require": { "php": ">=7.1", "google/recaptcha": "^1.2", - "symfony/form": "^3.4|^4.0|^5.0|^6.0", - "symfony/framework-bundle": "^3.4.26|^4.2.7|^5.0|^6.0", - "symfony/expression-language": "^3.4|^4.0|^5.0|^6.0", - "symfony/yaml": "^3.4|^4.0|^5.0|^6.0", - "symfony/validator": "^3.4|^4.0|^5.0|^6.0", - "symfony/twig-bundle": "^3.4|^4.0|^5.0|^6.0", + "symfony/form": "^3.4|^4.0|^5.0|^6.0|^7.0", + "symfony/framework-bundle": "^3.4.26|^4.2.7|^5.0|^6.0|^7.0", + "symfony/expression-language": "^3.4|^4.0|^5.0|^6.0|^7.0", + "symfony/yaml": "^3.4|^4.0|^5.0|^6.0|^7.0", + "symfony/validator": "^3.4|^4.0|^5.0|^6.0|^7.0", + "symfony/twig-bundle": "^3.4|^4.0|^5.0|^6.0|^7.0", "twig/twig": "^2.9|^3.0" }, "require-dev": { "phpunit/phpunit": "^7|^8|^9|^10", - "symfony/http-client": "^4.3|^5.0|^6.0" + "symfony/http-client": "^4.3|^5.0|^6.0|^7.0" }, "autoload": { "psr-4": {