diff --git a/.gitattributes b/.gitattributes
index 5ff8fbb..93aa015 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,14 +1,14 @@
-* text=auto
-
# Always use LF
core.autocrlf=lf
-.editorconfig
+.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
-.php_cs export-ignore
-.scrutinizer.yml export-ignore
-.travis.yml export-ignore
.github export-ignore
+.php-cs-fixer.dist.php export-ignore
+CODE_OF_CONDUCT.md export-ignore
+Makefile export-ignore
phpunit.xml.dist export-ignore
-/tests export-ignore
+phpstan.neon export-ignore
+phpstan-baseline.neon export-ignore
+tests/ export-ignore
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 74456ee..861ea29 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,149 @@ on:
- main
jobs:
- test:
- name: PHP ${{ matrix.PHP_VERSION }}
- runs-on: ubuntu-latest
+ cs-fixer:
+ name: 'PHP CS Fixer'
+
+ runs-on: 'ubuntu-latest'
+
strategy:
- fail-fast: false
matrix:
- include:
- - PHP_VERSION: '7.1'
- SYMFONY_REQUIRE: '^3.4'
- - PHP_VERSION: '7.2'
- SYMFONY_REQUIRE: '^4.4'
- - PHP_VERSION: '7.3'
- SYMFONY_REQUIRE: '^5.0'
- - PHP_VERSION: '7.4'
- SYMFONY_REQUIRE: '^5.2'
- - PHP_VERSION: '8.0'
- SYMFONY_REQUIRE: '^5.3'
- - 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@v4'
- # 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, bcmath, 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
- SYMFONY_PHPUNIT_VERSION: '7.5.6'
- 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 "cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'
+
+ -
+ name: 'Cache dependencies'
+ uses: 'actions/cache@v3'
+ 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-'
- rm -f composer.lock
- composer install --no-progress --no-interaction --optimize-autoloader --ansi
+ -
+ name: 'Install dependencies'
+ run: 'composer install --no-progress'
- ## —— Tests ✅ ———————————————————————————————————————————————————————————
-
- name: Run Tests
- run: |
- make test
- lint:
- name: PHP-QA
- runs-on: ubuntu-latest
+ name: 'Check the code style'
+ run: 'make cs'
+
+ 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@v4'
- # 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: '7.4'
- extensions: mbstring, ctype, iconv, bcmath, filter, json
- coverage: none
+ php-version: '${{ matrix.php-version }}'
+ coverage: 'none'
- # —— Composer 🧙️ —————————————————————————————————————————————————————————
-
- name: Install Composer dependencies
- run: |
- rm -f composer.lock
- composer install --no-progress --no-interaction --no-suggest --optimize-autoloader --ansi
+ name: 'Get Composer cache directory'
+ id: 'composer-cache'
+ run: 'echo "cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'
+
+ -
+ name: 'Cache dependencies'
+ uses: 'actions/cache@v3'
+ 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'
+ run: 'composer install --no-progress'
-
- name: Run PHP-QA
+ name: 'Run PhpStan'
+ run: 'vendor/bin/phpstan analyze --no-progress'
+
+ tests:
+ name: 'PHPUnit'
+
+ runs-on: 'ubuntu-latest'
+
+ strategy:
+ matrix:
+ include:
+ -
+ php-version: '8.2'
+ composer-options: '--prefer-stable'
+ symfony-version: '6.3'
+ -
+ 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@v4'
+
+ -
+ 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 "cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'
+
+ -
+ name: 'Cache dependencies'
+ uses: 'actions/cache@v3'
+ 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: |
- make cs-full
+ composer global config --no-plugins allow-plugins.symfony/flex true
+ composer global require --no-progress --no-scripts --no-plugins symfony/flex
+ composer update --no-progress $COMPOSER_OPTIONS
+
+ -
+ name: 'Run tests'
+ run: make phpunit
diff --git a/.gitignore b/.gitignore
index ab2bbab..e2245b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,9 @@
-/phpunit.xml
-/composer.lock
-*.phar
+composer.lock
/vendor/
-/.php_cs.cache
-symfony.lock
+
+phpunit.xml
.phpunit.result.cache
+.phpunit.cache/
+.phpunit
+
+.php-cs-fixer.cache
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
new file mode 100644
index 0000000..14ca91b
--- /dev/null
+++ b/.php-cs-fixer.dist.php
@@ -0,0 +1,30 @@
+
+
+This source file is subject to the MIT license that is bundled
+with this source code in the file LICENSE.
+EOF;
+
+/** @var \Symfony\Component\Finder\Finder $finder */
+$finder = PhpCsFixer\Finder::create();
+$finder
+ ->in([
+ __DIR__ . '/src',
+ __DIR__ . '/tests',
+ ]);
+
+$config = new PhpCsFixer\Config();
+$config
+ ->setRiskyAllowed(true)
+ ->setRules(
+ array_merge(
+ require __DIR__ . '/vendor/rollerscapes/standards/php-cs-fixer-rules.php',
+ ['header_comment' => ['header' => $header]])
+ )
+ ->setFinder($finder);
+
+return $config;
diff --git a/.php_cs b/.php_cs
deleted file mode 100644
index e7b865d..0000000
--- a/.php_cs
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-This source file is subject to the MIT license that is bundled
-with this source code in the file LICENSE.
-EOF;
-
-return PhpCsFixer\Config::create()
- ->setRules([
- '@Symfony' => true,
- '@Symfony:risky' => true,
- 'array_syntax' => ['syntax' => 'short'],
- 'no_unreachable_default_argument_value' => false,
- 'braces' => ['allow_single_line_closure' => true],
- 'header_comment' => ['header' => $header],
- 'heredoc_to_nowdoc' => false,
- 'phpdoc_annotation_without_dot' => false,
- 'native_function_invocation' => false,
- 'phpdoc_types_order' => [
- 'null_adjustment' => 'none',
- 'sort_algorithm' => 'none',
- ],
- ])
- ->setRiskyAllowed(true)
- ->setFinder(
- PhpCsFixer\Finder::create()
- ->in([__DIR__.'/src', __DIR__.'/tests'])
- )
-;
diff --git a/LICENSE b/LICENSE
index 9b7544e..7d4bb1b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2012-2018 Sebastiaan Stok
+Copyright (c) 2012-present Sebastiaan Stok
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile b/Makefile
index 53f4622..2ba1948 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,4 @@
-QA_DOCKER_IMAGE=jakzal/phpqa:1.34.1-php7.4-alpine
-QA_DOCKER_COMMAND=docker run --init -t --rm --user "$(shell id -u):$(shell id -g)" --volume /tmp/tmp-phpqa-$(shell id -u):/tmp --volume "$(shell pwd):/project" --workdir /project ${QA_DOCKER_IMAGE}
+include vendor/rollerscapes/standards/Makefile
-dist: install cs-full phpstan test-full
-lint: install security-check cs-full phpstan
-
-install:
- composer install --no-progress --no-interaction --no-suggest --optimize-autoloader --prefer-dist --ansi
-
-test:
- ./vendor/bin/simple-phpunit --verbose
-
-# Linting tools
-security-check: ensure
- sh -c "${QA_DOCKER_COMMAND} security-checker security:check ./composer.lock"
-
-phpstan: ensure
- sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon"
-
-cs: ensure
- sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --diff"
-
-cs-full: ensure
- sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --using-cache=false --diff"
-
-cs-full-check: ensure
- sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --using-cache=false --diff --dry-run"
-
-ensure:
- mkdir -p ${HOME}/.composer /tmp/tmp-phpqa-$(shell id -u)
-
-.PHONY: install test phpstan cs cs-full cs-full-check
+phpunit:
+ ./vendor/bin/phpunit
diff --git a/README.md b/README.md
index 099f3cd..af9f33e 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
RollerworksPasswordStrengthBundle
=================================
-This Symfony-bundle integrates the Rollerworks [PasswordStrengthValidator][1] into your Symfony application.
+This Symfony-bundle integrates the Rollerworks [PasswordStrengthValidator][component] into your Symfony application.
_The PasswordStrengthValidator provides various password strength validators for the Symfony Validator._
@@ -17,37 +17,21 @@ To install this package, add `rollerworks/password-strength-bundle` to your comp
$ php composer.phar require rollerworks/password-strength-bundle
```
-Now, [Composer][2] will automatically download all required files, and install them
-for you.
+Now, [Composer][composer] will automatically download all required files,
+and install them for you.
-### Step2: Enable the bundle
+[Symfony Flex][flex]is assumed to enable the Bundle and add required configuration.
+https://symfony.com/doc/current/bundles.html
-**Note:** This step is **not** required for Symfony Flex.
-
-Enable the bundle in the kernel:
-
-```php
-=7.1",
- "rollerworks/password-strength-validator": "^1.0.1",
- "symfony/framework-bundle": "^3.4.22 || ^4.0 || ^5.0 || ^6.0"
+ "php": ">=8.2",
+ "rollerworks/password-strength-validator": "^2.0",
+ "symfony/framework-bundle": "^6.0 || ^7.0"
},
"require-dev": {
- "matthiasnoback/symfony-dependency-injection-test": "^3.1.0 || ^4.1.0",
- "symfony/console": "^3.4.22 || ^4.0 || ^5.0 || ^6.0",
- "symfony/phpunit-bridge": "^3.4.22 || ^4.0 || ^5.0 || ^6.0",
- "symfony/var-dumper": "^3.4.22 || ^4.0 || ^5.0 || ^6.0",
- "symfony/flex": "^1.20 || ^2.3"
- },
- "repositories": [
- {"url": "https://github.com/sstok/SymfonyDependencyInjectionTest.git", "type": "git"},
- {"url": "https://github.com/sstok/SymfonyConfigTest.git", "type": "git"}
- ],
- "extra": {
- "branch-alias": {
- "dev-master": "2.1-dev"
- }
+ "matthiasnoback/symfony-dependency-injection-test": "^5.0 || ^v4.3.1",
+ "phpunit/phpunit": "^9.5",
+ "rollerscapes/standards": "^1.0",
+ "symfony/phpunit-bridge": "^6.0 || ^7.0"
},
+ "minimum-stability": "dev",
+ "prefer-stable": true,
"autoload": {
"psr-4": {
"Rollerworks\\Bundle\\PasswordStrengthBundle\\": "src/"
@@ -53,17 +45,14 @@
"Rollerworks\\Bundle\\PasswordStrengthBundle\\Tests\\": "tests/"
}
},
- "minimum-stability": "dev",
- "prefer-stable": true,
"config": {
"allow-plugins": {
"symfony/flex": true
}
},
- "scripts": {
- "auto-scripts": {
- "cache:clear": "symfony-cmd",
- "assets:install %PUBLIC_DIR%": "symfony-cmd"
+ "extra": {
+ "branch-alias": {
+ "dev-main": "3.0-dev"
}
}
}
diff --git a/docs/configuration.md b/docs/configuration.md
deleted file mode 100644
index 42b018e..0000000
--- a/docs/configuration.md
+++ /dev/null
@@ -1,139 +0,0 @@
-Bundle configuration reference
-==============================
-
-## Blacklist
-
-The `Rollerworks\Component\PasswordStrength\Validator\Constraints\Blacklist` constraint requires
-you configure a blacklist provider. Otherwise any password will be considered valid.
-
-See also https://github.com/rollerworks/PasswordStrengthValidator/blob/master/docs/blacklist.md
-for a complete manual on using this constraint.
-
-**New since 2.0:**
-
-> Since 2.0 the `Blacklist` constraint allows to use a different provider then the default.
-> Use the `provider` option of the constraint to search in a different provider.
->
-> `new Blacklist(['provider' => 'my_customer_provider.name' ])`
->
-> Note that only providers registered in the `blacklist.providers` configuration
-> can be used.
-
-First you need to set a default provider.
-
-**Note:** Some providers require additional configuring, like database credentials.
-
-> The configuration file is usually located at `app/config/config.yml`
->
-> When using Symfony Flex the configuration file may be located elsewhere,
-> and could be generated for you (eg. `config/packages/rollerworks_password.yml`).
-
-First you need to configure a default blacklist provider.
-Add the following to your config file:
-
-```yaml
-rollerworks_password_strength:
- blacklist:
- # Replace rollerworks_password_strength.blacklist.provider.noop with the service-id of the provider you want to use
- default_provider: rollerworks_password_strength.blacklist.provider.noop
-```
-
-The `rollerworks_password_strength.blacklist.provider.noop` is a no-op provider.
-It's main purpose is to ensures the application doesn't break, but you can also use
-this to disable password blacklist listing without having to update your code.
-
-### Configuring providers
-
-The PasswordStrength component comes already pre-bundled with support for, in-memory,
-SQLite3, PDO, and a ChainProvider to search in multiple providers.
-
-**Caution:**
-
-* The `blacklist.default_provider` option accepts any service-id.
-* The `blacklist.providers` option is a fixed config-structure of providers.
-
-The `blacklist.providers` option is used to compose a list of loadable provider
-services, only configured providers in the list can be used by the `Blacklist` constraint,
-and for maintenance commands. _It's not possible to add custom providers (yet)._
-
-
-
-This bundle provides an integration for all the pre-bundled provider of the component.
-You can choose from:
-
-* rollerworks_password_strength.blacklist.provider.noop: Default implementation, always returns "not blacklisted".
-* [rollerworks_password_strength.blacklist.provider.array](#array): In-memory-array blacklist, not recommended for big lists.
-* [rollerworks_password_strength.blacklist.provider.sqlite](#sqlite): SQLite3 database file.
-* [rollerworks_password_strength.blacklist.provider.chain](#chain): Allows using multiple blacklist providers.
-
-### Array
-
-Update your configuration as follow:
-
-```yaml
-rollerworks_password_strength:
- blacklist:
- default_provider: rollerworks_password_strength.blacklist.provider.array
- providers:
- # The 'array' contains a list with all the blacklisted words
- array: [blacklisted-word-1, blacklisted-word-2]
-```
-
-### Sqlite
-
-Update your configuration as follow:
-
-```yaml
-rollerworks_password_strength:
- blacklist:
- default_provider: rollerworks_password_strength.blacklist.provider.sqlite
- providers:
- sqlite:
- # Make sure the location is outside the cache dir
- dsn: "file:%kernel.root_dir%/Resources/password_blacklist.db"
-```
-
-### Chain
-
-The chain provider works by searching in the registered providers,
-you can also add service-id of your custom providers.
-
-Update your configuration as follow:
-
-```yaml
-rollerworks_password_strength:
- blacklist:
- default_provider: rollerworks_password_strength.blacklist.provider.sqlite
- providers:
- chain:
- lazy: true # Use the LazyChainLoader for better performance (doesn't allow updating at runtime)
- providers:
- # Add a list of provider service-ids to search in
- - rollerworks_password_strength.blacklist.provider.array
- - rollerworks_password_strength.blacklist.provider.sqlite
-```
-
-**Note:** The `lazy` option uses `LazyChainLoader` for better performance,
-but unlike the "old" `ChainLoader` the loader doesn't allow adding extra providers
-at runtime, all providers you want to use _must_ be in the list.
-
-### Custom blacklist provider
-
-To use a custom blacklist provider, first register it in the service container.
-
-Depending your usage, add it to the `providers.chain.providers` list or set the
-`default_provider` to the service id.
-
-**Note:** The blacklist provider must implement the
-`Rollerworks\Component\PasswordStrength\Blacklist\BlacklistProviderInterface`.
-
-## Commands
-
-Commands for managing the blacklist are automatically registered
-when the Symfony Console component is installed.
-
-You can use the `--provider` option to specify a loader to manage.
-_This doesn't support custom loaders yet._
-
-See also: https://github.com/rollerworks/PasswordStrengthValidator/blob/master/docs/blacklist.md#commands
-
diff --git a/phpstan.neon b/phpstan.neon
index 9247cda..d799271 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,15 +1,17 @@
includes:
- - /tools/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-phpunit/extension.neon
+ - vendor/rollerscapes/standards/phpstan.neon
+ #- phpstan-baseline.neon
parameters:
- autoload_files:
- - vendor/autoload.php
- - vendor/bin/.phpunit/phpunit-8.3.5-0/vendor/autoload.php # Pain is your friend.... (at least it works for now)
+ #reportUnmatchedIgnoredErrors: false
level: 5
+
paths:
- ./src
- ./tests
+ excludePaths:
+ - var/
+ - templates/
+ - translations/
- checkNullables: false # To many false positives
- ignoreErrors:
- - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder\:\:root\(\)#'
+ #ignoreErrors:
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index fe780a5..c7d9fc8 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,7 +1,7 @@
-
-
+
+
./src
-
- ./vendor/
- ./tests/
-
-
-
+
+
+ ./vendor/
+ ./tests/
+
+
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
deleted file mode 100644
index 6d0b95e..0000000
--- a/src/DependencyInjection/Configuration.php
+++ /dev/null
@@ -1,64 +0,0 @@
-
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Rollerworks\Bundle\PasswordStrengthBundle\DependencyInjection;
-
-use Symfony\Component\Config\Definition\Builder\TreeBuilder;
-use Symfony\Component\Config\Definition\ConfigurationInterface;
-
-class Configuration implements ConfigurationInterface
-{
- public function getConfigTreeBuilder(): TreeBuilder
- {
- $treeBuilder = new TreeBuilder('rollerworks_password_strength');
-
- if (method_exists($treeBuilder, 'getRootNode')) {
- $rootNode = $treeBuilder->getRootNode();
- } else {
- // BC for Symfony < 4.2
- $rootNode = $treeBuilder->root('rollerworks_password_strength');
- }
-
- $rootNode
- ->addDefaultsIfNotSet()
- ->children()
- ->arrayNode('blacklist')
- ->addDefaultsIfNotSet()
- ->children()
- ->scalarNode('default_provider')->defaultValue('rollerworks_password_strength.blacklist.provider.noop')->end()
- ->arrayNode('providers')
- ->fixXmlConfig('provider')
- ->children()
- ->arrayNode('sqlite')
- ->children()
- ->scalarNode('dsn')->defaultNull()->cannotBeEmpty()->end()
- ->end()
- ->end()
- ->arrayNode('chain')
- ->children()
- ->booleanNode('lazy')->defaultFalse()->end()
- ->arrayNode('providers')
- ->fixXmlConfig('provider')
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->end()
- ->arrayNode('array')->prototype('scalar')->end()
- ->end()
- ->end()
- ->end()
- ->end()
- ->end()
- ;
-
- return $treeBuilder;
- }
-}
diff --git a/src/DependencyInjection/RollerworksPasswordStrengthExtension.php b/src/DependencyInjection/RollerworksPasswordStrengthExtension.php
index a1cb5db..7057ca7 100644
--- a/src/DependencyInjection/RollerworksPasswordStrengthExtension.php
+++ b/src/DependencyInjection/RollerworksPasswordStrengthExtension.php
@@ -11,132 +11,29 @@
namespace Rollerworks\Bundle\PasswordStrengthBundle\DependencyInjection;
-use Rollerworks\Component\PasswordStrength\Blacklist\LazyChainProvider;
-use Rollerworks\Component\PasswordStrength\Command\BlacklistListCommand;
+use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrength;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\Config\Resource\DirectoryResource;
-use Symfony\Component\Console\Application;
-use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
final class RollerworksPasswordStrengthExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container): void
{
- $configuration = new Configuration();
- $config = $this->processConfiguration($configuration, $configs);
-
- $container->setParameter('rollerworks_password_strength.blacklist_provider', $config['blacklist']['default_provider']);
- $container->setParameter('rollerworks_password_strength.blacklist.sqlite.dsn', '');
-
- $container->setAlias('rollerworks_password_strength.blacklist_provider', $config['blacklist']['default_provider']);
-
- $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('strength_validator.xml');
- $loader->load('blacklist.xml');
-
- if (isset($config['blacklist']['providers'])) {
- $this->setBlackListProvidersConfiguration($config['blacklist']['providers'], $container);
- $this->registerBlacklistCommands($container, $config['blacklist']['providers']);
- }
}
- /**
- * Allow an extension to prepend the extension configurations.
- */
public function prepend(ContainerBuilder $container): void
{
$container->prependExtensionConfig('framework', [
'translator' => [
'paths' => [
- dirname(dirname((new \ReflectionClass(LazyChainProvider::class))->getFileName())).'/Resources/translations',
+ \dirname((new \ReflectionClass(PasswordStrength::class))->getFileName(), 3) . '/Resources/translations',
],
],
]);
}
-
- private function setBlackListProvidersConfiguration(array $config, ContainerBuilder $container)
- {
- if (isset($config['sqlite'])) {
- $container->setParameter('rollerworks_password_strength.blacklist.sqlite.dsn', $config['sqlite']['dsn']);
- }
-
- if (isset($config['array'])) {
- $container
- ->getDefinition('rollerworks_password_strength.blacklist.provider.array')
- ->replaceArgument(0, $config['array']);
- }
-
- if (isset($config['chain'])) {
- if ($config['chain']['lazy']) {
- $this->configureLazyChainBlacklistProvider($container, $config);
- } else {
- $this->configureChainBlacklistProvider($container, $config);
- }
- }
- }
-
- private function configureLazyChainBlacklistProvider(ContainerBuilder $container, array $config)
- {
- $refs = [];
- $serviceIds = [];
-
- foreach ($config['chain']['providers'] as $name => $serviceId) {
- $refs[$serviceId] = new Reference($serviceId);
- $serviceIds[] = $serviceId;
- }
-
- $chainLoader = $container->getDefinition('rollerworks_password_strength.blacklist.provider.chain');
- $chainLoader->setArguments([ServiceLocatorTagPass::register($container, $refs), $serviceIds]);
- $chainLoader->setClass(LazyChainProvider::class);
- }
-
- private function configureChainBlacklistProvider(ContainerBuilder $container, array $config)
- {
- $chainLoader = $container->getDefinition('rollerworks_password_strength.blacklist.provider.chain');
-
- foreach ($config['chain']['providers'] as $provider) {
- $chainLoader->addMethodCall('addProvider', [new Reference($provider)]);
- }
- }
-
- private function registerBlacklistCommands(ContainerBuilder $container, array $providers)
- {
- if (!class_exists(Application::class)) {
- return;
- }
-
- $refs = ['default' => new Reference('rollerworks_password_strength.blacklist_provider')];
- foreach ($providers as $name => $serviceId) {
- $refs[$name] = new Reference('rollerworks_password_strength.blacklist.provider.'.$name);
- }
- $providersService = ServiceLocatorTagPass::register($container, $refs);
-
- $r = new \ReflectionClass(BlacklistListCommand::class);
- $container->addResource(new DirectoryResource(dirname($r->getFileName())));
- $namespace = $r->getNamespaceName();
-
- $finder = (new Finder())
- ->in(dirname($r->getFileName()))
- ->name('/\.php$/')
- ->notName('/BlacklistCommand.php$/')
- ->notName('/BlacklistCommonCommand\.php$/')
- ;
-
- /** @var SplFileInfo $file */
- foreach ($finder as $file) {
- $class = $namespace.'\\'.$file->getBasename('.php');
-
- $container->register($class, $class)
- ->addTag('console.command')
- ->addArgument($providersService)
- ;
- }
- }
}
diff --git a/src/Resources/config/blacklist.xml b/src/Resources/config/blacklist.xml
deleted file mode 100644
index 03d9c17..0000000
--- a/src/Resources/config/blacklist.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
- %rollerworks_password_strength.blacklist.sqlite.dsn%
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/RollerworksPasswordStrengthBundle.php b/src/RollerworksPasswordStrengthBundle.php
index 131d4a8..ed93971 100644
--- a/src/RollerworksPasswordStrengthBundle.php
+++ b/src/RollerworksPasswordStrengthBundle.php
@@ -13,9 +13,4 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
-/**
- * @author Sebastiaan Stok
- */
-class RollerworksPasswordStrengthBundle extends Bundle
-{
-}
+final class RollerworksPasswordStrengthBundle extends Bundle {}
diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php
deleted file mode 100644
index 654b64d..0000000
--- a/tests/DependencyInjection/ConfigurationTest.php
+++ /dev/null
@@ -1,123 +0,0 @@
-
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Rollerworks\Bundle\PasswordStrengthBundle\Tests\DependencyInjection;
-
-use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
-use PHPUnit\Framework\TestCase;
-use Rollerworks\Bundle\PasswordStrengthBundle\DependencyInjection\Configuration;
-
-class ConfigurationTest extends TestCase
-{
- use ConfigurationTestCaseTrait;
-
- protected function getConfiguration()
- {
- return new Configuration();
- }
-
- public function testNoBlacklistProvidersConfiguredByDefault()
- {
- $this->assertProcessedConfigurationEquals(
- [
- [],
- ],
- [
- 'blacklist' => [
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.noop',
- ],
- ]
- );
- }
-
- public function testSqlLiteBlacklistProviderIsConfigured()
- {
- $this->assertProcessedConfigurationEquals(
- [
- [
- 'blacklist' => [
- 'providers' => [
- 'sqlite' => ['dsn' => 'sqlite:/path/to/the/db/file'],
- ],
- ],
- ],
- ],
- [
- 'blacklist' => [
- 'providers' => [
- 'sqlite' => ['dsn' => 'sqlite:/path/to/the/db/file'],
- 'array' => [],
- ],
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.noop',
- ],
- ]
- );
- }
-
- public function testArrayBlacklistProviderIsConfigured()
- {
- $this->assertProcessedConfigurationEquals(
- [
- [
- 'blacklist' => [
- 'providers' => [
- 'array' => ['foo', 'foobar', 'kaboom'],
- ],
- ],
- ],
- ],
- [
- 'blacklist' => [
- 'providers' => [
- 'array' => ['foo', 'foobar', 'kaboom'],
- ],
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.noop',
- ],
- ]
- );
- }
-
- public function testConfigChain()
- {
- $this->assertProcessedConfigurationEquals(
- [
- [
- 'blacklist' => [
- 'providers' => [
- 'chain' => [
- 'lazy' => false,
- 'providers' => [
- 'rollerworks_password_strength.blacklist.provider.array',
- 'rollerworks_password_strength.blacklist.provider.sqlite',
- ],
- ],
- ],
- ],
- ],
- ],
- [
- 'blacklist' => [
- 'providers' => [
- 'chain' => [
- 'lazy' => false,
- 'providers' => [
- 'rollerworks_password_strength.blacklist.provider.array',
- 'rollerworks_password_strength.blacklist.provider.sqlite',
- ],
- ],
- 'array' => [],
- ],
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.noop',
- ],
- ]
- );
- }
-}
diff --git a/tests/DependencyInjection/ExtensionTest.php b/tests/DependencyInjection/ExtensionTest.php
index 72c4ae0..90693ce 100644
--- a/tests/DependencyInjection/ExtensionTest.php
+++ b/tests/DependencyInjection/ExtensionTest.php
@@ -13,163 +13,15 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Rollerworks\Bundle\PasswordStrengthBundle\DependencyInjection\RollerworksPasswordStrengthExtension;
-use Rollerworks\Component\PasswordStrength\Blacklist\ArrayProvider;
-use Rollerworks\Component\PasswordStrength\Blacklist\ChainProvider;
-use Rollerworks\Component\PasswordStrength\Blacklist\LazyChainProvider;
-use Rollerworks\Component\PasswordStrength\Blacklist\NoopProvider;
-use Rollerworks\Component\PasswordStrength\Blacklist\SqliteProvider;
-use Rollerworks\Component\PasswordStrength\Command\BlacklistCommand;
-use Rollerworks\Component\PasswordStrength\Command\BlacklistCommonCommand;
-use Rollerworks\Component\PasswordStrength\Command\BlacklistListCommand;
-use Rollerworks\Component\PasswordStrength\Validator\Constraints\Blacklist as BlacklistConstraint;
-use Rollerworks\Component\PasswordStrength\Validator\Constraints\BlacklistValidator;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrength;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrengthValidator;
-use Symfony\Component\Console\Application;
-use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Validator\ContainerConstraintValidatorFactory;
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
class ExtensionTest extends AbstractExtensionTestCase
{
- public function testLoadDefaultConfiguration()
- {
- $this->load();
- $this->initProviderService();
- $this->compile();
-
- $this->assertContainerBuilderHasService(BlacklistValidator::class);
- $this->assertContainerBuilderHasService('rollerworks_password_strength.blacklist_provider', NoopProvider::class);
-
- $constraint = new BlacklistConstraint();
- $this->assertContainerBuilderHasService($constraint->validatedBy());
- }
-
- private function initProviderService(): void
- {
- $this->container->getAlias('rollerworks_password_strength.blacklist_provider')->setPublic(true);
- $this->container->getCompiler()->addPass(new MakeAllServicesPublicPass(), PassConfig::TYPE_OPTIMIZE);
- }
-
- public function testLoadWithSqliteConfiguration()
- {
- $this->load([
- 'blacklist' => [
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.sqlite',
- 'providers' => [
- 'sqlite' => ['dsn' => 'sqlite:something'],
- ],
- ],
- ]);
-
- $this->initProviderService();
- $this->compile();
-
- $this->assertContainerBuilderHasService(PasswordStrengthValidator::class);
- $this->assertContainerBuilderHasService('rollerworks_password_strength.blacklist_provider', SqliteProvider::class);
- }
-
- public function testLoadWithArrayConfiguration()
- {
- $this->load([
- 'blacklist' => [
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.array',
- 'providers' => [
- 'array' => ['foo', 'foobar', 'kaboom'],
- ],
- ],
- ]);
-
- $this->initProviderService();
- $this->compile();
-
- $this->assertContainerBuilderHasService(PasswordStrengthValidator::class);
- $this->assertContainerBuilderHasService('rollerworks_password_strength.blacklist_provider', ArrayProvider::class);
-
- $provider = $this->container->get('rollerworks_password_strength.blacklist_provider');
-
- self::assertTrue($provider->isBlacklisted('foo'));
- self::assertTrue($provider->isBlacklisted('foobar'));
- self::assertTrue($provider->isBlacklisted('kaboom'));
- self::assertFalse($provider->isBlacklisted('leeRoy'));
- }
-
- public function testLoadWithChainConfiguration()
- {
- $this->load([
- 'blacklist' => [
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.chain',
- 'providers' => [
- 'array' => ['foo', 'foobar', 'kaboom'],
- 'chain' => [
- 'providers' => [
- 'rollerworks_password_strength.blacklist.provider.array',
- 'acme.password_blacklist.array',
- ],
- ],
- ],
- ],
- ]);
-
- $this->container->set(
- 'acme.password_blacklist.array',
- new ArrayProvider(['amy', 'doctor', 'rory'])
- );
-
- $this->initProviderService();
- $this->compile();
-
- $this->assertContainerBuilderHasService(PasswordStrengthValidator::class);
- $this->assertContainerBuilderHasService('rollerworks_password_strength.blacklist_provider', ChainProvider::class);
-
- $provider = $this->container->get('rollerworks_password_strength.blacklist_provider');
- self::assertTrue($provider->isBlacklisted('foo'));
- self::assertTrue($provider->isBlacklisted('foobar'));
- self::assertTrue($provider->isBlacklisted('kaboom'));
- self::assertTrue($provider->isBlacklisted('doctor'));
- self::assertFalse($provider->isBlacklisted('leeRoy'));
- }
-
- public function testLoadWithLazyChainConfiguration()
- {
- $this->load([
- 'blacklist' => [
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.chain',
- 'providers' => [
- 'array' => ['foo', 'foobar', 'kaboom'],
- 'chain' => [
- 'lazy' => true,
- 'providers' => [
- 'rollerworks_password_strength.blacklist.provider.array',
- 'acme.password_blacklist.array',
- ],
- ],
- ],
- ],
- ]);
-
- $this->container->set(
- 'acme.password_blacklist.array',
- new ArrayProvider(['amy', 'doctor', 'rory'])
- );
-
- $this->initProviderService();
- $this->compile();
-
- $this->assertContainerBuilderHasService(PasswordStrengthValidator::class);
- $this->assertContainerBuilderHasService('rollerworks_password_strength.blacklist_provider', LazyChainProvider::class);
-
- $provider = $this->container->get('rollerworks_password_strength.blacklist_provider');
- self::assertTrue($provider->isBlacklisted('foo'));
- self::assertTrue($provider->isBlacklisted('foobar'));
- self::assertTrue($provider->isBlacklisted('kaboom'));
- self::assertTrue($provider->isBlacklisted('doctor'));
- self::assertFalse($provider->isBlacklisted('leeRoy'));
- }
-
- public function testPasswordValidatorsAreRegistered()
+ public function test_password_validators_are_registered()
{
$this->container->addCompilerPass(new AddConstraintValidatorsPass());
$this->container->register('validator.validator_factory', ContainerConstraintValidatorFactory::class)
@@ -177,55 +29,12 @@ public function testPasswordValidatorsAreRegistered()
->setArguments([new Reference('service_container'), []]);
$this->load();
- $this->initProviderService();
$this->compile();
/** @var ContainerConstraintValidatorFactory $factory */
$factory = $this->container->get('validator.validator_factory');
self::assertInstanceOf(PasswordStrengthValidator::class, $factory->getInstance(new PasswordStrength(['minStrength' => 1])));
- self::assertInstanceOf(BlacklistValidator::class, $factory->getInstance(new BlacklistConstraint()));
- }
-
- public function testBlacklistCommandsAreRegistered()
- {
- if (!class_exists(Application::class)) {
- $this->markTestSkipped('Needs the Symfony/console component');
- }
-
- $this->container->set(
- 'acme.password_blacklist.array',
- new ArrayProvider(['amy', 'doctor', 'rory'])
- );
-
- $this->load([
- 'blacklist' => [
- 'default_provider' => 'rollerworks_password_strength.blacklist.provider.chain',
- 'providers' => [
- 'array' => ['foo', 'foobar', 'kaboom'],
- 'chain' => [
- 'providers' => [
- 'rollerworks_password_strength.blacklist.provider.array',
- 'acme.password_blacklist.array',
- ],
- ],
- ],
- ],
- ]);
- $this->initProviderService();
- $this->compile();
-
- // No need to test all commands.
- $this->assertContainerBuilderHasServiceDefinitionWithTag(BlacklistListCommand::class, 'console.command');
- $this->assertContainerBuilderNotHasService(BlacklistCommand::class);
- $this->assertContainerBuilderNotHasService(BlacklistCommonCommand::class);
- $command = $this->container->findDefinition(BlacklistListCommand::class);
- /** @var ServiceLocator $argument */
- $argument = $this->container->get((string) $command->getArgument(0));
-
- self::assertTrue($argument->has('default'), 'Should have "default" as provider');
- self::assertTrue($argument->has('array'), 'Should have "array" as provider');
- self::assertFalse($argument->has('container'), 'Should not have "container" as provider');
}
protected function getContainerExtensions(): array
diff --git a/tests/DependencyInjection/MakeAllServicesPublicPass.php b/tests/DependencyInjection/MakeAllServicesPublicPass.php
deleted file mode 100644
index 35681d4..0000000
--- a/tests/DependencyInjection/MakeAllServicesPublicPass.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace Rollerworks\Bundle\PasswordStrengthBundle\Tests\DependencyInjection;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-
-final class MakeAllServicesPublicPass implements CompilerPassInterface
-{
- public function process(ContainerBuilder $container): void
- {
- foreach ($container->getDefinitions() as $def) {
- $def->setPublic(true);
- }
- }
-}
diff --git a/tests/fixtures/passwords-list1.txt b/tests/fixtures/passwords-list1.txt
deleted file mode 100644
index a1a8ab7..0000000
--- a/tests/fixtures/passwords-list1.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-test
-foobar
diff --git a/tests/fixtures/passwords-list2.txt b/tests/fixtures/passwords-list2.txt
deleted file mode 100644
index e69de29..0000000