diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index afe093a..da9f029 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,5 @@ | Q | A | ------------- | --- -| Branch? | main | Bug fix? | yes/no | New feature? | yes/no | BC breaks? | yes/no diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0c0e2ae..464be35 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,5 @@ -name: Full CI process +name: 'CI' + on: push: branches: @@ -8,92 +9,159 @@ on: - main jobs: - test: - name: PHP ${{ matrix.PHP_VERSION }} - runs-on: ubuntu-18.04 + cs-fixer: + name: 'PHP CS Fixer' + + runs-on: 'ubuntu-latest' + strategy: - fail-fast: false matrix: - include: - - PHP_VERSION: '7.4' - SYMFONY_REQUIRE: '^5.0' - - PHP_VERSION: '7.4' - SYMFONY_REQUIRE: '^5.2' - - PHP_VERSION: '8.0' - - PHP_VERSION: '8.0' - SYMFONY_REQUIRE: '^6.0' + php-version: + - '8.2' steps: - # —— Setup Github actions 🐙 ————————————————————————————————————————————— - # https://github.com/actions/checkout (official) - - name: Checkout - uses: actions/checkout@v2 + name: 'Check out' + uses: 'actions/checkout@v2' - # https://github.com/shivammathur/setup-php (community) - - name: Setup PHP, extensions and composer with shivammathur/setup-php - uses: shivammathur/setup-php@v2 + name: 'Set up PHP' + uses: 'shivammathur/setup-php@v2' with: - php-version: ${{ matrix.PHP_VERSION }} - extensions: mbstring, ctype, iconv, filter, json - coverage: none - env: - update: true + php-version: '${{ matrix.php-version }}' + coverage: 'none' - # —— Composer 🧙‍️ ————————————————————————————————————————————————————————— - - name: Install Composer dependencies - env: - SYMFONY_REQUIRE: ${{ matrix.SYMFONY_REQUIRE }} - SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE: 1 - run: | - git config --global author.name Sebastiaan Stok - git config --global author.email s.stok@rollerscapes.net - git config --global user.name Sebastiaan Stok - git config --global user.email s.stok@rollerscapes.net + name: 'Get Composer cache directory' + id: 'composer-cache' + run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"' - rm -f composer.lock - composer global config --no-plugins allow-plugins.symfony/flex true - composer config --no-plugins allow-plugins.symfony/flex true - composer global require symfony/flex - composer install --no-progress --no-interaction --no-suggest --optimize-autoloader --ansi + - + name: 'Cache dependencies' + uses: 'actions/cache@v2' + with: + path: '${{ steps.composer-cache.outputs.cache-dir }}' + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: 'php-${{ matrix.php-version }}-composer-locked-' - ## —— Tests ✅ ——————————————————————————————————————————————————————————— - - name: Run Tests - run: | - make test - lint: - name: PHP-QA - runs-on: ubuntu-latest + name: 'Install dependencies' + run: 'composer update --no-progress --prefer-stable' + + - + name: 'Check the code style' + run: 'make cs-full' + + phpstan: + name: 'PhpStan' + + runs-on: 'ubuntu-latest' + strategy: - fail-fast: false + matrix: + php-version: + - '8.2' + steps: - - name: Checkout - uses: actions/checkout@v2 + name: 'Check out' + uses: 'actions/checkout@v2' + + - + name: 'Set up PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + coverage: 'none' + + - + name: 'Get Composer cache directory' + id: 'composer-cache' + run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"' - # https://github.com/shivammathur/setup-php (community) - - name: Setup PHP, extensions and composer with shivammathur/setup-php - uses: shivammathur/setup-php@v2 + name: 'Cache dependencies' + uses: 'actions/cache@v2' with: - php-version: '7.4' - extensions: mbstring, ctype, iconv, filter, json - coverage: none + path: '${{ steps.composer-cache.outputs.cache-dir }}' + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: 'php-${{ matrix.php-version }}-composer-locked-' + + - + name: 'Install dependencies' + run: 'composer update --no-progress --prefer-stable' - # —— Composer 🧙‍️ ————————————————————————————————————————————————————————— - - name: Install Composer dependencies + name: 'Run PhpStan' + run: 'vendor/bin/phpstan analyze --no-progress' + + tests: + name: 'PHPUnit' + + runs-on: 'ubuntu-latest' + + strategy: + matrix: + include: + - + php-version: '8.0' + composer-options: '--prefer-stable' + symfony-version: '5.4' + + - + php-version: '8.0' + composer-options: '--prefer-stable' + symfony-version: '6.0' + - + php-version: '8.2' + composer-options: '--prefer-stable' + symfony-version: '^6.4' + + - + php-version: '8.2' + composer-options: '--prefer-stable' + symfony-version: '^7.0' + + steps: + - + name: 'Check out' + uses: 'actions/checkout@v2' + + - + name: 'Set up PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + coverage: 'none' + + - + name: 'Get Composer cache directory' + id: 'composer-cache' + run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"' + + - + name: 'Cache dependencies' + uses: 'actions/cache@v2' + with: + path: '${{ steps.composer-cache.outputs.cache-dir }}' + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: 'php-${{ matrix.php-version }}-composer-locked-' + + - + name: 'Install dependencies' + env: + COMPOSER_OPTIONS: '${{ matrix.composer-options }}' + SYMFONY_REQUIRE: '${{ matrix.symfony-version }}' run: | - rm -f composer.lock composer global config --no-plugins allow-plugins.symfony/flex true - composer config --no-plugins allow-plugins.symfony/flex true - composer global require symfony/flex - composer install --no-progress --no-interaction --no-suggest --optimize-autoloader --ansi + composer global require --no-progress --no-scripts --no-plugins symfony/flex + composer update --no-progress $COMPOSER_OPTIONS + + - + name: 'Install PHPUnit' + run: 'vendor/bin/simple-phpunit install' - - name: Run PHP-QA + name: 'Run tests' run: | - make lint + vendor/bin/simple-phpunit diff --git a/composer.json b/composer.json index b28f8c0..14cef28 100644 --- a/composer.json +++ b/composer.json @@ -17,16 +17,14 @@ "require": { "php": ">=7.4", "symfony/polyfill-mbstring": "^1.5.0", - "symfony/validator": "^5.0 || ^6.0" + "symfony/validator": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "phpspec/prophecy": "^1.10.3", - "phpspec/prophecy-phpunit": "^2.0", - "phpstan/phpstan": "^0.12.99", - "phpstan/phpstan-phpunit": "^0.12.22", + "phpstan/phpstan": "^1.10.39", + "phpstan/phpstan-phpunit": "1.3.15", "phpunit/phpunit": "^9.5", - "symfony/framework-bundle": "^5.3 || ^6.0", - "symfony/phpunit-bridge": "^5.3 || ^6.0" + "symfony/framework-bundle": "^5.3 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^5.3 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { @@ -42,7 +40,7 @@ }, "extra": { "branch-alias": { - "dev-main": "1.1-dev" + "dev-main": "1.2-dev" } }, "config": { diff --git a/phpstan.neon b/phpstan.neon index ad20f46..4737151 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,6 +9,3 @@ parameters: - ./src/Resources ignoreErrors: - #- '#__construct\(\) does not call parent constructor from .+#' - #- '#Access to an undefined property Symfony\\Component\\Validator\\Constraint\:\:#' - #- "#Casting to string something that's already string#" diff --git a/src/Bundle/RollerworksPasswordCommonListBundle.php b/src/Bundle/RollerworksPasswordCommonListBundle.php index 69cc808..9d13333 100644 --- a/src/Bundle/RollerworksPasswordCommonListBundle.php +++ b/src/Bundle/RollerworksPasswordCommonListBundle.php @@ -13,6 +13,4 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -class RollerworksPasswordCommonListBundle extends Bundle -{ -} +class RollerworksPasswordCommonListBundle extends Bundle {} diff --git a/src/Constraints/NotInPasswordCommonList.php b/src/Constraints/NotInPasswordCommonList.php index 6f437f2..dfc71ae 100644 --- a/src/Constraints/NotInPasswordCommonList.php +++ b/src/Constraints/NotInPasswordCommonList.php @@ -17,6 +17,7 @@ /** * @Annotation + * * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) */ #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] diff --git a/src/Constraints/NotInPasswordCommonListValidator.php b/src/Constraints/NotInPasswordCommonListValidator.php index 0de31a7..cb793c1 100644 --- a/src/Constraints/NotInPasswordCommonListValidator.php +++ b/src/Constraints/NotInPasswordCommonListValidator.php @@ -30,7 +30,7 @@ public function validate($value, Constraint $constraint): void return; } - if (! is_scalar($value) && ! (\is_object($value) && method_exists($value, '__toString'))) { + if (! \is_scalar($value) && ! (\is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedValueException($value, 'string'); } diff --git a/tests/Constraints/NotInPasswordCommonListTest.php b/tests/Constraints/NotInPasswordCommonListTest.php index 5d33d7b..555eda4 100644 --- a/tests/Constraints/NotInPasswordCommonListTest.php +++ b/tests/Constraints/NotInPasswordCommonListTest.php @@ -15,15 +15,17 @@ use Rollerworks\Component\PasswordCommonList\Constraints\NotInPasswordCommonList; use Rollerworks\Component\PasswordCommonList\Constraints\NotInPasswordCommonListValidator; -use Stringable; +use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; /** * @internal + * + * @template-extends ConstraintValidatorTestCase */ final class NotInPasswordCommonListTest extends ConstraintValidatorTestCase { - protected function createValidator(): NotInPasswordCommonListValidator + protected function createValidator(): ConstraintValidatorInterface { return new NotInPasswordCommonListValidator(); } @@ -38,7 +40,7 @@ public function it_ignores_empty_values(): void $this->assertNoViolation(); $this->validator->validate( - new class() implements Stringable { + new class() implements \Stringable { public function __toString(): string { return ''; @@ -61,6 +63,7 @@ public function no_violation_for_unlisted_password(): void /** * @test + * * @dataProvider provide_unsafe_passwords */ public function it_raises_a_violation_for_common_used_password_as_string(string $password): void @@ -75,11 +78,12 @@ public function it_raises_a_violation_for_common_used_password_as_string(string /** * @test + * * @dataProvider provide_unsafe_passwords */ public function it_raises_a_violation_for_common_used_password_as_stringable(string $password): void { - $value = new class($password) implements Stringable { + $value = new class($password) implements \Stringable { private string $password; public function __construct(string $password)