diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index c352bc5..65df556 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -10,6 +10,35 @@ on: workflow_dispatch: ~ jobs: + phpstan: + runs-on: ubuntu-latest + timeout-minutes: 5 + env: + APP_DEBUG: '1' # https://github.com/phpstan/phpstan-symfony/issues/37 + SYMFONY_REQUIRE: '^7.0' + SYMFONY_PHPUNIT_VERSION: '9.5' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + tools: flex + coverage: none # disable xdebug, pcov + ini-values: memory_limit=-1 + + - name: Update project dependencies + run: | + composer update --no-interaction --no-progress --ansi + composer require --dev "phpstan/phpstan:^1.10" "phpstan/phpstan-strict-rules:^1.5" "phpstan/phpstan-phpunit: ^1.3" "phpstan/phpstan-deprecation-rules:^1.1" + + - name: Run PHPStan analysis + run: | + ./vendor/bin/phpstan --version + ./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi + phpunit: runs-on: ubuntu-latest strategy: @@ -82,30 +111,26 @@ jobs: code-coverage: name: Code Coverage runs-on: ubuntu-latest + timeout-minutes: 5 + env: + APP_DEBUG: '1' # https://github.com/phpstan/phpstan-symfony/issues/37 + SYMFONY_REQUIRE: '^5.0' + SYMFONY_PHPUNIT_VERSION: '9.5' steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: '7.4' + tools: flex coverage: xdebug + ini-values: memory_limit=-1 - - 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: Install PHP dependencies - run: composer install --no-interaction + - name: Update project dependencies + run: | + composer update --no-interaction --no-progress --ansi - name: Run code coverage run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover diff --git a/Tests/Form/Recaptcha3TypeTest.php b/Tests/Form/Recaptcha3TypeTest.php index 8754896..51ad653 100644 --- a/Tests/Form/Recaptcha3TypeTest.php +++ b/Tests/Form/Recaptcha3TypeTest.php @@ -27,14 +27,14 @@ public function testDefaultOptions() $form = $this->factory->create(Recaptcha3Type::class); $form->setData($data); - $this->assertTrue($form->isSynchronized()); - $this->assertEquals($data, $form->getData()); + self::assertTrue($form->isSynchronized()); + self::assertEquals($data, $form->getData()); $view = $form->createView(); - $this->assertSame(self::SITEKEY, $view->vars['site_key']); - $this->assertSame(self::HOST, $view->vars['host']); - $this->assertSame('homepage', $view->vars['action_name']); - $this->assertSame('', $view->vars['script_nonce_csp']); - $this->assertTrue($view->vars['enabled']); + self::assertSame(self::SITEKEY, $view->vars['site_key']); + self::assertSame(self::HOST, $view->vars['host']); + self::assertSame('homepage', $view->vars['action_name']); + self::assertSame('', $view->vars['script_nonce_csp']); + self::assertTrue($view->vars['enabled']); } } diff --git a/Tests/Services/HostProviderTest.php b/Tests/Services/HostProviderTest.php index 5e70a65..9ca43a3 100644 --- a/Tests/Services/HostProviderTest.php +++ b/Tests/Services/HostProviderTest.php @@ -3,7 +3,6 @@ namespace Services; use Karser\Recaptcha3Bundle\Services\HostProvider; -use Karser\Recaptcha3Bundle\Services\HostProviderInterface; use PHPUnit\Framework\TestCase; class HostProviderTest extends TestCase @@ -12,7 +11,7 @@ class HostProviderTest extends TestCase public function test__construct() { $hostProvider = new HostProvider('www.a-domain.tld'); - self::assertInstanceOf(HostProviderInterface::class, $hostProvider); + self::assertSame('www.a-domain.tld', $hostProvider->getHost()); } public function testGetHost() diff --git a/Tests/TestKernel.php b/Tests/TestKernel.php index ab37c13..a1c701c 100644 --- a/Tests/TestKernel.php +++ b/Tests/TestKernel.php @@ -22,7 +22,7 @@ public function setConfigurationFilename($filename) /** * {@inheritdoc} */ - public function registerBundles(): array + public function registerBundles(): iterable { return [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), diff --git a/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php b/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php index 140a76c..7e9d337 100644 --- a/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php +++ b/Tests/Validator/Constraints/Recaptcha3ValidatorTest.php @@ -105,7 +105,7 @@ public function testLastResponse() $this->recaptcha->nextSuccess = true; $validator = new Recaptcha3Validator($this->recaptcha, $enabled = true, $this->resolver); - self::assertNull($this->validator->getLastResponse()); + self::assertNull($validator->getLastResponse()); $validator->validate('test', new Recaptcha3()); self::assertNotNull($validator->getLastResponse()); diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..4374b9b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,24 @@ +includes: + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon + +parameters: + level: 5 + reportUnmatchedIgnoredErrors: false + checkMissingIterableValueType: false + checkGenericClassInNonGenericObjectType: false + inferPrivatePropertyTypeFromConstructor: true + paths: + - %currentWorkingDirectory% + ignoreErrors: + - '#Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder constructor invoked with 0 parameters, 1-3 required#' + - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)#' + - '#Call to function method_exists\(\) with .*?TreeBuilder.*? and .*?getRootNode.*? will always evaluate to true#' + - '#Comparison operation "<" between 70006 and 50200 is always false#' + - '#Comparison operation ">=" between 7 and 6 is always true#' + - '#Else branch is unreachable because ternary operator condition is always true#' + + excludePaths: + - %currentWorkingDirectory%/.github/* + - %currentWorkingDirectory%/.idea/* + - %currentWorkingDirectory%/vendor/*