Skip to content

Commit

Permalink
feature #34 Add support for Symfony 5 (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

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


Commits
-------

0b16a9a Add support for Symfony 5
76e8ac9 Fix CS
02bdb76 Disable PhpStan
af1cb9b Remove PHP 7.4 (for now)
  • Loading branch information
sstok authored Dec 1, 2019
2 parents 83b9040 + af1cb9b commit 8c6441b
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.phar
/vendor/
/.php_cs.cache
symfony.lock
46 changes: 31 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
language: php

dist: xenial

env:
global:
- SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE=1
- SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
- SYMFONY_PHPUNIT_VERSION=7.5.6
- QA_DOCKER_IMAGE=jakzal/phpqa:1.25.0-php7.2-alpine

matrix:
include:
- php: 7.1
env: SYMFONY_REQUIRE='^3.4'
- php: 7.2
env: DEPENDENCIES='dev'
- php: 7.2
env: DEPENDENCIES='low'
- php: 7.2
env: SYMFONY_REQUIRE='^4.4'
- php: 7.3
env: SYMFONY_REQUIRE='^5.0'
# - php: 7.4
# env: SYMFONY_REQUIRE='^5.0'
- php: 7.2
env: lint=1
services:
- docker
fast_finish: true

sudo: false

cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/cache/files

before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.14.2/php-cs-fixer.phar; fi
- if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi
- composer global require symfony/flex

- if [[ $lint = 1 ]]; then docker pull ${QA_DOCKER_IMAGE}; fi
- export PATH="$PATH:$HOME/.composer/vendor/bin"

install:
- if [ "$DEPENDENCIES" == "dev" ]; then composer config minimum-stability dev; fi;
- if [ "$DEPENDENCIES" != "low" ]; then composer update --prefer-dist --no-progress --no-suggest --ansi; fi;
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-dist --no-progress --no-suggest --ansi --prefer-lowest; fi;
- composer install --prefer-dist --no-progress --no-suggest --ansi

script:
- export SYMFONY_PHPUNIT_VERSION=7.5.6
- export SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
- export SYMFONY_DEPRECATIONS_HELPER=strict
- vendor/bin/simple-phpunit --verbose
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
#- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi # temporarily disabled
- |
if [[ $lint = 1 ]]
then
mkdir /tmp/tmp-phpqa-$(id -u)
export QA_DOCKER_COMMAND="docker run --init --interactive --tty --rm --user "$(id -u):$(id -g)" --volume /tmp/tmp-phpqa-$(id -u):/tmp --volume "$(pwd):/project" --workdir /project ${QA_DOCKER_IMAGE}"
sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --diff --dry-run"
#sh -c "${QA_DOCKER_COMMAND} phpstan analyse"
#sh -c "${QA_DOCKER_COMMAND} vendor/bin/psalm --show-info=false"
fi
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"psr/container": "^1.0",
"psr/log": "^1.0",
"symfony/polyfill-mbstring": "^1.5.0",
"symfony/translation": "^3.4.22 || ^4.0",
"symfony/validator": "^3.4.22 || ^4.0"
"symfony/translation": "^3.4.22 || ^4.0 || ^5.0",
"symfony/validator": "^3.4.22 || ^4.0 || ^5.0"
},
"require-dev": {
"symfony/config": "^3.4.22 || ^4.0",
"symfony/console": "^3.4.22 || ^4.0",
"symfony/phpunit-bridge": "^3.4.22 || ^4.0",
"symfony/config": "^3.4.22 || ^4.0 || ^5.0",
"symfony/console": "^3.4.22 || ^4.0 || ^5.0",
"symfony/phpunit-bridge": "^3.4.22 || ^4.0 || ^5.0",
"php-http/httplug": "^1.1",
"guzzlehttp/psr7": "^1.4"
},
Expand Down
9 changes: 8 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
includes:
- /tools/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
autoload_files:
- vendor/autoload.php
- vendor/symfony/phpunit-bridge/bin/.phpunit/phpunit-5.7.1/vendor/autoload.php
- vendor/bin/.phpunit/phpunit-7.5.6-0/vendor/autoload.php # Pain is your friend.... (at least it works for now)
level: 5
paths:
- ./src
- ./tests

ignoreErrors:
#- '#__construct\(\) does not call parent constructor from .+#'
Expand Down
3 changes: 0 additions & 3 deletions src/Blacklist/ArrayProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class ArrayProvider implements BlacklistProviderInterface
{
private $blacklist = [];

/**
* @param array $blacklist
*/
public function __construct(array $blacklist)
{
$this->blacklist = $blacklist;
Expand Down
2 changes: 0 additions & 2 deletions src/Blacklist/ChainProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public function __construct(array $providers = [])
/**
* Adds a new blacklist provider.
*
* @param BlacklistProviderInterface $provider
*
* @throws \RuntimeException
*
* @return self
Expand Down
3 changes: 1 addition & 2 deletions src/Blacklist/LazyChainProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ final class LazyChainProvider implements BlacklistProviderInterface
/**
* Constructor.
*
* @param ContainerInterface $container
* @param string[] $providers
* @param string[] $providers
*/
public function __construct(ContainerInterface $container, array $providers)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Blacklist/PdoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ abstract protected function initDb();
/**
* @param object $db
* @param string $query
* @param array $args
*
* @return mixed
*/
Expand All @@ -166,7 +165,6 @@ protected function fetch($db, $query, array $args = [])
/**
* @param object $db
* @param string $query
* @param array $args
*
* @throws \RuntimeException
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Command/BlacklistCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->blacklistProvider = $this->providers->get($input->getOption('provider'));

if (!$this->blacklistProvider instanceof UpdatableBlacklistProviderInterface) {
throw new \RuntimeException(
sprintf('Blacklist provider "%s" is not updatable.', $input->getOption('provider'))
);
throw new \RuntimeException(sprintf('Blacklist provider "%s" is not updatable.', $input->getOption('provider')));
}
}
}
4 changes: 3 additions & 1 deletion src/Command/BlacklistCommonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class BlacklistCommonCommand extends BlacklistCommand
{
const MESSAGE = '%d';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

Expand Down Expand Up @@ -57,6 +57,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln(sprintf(static::MESSAGE, $count));

return 0;
}

abstract protected function attemptAction(UpdatableBlacklistProviderInterface $service, $password);
Expand Down
4 changes: 3 additions & 1 deletion src/Command/BlacklistListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->blacklistProvider->all() as $password) {
$output->writeln($password, OutputInterface::OUTPUT_RAW);
}

return 0;
}
}
4 changes: 3 additions & 1 deletion src/Command/BlacklistPurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

Expand All @@ -48,5 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->blacklistProvider->purge();

$io->success('Successfully removed all passwords from your blacklist.');

return 0;
}
}
2 changes: 1 addition & 1 deletion src/P0wnedPassword/Request/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Rollerworks\Component\PasswordStrength\P0wnedPassword\Request;

use GuzzleHttp\Psr7\Request;
use Http\Client\Exception\HttpException;
use Http\Client\Exception as HttpException2;
use Http\Client\Exception\HttpException;
use Http\Client\HttpClient;
use Psr\Log\LoggerInterface;

Expand Down
12 changes: 3 additions & 9 deletions src/Validator/Constraints/BlacklistValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ class BlacklistValidator extends ConstraintValidator
private $providersLoader;

/**
* @param BlacklistProviderInterface $defaultProvider
* @param ContainerInterface $providersLoader Service-container for loading
* blacklist providers
* @param ContainerInterface $providersLoader Service-container for loading
* blacklist providers
*/
public function __construct(BlacklistProviderInterface $defaultProvider, ContainerInterface $providersLoader = null)
{
Expand All @@ -59,12 +58,7 @@ public function validate($password, Constraint $constraint)
$provider = $this->defaultProvider;
} else {
if (null === $this->providersLoader || !$this->providersLoader->has($constraint->provider)) {
throw new RuntimeException(
sprintf(
'Unable to use blacklist provider "%s", eg. no blacklists were configured or this provider is not supported.',
$constraint->provider
)
);
throw new RuntimeException(sprintf('Unable to use blacklist provider "%s", eg. no blacklists were configured or this provider is not supported.', $constraint->provider));
}

$provider = $this->providersLoader->get($constraint->provider);
Expand Down
2 changes: 0 additions & 2 deletions src/Validator/Constraints/P0wnedPasswordValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class P0wnedPasswordValidator extends ConstraintValidator

/**
* P0wnedPasswordValidator constructor.
*
* @param Client $client
*/
public function __construct(Client $client)
{
Expand Down
17 changes: 11 additions & 6 deletions src/Validator/Constraints/PasswordStrengthValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

use Symfony\Component\Translation\Loader\XliffFileLoader;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Password strength Validation.
Expand Down Expand Up @@ -49,14 +50,18 @@ class PasswordStrengthValidator extends ConstraintValidator
5 => 'very_strong',
];

public function __construct(TranslatorInterface $translator = null)
public function __construct($translator = null)
{
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
}

// If translator is missing create a new translator.
// With the 'en' locale and 'validators' domain.
if (null === $translator) {
$translator = new Translator('en');
$translator->addLoader('xlf', new XliffFileLoader());
$translator->addResource('xlf', dirname(dirname(__DIR__)).'/Resources/translations/validators.en.xlf', 'en', 'validators');
$translator->addResource('xlf', dirname(__DIR__, 2).'/Resources/translations/validators.en.xlf', 'en', 'validators');
}

$this->translator = $translator;
Expand Down Expand Up @@ -107,8 +112,8 @@ public function validate($password, Constraint $constraint)
if ($passwordStrength < $constraint->minStrength) {
$parameters = [
'{{ length }}' => $constraint->minLength,
'{{ min_strength }}' => $this->translator->trans(/** @Ignore */'rollerworks_password.strength_level.'.self::$levelToLabel[$constraint->minStrength], [], 'validators'),
'{{ current_strength }}' => $this->translator->trans(/** @Ignore */'rollerworks_password.strength_level.'.self::$levelToLabel[$passwordStrength], [], 'validators'),
'{{ min_strength }}' => $this->translator->trans(/* @Ignore */'rollerworks_password.strength_level.'.self::$levelToLabel[$constraint->minStrength], [], 'validators'),
'{{ current_strength }}' => $this->translator->trans(/* @Ignore */'rollerworks_password.strength_level.'.self::$levelToLabel[$passwordStrength], [], 'validators'),
'{{ strength_tips }}' => implode(', ', array_map([$this, 'translateTips'], $tips)),
];

Expand All @@ -123,7 +128,7 @@ public function validate($password, Constraint $constraint)
*/
public function translateTips($tip)
{
return $this->translator->trans(/** @Ignore */'rollerworks_password.tip.'.$tip, [], 'validators');
return $this->translator->trans(/* @Ignore */'rollerworks_password.tip.'.$tip, [], 'validators');
}

private function calculateStrength($password, &$tips)
Expand Down
2 changes: 0 additions & 2 deletions tests/BlackListMockProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ protected function createMockedProvider($blacklisted)
}

/**
* @param array $loaders
*
* @return ContainerInterface|object
*/
protected function createLoadersContainer(array $loaders)
Expand Down
2 changes: 1 addition & 1 deletion tests/P0wnedPassword/Request/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Http\Client\HttpClient;
use Rollerworks\Component\PasswordStrength\P0wnedPassword\Request\Client;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Rollerworks\Component\PasswordStrength\P0wnedPassword\Request\Client;
use Rollerworks\Component\PasswordStrength\P0wnedPassword\Request\Result;

class ClientTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/Symfony27Compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* with this source code in the file LICENSE.
*/

use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;

if (!class_exists(ConstraintValidatorTestCase::class)) {
class_alias(AbstractConstraintValidatorTest::class, ConstraintValidatorTestCase::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/Validator/P0wnedPasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Rollerworks\Component\PasswordStrength\Tests\Validator;

use PHPUnit\Framework\MockObject\MockObject;
use Rollerworks\Component\PasswordStrength\P0wnedPassword\Request\Client;
use Rollerworks\Component\PasswordStrength\P0wnedPassword\Request\Result;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\P0wnedPassword;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\P0wnedPasswordValidator;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

class P0wnedPasswordValidatorTest extends ConstraintValidatorTestCase
Expand All @@ -26,7 +26,7 @@ class P0wnedPasswordValidatorTest extends ConstraintValidatorTestCase
/** @var P0wnedPasswordValidator */
protected $validator;

public function setUp()
public function setUp(): void
{
$this->client = $this->createMock(Client::class);
parent::setUp();
Expand Down
7 changes: 2 additions & 5 deletions tests/Validator/PasswordRequirementsValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public function testEmptyIsValid()
/**
* @dataProvider provideValidConstraints
*
* @param string $value
* @param PasswordRequirements $constraint
* @param string $value
*/
public function testValidValueConstraints($value, PasswordRequirements $constraint)
{
Expand All @@ -75,9 +74,7 @@ public function testValidValueConstraints($value, PasswordRequirements $constrai
/**
* @dataProvider provideViolationConstraints
*
* @param string $value
* @param PasswordRequirements $constraint
* @param array $violations
* @param string $value
*/
public function testViolationValueConstraints($value, PasswordRequirements $constraint, array $violations = [])
{
Expand Down

0 comments on commit 8c6441b

Please sign in to comment.