Skip to content

Commit

Permalink
feature #4 Allow Symfony 7 (sstok)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 1.2-dev branch.

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets | 
| License       | MIT



Commits
-------

d1d45e2 Allow Symfony 7
a520dfc -
  • Loading branch information
sstok authored Oct 28, 2023
1 parent 5f1bf03 commit 0dce962
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 84 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
| Q | A
| ------------- | ---
| Branch? | main
| Bug fix? | yes/no
| New feature? | yes/no
| BC breaks? | yes/no
Expand Down
196 changes: 132 additions & 64 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Full CI process
name: 'CI'

on:
push:
branches:
Expand All @@ -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 [email protected]
git config --global user.name Sebastiaan Stok
git config --global user.email [email protected]
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
14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -42,7 +40,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "1.2-dev"
}
},
"config": {
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
4 changes: 1 addition & 3 deletions src/Bundle/RollerworksPasswordCommonListBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

use Symfony\Component\HttpKernel\Bundle\Bundle;

class RollerworksPasswordCommonListBundle extends Bundle
{
}
class RollerworksPasswordCommonListBundle extends Bundle {}
1 change: 1 addition & 0 deletions src/Constraints/NotInPasswordCommonList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @Annotation
*
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/NotInPasswordCommonListValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
12 changes: 8 additions & 4 deletions tests/Constraints/NotInPasswordCommonListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotInPasswordCommonListValidator>
*/
final class NotInPasswordCommonListTest extends ConstraintValidatorTestCase
{
protected function createValidator(): NotInPasswordCommonListValidator
protected function createValidator(): ConstraintValidatorInterface
{
return new NotInPasswordCommonListValidator();
}
Expand All @@ -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 '';
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 0dce962

Please sign in to comment.