Skip to content

Commit

Permalink
added phpstan typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
karser committed Apr 28, 2024
1 parent 9c3adb3 commit d388760
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 28 deletions.
59 changes: 42 additions & 17 deletions .github/workflows/code_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Tests/Form/Recaptcha3TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
3 changes: 1 addition & 2 deletions Tests/Services/HostProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Services;

use Karser\Recaptcha3Bundle\Services\HostProvider;
use Karser\Recaptcha3Bundle\Services\HostProviderInterface;
use PHPUnit\Framework\TestCase;

class HostProviderTest extends TestCase
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setConfigurationFilename($filename)
/**
* {@inheritdoc}
*/
public function registerBundles(): array
public function registerBundles(): iterable
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Validator/Constraints/Recaptcha3ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
24 changes: 24 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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/*

0 comments on commit d388760

Please sign in to comment.