diff --git a/.travis.yml b/.travis.yml index eea187d..72fc1fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ matrix: - php: 7.0 env: DEPENDENCIES='dev' - php: 7.1 - env: DEPENDENCIES='low' + env: DEPENDENCIES='low' lint=1 fast_finish: true sudo: false @@ -17,6 +17,10 @@ cache: 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.3.2/php-cs-fixer.phar; fi + - if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi + - export PATH="$PATH:$HOME/.composer/vendor/bin" install: - if [ "$DEPENDENCIES" == "dev" ]; then composer config minimum-stability dev; fi; @@ -28,3 +32,5 @@ script: - 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 diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..56e84d3 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +parameters: + autoload_files: + - vendor/autoload.php + - vendor/symfony/phpunit-bridge/bin/.phpunit/phpunit-5.7.1/vendor/autoload.php + + 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#" + + # Tests + - '#Parameter \#1 \$password of method Rollerworks\\Component\\PasswordStrength\\Blacklist\\[a-zA-Z]+\:\:isBlacklisted\(\) expects string#' diff --git a/src/Blacklist/ArrayProvider.php b/src/Blacklist/ArrayProvider.php index 85d7cbb..c7e4dba 100644 --- a/src/Blacklist/ArrayProvider.php +++ b/src/Blacklist/ArrayProvider.php @@ -20,7 +20,7 @@ */ class ArrayProvider implements BlacklistProviderInterface { - private $blacklist = array(); + private $blacklist = []; /** * @param array $blacklist diff --git a/src/Blacklist/ChainProvider.php b/src/Blacklist/ChainProvider.php index 4c87aa2..5c5d3de 100644 --- a/src/Blacklist/ChainProvider.php +++ b/src/Blacklist/ChainProvider.php @@ -28,7 +28,7 @@ class ChainProvider implements BlacklistProviderInterface * * @param BlacklistProviderInterface[] $providers */ - public function __construct(array $providers = array()) + public function __construct(array $providers = []) { foreach ($providers as $provider) { $this->addProvider($provider); diff --git a/src/Blacklist/PdoProvider.php b/src/Blacklist/PdoProvider.php index 7081dbc..4d09c4c 100644 --- a/src/Blacklist/PdoProvider.php +++ b/src/Blacklist/PdoProvider.php @@ -51,10 +51,10 @@ public function add($password) } $db = $this->initDb(); - $args = array( + $args = [ ':password' => $password, ':created_at' => time(), - ); + ]; try { if ($this->isBlacklisted($password)) { @@ -84,9 +84,9 @@ public function delete($password) } $db = $this->initDb(); - $args = array( + $args = [ ':password' => $password, - ); + ]; try { $this->exec($db, 'DELETE FROM rollerworks_passdbl WHERE passwd = :password', $args); @@ -132,7 +132,7 @@ public function isBlacklisted($password) } $db = $this->initDb(); - $tokenExists = $this->fetch($db, 'SELECT 1 FROM rollerworks_passdbl WHERE passwd = :password LIMIT 1', array(':password' => $password)); + $tokenExists = $this->fetch($db, 'SELECT 1 FROM rollerworks_passdbl WHERE passwd = :password LIMIT 1', [':password' => $password]); return !empty($tokenExists); } @@ -151,7 +151,7 @@ abstract protected function initDb(); * * @return mixed */ - protected function fetch($db, $query, array $args = array()) + protected function fetch($db, $query, array $args = []) { $stmt = $this->prepareStatement($db, $query); @@ -170,7 +170,7 @@ protected function fetch($db, $query, array $args = array()) * * @throws \RuntimeException */ - protected function exec($db, $query, array $args = array()) + protected function exec($db, $query, array $args = []) { $stmt = $this->prepareStatement($db, $query); diff --git a/src/Blacklist/SqliteProvider.php b/src/Blacklist/SqliteProvider.php index a65d843..d11fb88 100644 --- a/src/Blacklist/SqliteProvider.php +++ b/src/Blacklist/SqliteProvider.php @@ -77,7 +77,7 @@ protected function initDb() /** * {@inheritdoc} */ - protected function exec($db, $query, array $args = array()) + protected function exec($db, $query, array $args = []) { if ($db instanceof \SQLite3) { $stmt = $this->prepareStatement($db, $query); @@ -98,12 +98,12 @@ protected function exec($db, $query, array $args = array()) /** * {@inheritdoc} */ - protected function fetch($db, $query, array $args = array()) + protected function fetch($db, $query, array $args = []) { - $return = array(); + $return = []; if ($db instanceof \SQLite3) { - $stmt = $this->prepareStatement($db, $query, true); + $stmt = $this->prepareStatement($db, $query); foreach ($args as $arg => $val) { $stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT); } diff --git a/src/Command/BlacklistCommonCommand.php b/src/Command/BlacklistCommonCommand.php index a8b6d20..f60fd93 100644 --- a/src/Command/BlacklistCommonCommand.php +++ b/src/Command/BlacklistCommonCommand.php @@ -11,7 +11,6 @@ namespace Rollerworks\Component\PasswordStrength\Command; -use Rollerworks\Component\PasswordStrength\Blacklist\SqliteProvider; use Rollerworks\Component\PasswordStrength\Blacklist\UpdatableBlacklistProviderInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Command/BlacklistDeleteCommand.php b/src/Command/BlacklistDeleteCommand.php index 9f249a1..91bdb48 100644 --- a/src/Command/BlacklistDeleteCommand.php +++ b/src/Command/BlacklistDeleteCommand.php @@ -11,7 +11,6 @@ namespace Rollerworks\Component\PasswordStrength\Command; -use Rollerworks\Component\PasswordStrength\Blacklist\SqliteProvider; use Rollerworks\Component\PasswordStrength\Blacklist\UpdatableBlacklistProviderInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; diff --git a/src/Command/BlacklistPurgeCommand.php b/src/Command/BlacklistPurgeCommand.php index b782903..51b1276 100644 --- a/src/Command/BlacklistPurgeCommand.php +++ b/src/Command/BlacklistPurgeCommand.php @@ -11,12 +11,9 @@ namespace Rollerworks\Component\PasswordStrength\Command; -use Symfony\Component\Console\Helper\DialogHelper; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; class BlacklistPurgeCommand extends BlacklistCommand diff --git a/src/Validator/Constraints/PasswordRequirementsValidator.php b/src/Validator/Constraints/PasswordRequirementsValidator.php index 7e34bc7..4852cf7 100644 --- a/src/Validator/Constraints/PasswordRequirementsValidator.php +++ b/src/Validator/Constraints/PasswordRequirementsValidator.php @@ -33,7 +33,7 @@ public function validate($value, Constraint $constraint) if ($constraint->minLength > 0 && (mb_strlen($value) < $constraint->minLength)) { $this->context->buildViolation($constraint->tooShortMessage) - ->setParameters(array('{{length}}' => $constraint->minLength)) + ->setParameters(['{{length}}' => $constraint->minLength]) ->setInvalidValue($value) ->addViolation(); } diff --git a/src/Validator/Constraints/PasswordStrength.php b/src/Validator/Constraints/PasswordStrength.php index 4698ae2..09ae39f 100644 --- a/src/Validator/Constraints/PasswordStrength.php +++ b/src/Validator/Constraints/PasswordStrength.php @@ -34,7 +34,7 @@ public function getDefaultOption() public function getRequiredOptions() { - return array('minStrength'); + return ['minStrength']; } public function validatedBy() diff --git a/src/Validator/Constraints/PasswordStrengthValidator.php b/src/Validator/Constraints/PasswordStrengthValidator.php index e3de3f2..f8b21e9 100644 --- a/src/Validator/Constraints/PasswordStrengthValidator.php +++ b/src/Validator/Constraints/PasswordStrengthValidator.php @@ -81,7 +81,7 @@ public function validate($password, Constraint $constraint) if ($passLength < $constraint->minLength) { $this->context->buildViolation($constraint->tooShortMessage) - ->setParameters(array('{{length}}' => $constraint->minLength)) + ->setParameters(['{{length}}' => $constraint->minLength]) ->addViolation(); return; @@ -105,12 +105,12 @@ public function validate($password, Constraint $constraint) // Detecting this is tricky and requires a deep understanding of the syntax. if ($passwordStrength < $constraint->minStrength) { - $parameters = array( + $parameters = [ '{{ length }}' => $constraint->minLength, '{{ min_strength }}' => $this->translator->trans('rollerworks_password.strength_level.'.self::$levelToLabel[$constraint->minStrength], [], 'validators'), '{{ current_strength }}' => $this->translator->trans('rollerworks_password.strength_level.'.self::$levelToLabel[$passwordStrength], [], 'validators'), - '{{ strength_tips }}' => implode(', ', array_map(array($this, 'translateTips'), $tips)), - ); + '{{ strength_tips }}' => implode(', ', array_map([$this, 'translateTips'], $tips)), + ]; $this->context->buildViolation($constraint->message) ->setParameters($parameters) diff --git a/tests/Blacklist/ArrayProviderTest.php b/tests/Blacklist/ArrayProviderTest.php index 198ba52..133c9e8 100644 --- a/tests/Blacklist/ArrayProviderTest.php +++ b/tests/Blacklist/ArrayProviderTest.php @@ -18,7 +18,7 @@ class ArrayProviderTest extends TestCase { public function testBlackList() { - $provider = new ArrayProvider(array('test', 'foobar', 0)); + $provider = new ArrayProvider(['test', 'foobar', 0]); self::assertTrue($provider->isBlacklisted('test')); self::assertTrue($provider->isBlacklisted('foobar')); diff --git a/tests/Blacklist/ChainProviderTest.php b/tests/Blacklist/ChainProviderTest.php index d93c2ad..88fe684 100644 --- a/tests/Blacklist/ChainProviderTest.php +++ b/tests/Blacklist/ChainProviderTest.php @@ -20,8 +20,8 @@ class ChainProviderTest extends TestCase public function testBlackList() { $provider = new ChainProvider(); - $provider->addProvider(new ArrayProvider(array('test', 'foobar', 0))); - $provider->addProvider(new ArrayProvider(array('weak', 'god'))); + $provider->addProvider(new ArrayProvider(['test', 'foobar', 0])); + $provider->addProvider(new ArrayProvider(['weak', 'god'])); self::assertTrue($provider->isBlacklisted('test')); self::assertTrue($provider->isBlacklisted('foobar')); @@ -37,25 +37,25 @@ public function testBlackList() public function testProvidersByConstruct() { - $provider1 = new ArrayProvider(array('test', 'foobar', 0)); - $provider2 = new ArrayProvider(array('weak', 'god')); + $provider1 = new ArrayProvider(['test', 'foobar', 0]); + $provider2 = new ArrayProvider(['weak', 'god']); - $provider = new ChainProvider(array($provider1, $provider2)); + $provider = new ChainProvider([$provider1, $provider2]); - self::assertEquals(array($provider1, $provider2), $provider->getProviders()); + self::assertEquals([$provider1, $provider2], $provider->getProviders()); } public function testGetProviders() { $provider = new ChainProvider(); - $provider1 = new ArrayProvider(array('test', 'foobar', 0)); - $provider2 = new ArrayProvider(array('weak', 'god')); + $provider1 = new ArrayProvider(['test', 'foobar', 0]); + $provider2 = new ArrayProvider(['weak', 'god']); $provider->addProvider($provider1); $provider->addProvider($provider2); - self::assertEquals(array($provider1, $provider2), $provider->getProviders()); + self::assertEquals([$provider1, $provider2], $provider->getProviders()); } public function testNoAssignSelf() diff --git a/tests/Command/BlacklistCommandTestCase.php b/tests/Command/BlacklistCommandTestCase.php index a9ec365..bbf9c50 100644 --- a/tests/Command/BlacklistCommandTestCase.php +++ b/tests/Command/BlacklistCommandTestCase.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Rollerworks\Component\PasswordStrength\Blacklist\SqliteProvider; -use Symfony\Component\DependencyInjection\Container; abstract class BlacklistCommandTestCase extends TestCase { diff --git a/tests/Command/BlacklistDeleteCommandTest.php b/tests/Command/BlacklistDeleteCommandTest.php index d9b8e8d..f8ca19b 100644 --- a/tests/Command/BlacklistDeleteCommandTest.php +++ b/tests/Command/BlacklistDeleteCommandTest.php @@ -28,7 +28,7 @@ public function testDeleteOneWord() self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => 'test')); + $commandTester->execute(['command' => $command->getName(), 'passwords' => 'test']); self::assertFalse(self::$blackListProvider->isBlacklisted('test')); self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); @@ -43,7 +43,7 @@ public function testDeleteNoneExistingWord() self::assertFalse(self::$blackListProvider->isBlacklisted('test')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => 'test')); + $commandTester->execute(['command' => $command->getName(), 'passwords' => 'test']); self::assertFalse(self::$blackListProvider->isBlacklisted('test')); self::assertRegExp('/Successfully removed 0 password\(s\) from your blacklist database/', $commandTester->getDisplay()); @@ -58,7 +58,7 @@ public function testDeleteTwoWords() self::$blackListProvider->add('kaboom'); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => array('test', 'foobar'))); + $commandTester->execute(['command' => $command->getName(), 'passwords' => ['test', 'foobar']]); self::assertFalse(self::$blackListProvider->isBlacklisted('test')); self::assertFalse(self::$blackListProvider->isBlacklisted('foobar')); @@ -72,7 +72,7 @@ public function testNoInput() $command = $this->getCommand(); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName())); + $commandTester->execute(['command' => $command->getName()]); self::assertNotRegExp('/Successfully removed \d+ password\(s\) from your blacklist database/', $commandTester->getDisplay()); self::assertRegExp('/No passwords or file-option given/', $commandTester->getDisplay()); @@ -88,7 +88,7 @@ public function testReadFromFile() $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt']); self::assertRegExp('/Successfully removed 2 password\(s\) from your blacklist database/', $commandTester->getDisplay()); self::assertFalse(self::$blackListProvider->isBlacklisted('test')); @@ -106,14 +106,14 @@ public function testImportExistingFromFile() $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt']); self::assertRegExp('/Successfully removed 2 password\(s\) from your blacklist database/', $commandTester->getDisplay()); self::assertFalse(self::$blackListProvider->isBlacklisted('test')); self::assertFalse(self::$blackListProvider->isBlacklisted('foobar')); self::assertTrue(self::$blackListProvider->isBlacklisted('kaboom')); - $commandTester->execute(array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt']); self::assertRegExp('/Successfully removed 0 password\(s\) from your blacklist database/', $commandTester->getDisplay()); } @@ -130,7 +130,7 @@ public function testImportFromRelFile() // This changes the current working directory to this one so we can check relative files chdir(__DIR__); - $commandTester->execute(array('command' => $command->getName(), '--file' => '../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => '../fixtures/passwords-list1.txt']); self::assertRegExp('/Successfully removed 2 password\(s\) from your blacklist database/', $commandTester->getDisplay()); self::assertFalse(self::$blackListProvider->isBlacklisted('test')); @@ -147,7 +147,7 @@ public function testImportFromNoFile() $commandTester = new CommandTester($command); $commandTester->execute( - array('command' => $command->getName(), '--file' => '../fixtures/unknown.txt') + ['command' => $command->getName(), '--file' => '../fixtures/unknown.txt'] ); self::assertRegExp('#Unable to read passwords list. No such file: \.\./fixtures/unknown\.txt#', $commandTester->getDisplay()); @@ -162,7 +162,7 @@ public function testImportFromEmptyFile() $commandTester = new CommandTester($command); $commandTester->execute( - array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list2.txt') + ['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list2.txt'] ); self::assertRegExp('/Passwords list seems empty, are you sure this is the correct file\?/', $commandTester->getDisplay()); diff --git a/tests/Command/BlacklistListCommandTest.php b/tests/Command/BlacklistListCommandTest.php index fee33b8..fa51b2b 100644 --- a/tests/Command/BlacklistListCommandTest.php +++ b/tests/Command/BlacklistListCommandTest.php @@ -25,7 +25,7 @@ public function testList() $command = $application->find('rollerworks-password:blacklist:list'); - $blackListedWords = array('test', 'foobar', 'kaboom'); + $blackListedWords = ['test', 'foobar', 'kaboom']; foreach ($blackListedWords as $word) { self::$blackListProvider->add($word); @@ -38,7 +38,7 @@ public function testList() $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName())); + $commandTester->execute(['command' => $command->getName()]); $display = $commandTester->getDisplay(true); diff --git a/tests/Command/BlacklistPurgeCommandTest.php b/tests/Command/BlacklistPurgeCommandTest.php index 216aee3..32fa0c5 100644 --- a/tests/Command/BlacklistPurgeCommandTest.php +++ b/tests/Command/BlacklistPurgeCommandTest.php @@ -13,8 +13,6 @@ use Rollerworks\Component\PasswordStrength\Command\BlacklistPurgeCommand; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Helper\DialogHelper; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Tester\CommandTester; class BlacklistPurgeCommandTest extends BlacklistCommandTestCase @@ -32,8 +30,8 @@ public function testWithAsk() self::assertTrue(self::$blackListProvider->isBlacklisted('kaboom')); $commandTester = new CommandTester($command); - $commandTester->setInputs(array('no')); - $commandTester->execute(array('command' => $command->getName()), array('interactive' => true)); + $commandTester->setInputs(['no']); + $commandTester->execute(['command' => $command->getName()], ['interactive' => true]); $display = $commandTester->getDisplay(true); self::assertRegExp('/This will remove all the passwords from your blacklist./', $display); @@ -59,8 +57,8 @@ public function testWithAskConfirm() self::assertTrue(self::$blackListProvider->isBlacklisted('kaboom')); $commandTester = new CommandTester($command); - $commandTester->setInputs(array('y', 'yes')); - $commandTester->execute(array('command' => $command->getName())); + $commandTester->setInputs(['y', 'yes']); + $commandTester->execute(['command' => $command->getName()]); $display = $commandTester->getDisplay(true); self::assertRegExp('/This will remove all the passwords from your blacklist\./', $display); @@ -86,7 +84,7 @@ public function testNoAsk() self::assertTrue(self::$blackListProvider->isBlacklisted('kaboom')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), '--no-ask' => null)); + $commandTester->execute(['command' => $command->getName(), '--no-ask' => null]); self::assertRegExp('/Successfully removed all passwords from your blacklist\./', $commandTester->getDisplay(true)); diff --git a/tests/Command/BlacklistUpdateCommandTest.php b/tests/Command/BlacklistUpdateCommandTest.php index e0547c3..ac6ea74 100644 --- a/tests/Command/BlacklistUpdateCommandTest.php +++ b/tests/Command/BlacklistUpdateCommandTest.php @@ -24,7 +24,7 @@ public function testAddOneWord() self::assertFalse(self::$blackListProvider->isBlacklisted('test')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => 'test')); + $commandTester->execute(['command' => $command->getName(), 'passwords' => 'test']); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertRegExp('/Successfully added 1 password\(s\) to your blacklist database/', $commandTester->getDisplay()); @@ -37,13 +37,13 @@ public function testAddExistingWord() self::assertFalse(self::$blackListProvider->isBlacklisted('test')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => 'test')); + $commandTester->execute(['command' => $command->getName(), 'passwords' => 'test']); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertRegExp('/Successfully added 1 password\(s\) to your blacklist database/', $commandTester->getDisplay()); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => 'test')); + $commandTester->execute(['command' => $command->getName(), 'passwords' => 'test']); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertRegExp('/Successfully added 0 password\(s\) to your blacklist database/', $commandTester->getDisplay()); @@ -57,7 +57,7 @@ public function testAddTwoWords() self::assertFalse(self::$blackListProvider->isBlacklisted('foobar')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), 'passwords' => array('test', 'foobar'))); + $commandTester->execute(['command' => $command->getName(), 'passwords' => ['test', 'foobar']]); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); @@ -69,7 +69,7 @@ public function testNoInput() $command = $this->getCommand(); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName())); + $commandTester->execute(['command' => $command->getName()]); self::assertNotRegExp('/Successfully added \d+ password\(s\) to your blacklist database/', $commandTester->getDisplay()); self::assertRegExp('/No passwords or file-option given/', $commandTester->getDisplay()); @@ -83,7 +83,7 @@ public function testImportFromFile() self::assertFalse(self::$blackListProvider->isBlacklisted('foobar')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt']); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); @@ -98,7 +98,7 @@ public function testImportExistingFromFile() self::assertFalse(self::$blackListProvider->isBlacklisted('foobar')); $commandTester = new CommandTester($command); - $commandTester->execute(array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt']); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); @@ -106,7 +106,7 @@ public function testImportExistingFromFile() self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); - $commandTester->execute(array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt')); + $commandTester->execute(['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list1.txt']); self::assertTrue(self::$blackListProvider->isBlacklisted('test')); self::assertTrue(self::$blackListProvider->isBlacklisted('foobar')); @@ -125,7 +125,7 @@ public function testImportFromRelFile() $commandTester = new CommandTester($command); $commandTester->execute( - array('command' => $command->getName(), '--file' => '../fixtures/passwords-list1.txt') + ['command' => $command->getName(), '--file' => '../fixtures/passwords-list1.txt'] ); self::assertRegExp('/Successfully added 2 password\(s\) to your blacklist database/', $commandTester->getDisplay()); @@ -142,7 +142,7 @@ public function testImportFromNoFile() $commandTester = new CommandTester($command); $commandTester->execute( - array('command' => $command->getName(), '--file' => '../fixtures/unknown.txt') + ['command' => $command->getName(), '--file' => '../fixtures/unknown.txt'] ); self::assertRegExp('#Unable to read passwords list. No such file: \.\./fixtures/unknown\.txt#', $commandTester->getDisplay()); @@ -157,7 +157,7 @@ public function testImportFromEmptyFile() $commandTester = new CommandTester($command); $commandTester->execute( - array('command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list2.txt') + ['command' => $command->getName(), '--file' => __DIR__.'/../fixtures/passwords-list2.txt'] ); self::assertRegExp('/Passwords list seems empty, are you sure this is the correct file\?/', $commandTester->getDisplay()); diff --git a/tests/Validator/BlacklistValidationTest.php b/tests/Validator/BlacklistValidationTest.php index 95bfdb9..545862c 100644 --- a/tests/Validator/BlacklistValidationTest.php +++ b/tests/Validator/BlacklistValidationTest.php @@ -14,12 +14,11 @@ use Rollerworks\Component\PasswordStrength\Blacklist\ArrayProvider; use Rollerworks\Component\PasswordStrength\Validator\Constraints\Blacklist; use Rollerworks\Component\PasswordStrength\Validator\Constraints\BlacklistValidator; -use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; -use Symfony\Component\Validator\Validation; +use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -class BlacklistValidationTest extends AbstractConstraintValidatorTest +class BlacklistValidationTest extends ConstraintValidatorTestCase { - public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) + public function getMock($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) { if (func_num_args() === 1 && preg_match('/^Symfony\\\\Component\\\\([a-z]+\\\\)+[a-z]+Interface$/i', $originalClassName)) { return $this->getMockBuilder($originalClassName)->getMock(); @@ -41,7 +40,7 @@ public function getMock($originalClassName, $methods = array(), array $arguments protected function createValidator() { - $provider = new ArrayProvider(array('test', 'foobar')); + $provider = new ArrayProvider(['test', 'foobar']); return new BlacklistValidator($provider); } @@ -79,9 +78,9 @@ public function testNotBlackListed() public function testBlackListed() { - $constraint = new Blacklist(array( + $constraint = new Blacklist([ 'message' => 'myMessage', - )); + ]); $this->validator->validate('test', $constraint); $this->buildViolation('myMessage') diff --git a/tests/Validator/PasswordRequirementsValidatorTest.php b/tests/Validator/PasswordRequirementsValidatorTest.php index a795aab..b09c56d 100644 --- a/tests/Validator/PasswordRequirementsValidatorTest.php +++ b/tests/Validator/PasswordRequirementsValidatorTest.php @@ -13,12 +13,12 @@ use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordRequirements; use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordRequirementsValidator; -use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; -use Symfony\Component\Validator\Validation; +use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; +use Symfony\Component\Validator\Test\ConstraintViolationAssertion; -class PasswordRequirementsValidatorTest extends AbstractConstraintValidatorTest +class PasswordRequirementsValidatorTest extends ConstraintValidatorTestCase { - public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) + public function getMock($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) { if (func_num_args() === 1 && preg_match('/^Symfony\\\\Component\\\\([a-z]+\\\\)+[a-z]+Interface$/i', $originalClassName)) { return $this->getMockBuilder($originalClassName)->getMock(); @@ -79,20 +79,22 @@ public function testValidValueConstraints($value, PasswordRequirements $constrai * @param PasswordRequirements $constraint * @param array $violations */ - public function testViolationValueConstraints($value, PasswordRequirements $constraint, array $violations = array()) + public function testViolationValueConstraints($value, PasswordRequirements $constraint, array $violations = []) { $this->value = $value; + /** @var ConstraintViolationAssertion $constraintViolationAssertion */ + $constraintViolationAssertion = null; // Shut-up PHPStan $this->validator->validate($value, $constraint); foreach ($violations as $i => $violation) { - if ($i == 0) { + if ($i === 0) { $constraintViolationAssertion = $this->buildViolation($violation[0]) - ->setParameters(isset($violation[1]) ? $violation[1] : array()) + ->setParameters(isset($violation[1]) ? $violation[1] : []) ->setInvalidValue($value); } else { $constraintViolationAssertion = $constraintViolationAssertion->buildNextViolation($violation[0]) - ->setParameters(isset($violation[1]) ? $violation[1] : array()) + ->setParameters(isset($violation[1]) ? $violation[1] : []) ->setInvalidValue($value); } if ($i == count($violations) - 1) { @@ -103,47 +105,47 @@ public function testViolationValueConstraints($value, PasswordRequirements $cons public function provideValidConstraints() { - return array( - array('test', new PasswordRequirements(array('minLength' => 3))), - array('1234567', new PasswordRequirements(array('requireLetters' => false))), - array('1234567', new PasswordRequirements(array('requireLetters' => false))), - array('aBcDez', new PasswordRequirements(array('requireCaseDiff' => true))), - array('abcdef', new PasswordRequirements(array('requireNumbers' => false))), - array('123456', new PasswordRequirements(array('requireLetters' => false, 'requireNumbers' => true))), - array('123456789', new PasswordRequirements(array('requireLetters' => false, 'requireNumbers' => true))), - array('abcd12345', new PasswordRequirements(array('requireLetters' => true, 'requireNumbers' => true))), - array('1234abc56789', new PasswordRequirements(array('requireLetters' => true, 'requireNumbers' => true))), - - array('®', new PasswordRequirements(array('minLength' => 1, 'requireLetters' => false, 'requireSpecialCharacter' => true))), - array('»', new PasswordRequirements(array('minLength' => 1, 'requireLetters' => false, 'requireSpecialCharacter' => true))), - array('<>', new PasswordRequirements(array('minLength' => 1, 'requireLetters' => false, 'requireSpecialCharacter' => true))), - ); + return [ + ['test', new PasswordRequirements(['minLength' => 3])], + ['1234567', new PasswordRequirements(['requireLetters' => false])], + ['1234567', new PasswordRequirements(['requireLetters' => false])], + ['aBcDez', new PasswordRequirements(['requireCaseDiff' => true])], + ['abcdef', new PasswordRequirements(['requireNumbers' => false])], + ['123456', new PasswordRequirements(['requireLetters' => false, 'requireNumbers' => true])], + ['123456789', new PasswordRequirements(['requireLetters' => false, 'requireNumbers' => true])], + ['abcd12345', new PasswordRequirements(['requireLetters' => true, 'requireNumbers' => true])], + ['1234abc56789', new PasswordRequirements(['requireLetters' => true, 'requireNumbers' => true])], + + ['®', new PasswordRequirements(['minLength' => 1, 'requireLetters' => false, 'requireSpecialCharacter' => true])], + ['»', new PasswordRequirements(['minLength' => 1, 'requireLetters' => false, 'requireSpecialCharacter' => true])], + ['<>', new PasswordRequirements(['minLength' => 1, 'requireLetters' => false, 'requireSpecialCharacter' => true])], + ]; } public function provideViolationConstraints() { $constraint = new PasswordRequirements(); - return array( - array('1', new PasswordRequirements(array('minLength' => 2, 'requireLetters' => false)), array( - array($constraint->tooShortMessage, array('{{length}}' => 2)), - )), - array('test', new PasswordRequirements(array('requireLetters' => true)), array( - array($constraint->tooShortMessage, array('{{length}}' => $constraint->minLength)), - )), - array('123456', new PasswordRequirements(array('requireLetters' => true)), array( - array($constraint->missingLettersMessage), - )), - array('abcdez', new PasswordRequirements(array('requireCaseDiff' => true)), array( - array($constraint->requireCaseDiffMessage), - )), - array('!@#$%^&*()-', new PasswordRequirements(array('requireLetters' => true, 'requireNumbers' => true)), array( - array($constraint->missingLettersMessage), - array($constraint->missingNumbersMessage), - )), - array('aerfghy', new PasswordRequirements(array('requireLetters' => false, 'requireSpecialCharacter' => true)), array( - array($constraint->missingSpecialCharacterMessage), - )), - ); + return [ + ['1', new PasswordRequirements(['minLength' => 2, 'requireLetters' => false]), [ + [$constraint->tooShortMessage, ['{{length}}' => 2]], + ]], + ['test', new PasswordRequirements(['requireLetters' => true]), [ + [$constraint->tooShortMessage, ['{{length}}' => $constraint->minLength]], + ]], + ['123456', new PasswordRequirements(['requireLetters' => true]), [ + [$constraint->missingLettersMessage], + ]], + ['abcdez', new PasswordRequirements(['requireCaseDiff' => true]), [ + [$constraint->requireCaseDiffMessage], + ]], + ['!@#$%^&*()-', new PasswordRequirements(['requireLetters' => true, 'requireNumbers' => true]), [ + [$constraint->missingLettersMessage], + [$constraint->missingNumbersMessage], + ]], + ['aerfghy', new PasswordRequirements(['requireLetters' => false, 'requireSpecialCharacter' => true]), [ + [$constraint->missingSpecialCharacterMessage], + ]], + ]; } } diff --git a/tests/Validator/PasswordStrengthTest.php b/tests/Validator/PasswordStrengthTest.php index 73a5293..7887283 100644 --- a/tests/Validator/PasswordStrengthTest.php +++ b/tests/Validator/PasswordStrengthTest.php @@ -14,23 +14,22 @@ use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrength; use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrengthValidator; use Symfony\Component\Translation\Translator; -use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; -use Symfony\Component\Validator\Validation; +use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -class PasswordStrengthTest extends AbstractConstraintValidatorTest +class PasswordStrengthTest extends ConstraintValidatorTestCase { /** * @var array */ - private static $levelToLabel = array( + private static $levelToLabel = [ 1 => 'very_weak', 2 => 'weak', 3 => 'medium', 4 => 'strong', 5 => 'very_strong', - ); + ]; - public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) + public function getMock($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) { if (func_num_args() === 1 && preg_match('/^Symfony\\\\Component\\\\([a-z]+\\\\)+[a-z]+Interface$/i', $originalClassName)) { return $this->getMockBuilder($originalClassName)->getMock(); @@ -81,28 +80,28 @@ public function getWeakPasswords() { $pre = 'rollerworks_password.tip.'; - return array( + return [ // Very weak - array(2, 'weaker', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"), - array(2, '123456', 1, "{$pre}letters, {$pre}special_chars, {$pre}length"), - array(2, 'foobar', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"), - array(2, '!.!.!.', 1, "{$pre}letters, {$pre}numbers, {$pre}length"), + [2, 'weaker', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"], + [2, '123456', 1, "{$pre}letters, {$pre}special_chars, {$pre}length"], + [2, 'foobar', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"], + [2, '!.!.!.', 1, "{$pre}letters, {$pre}numbers, {$pre}length"], // Weak - array(3, 'wee6eak', 2, "{$pre}uppercase_letters, {$pre}special_chars, {$pre}length"), - array(3, 'foobar!', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}length"), - array(3, 'Foobar', 2, "{$pre}numbers, {$pre}special_chars, {$pre}length"), - array(3, '123456!', 2, "{$pre}letters, {$pre}length"), - array(3, '7857375923752947', 2, "{$pre}letters, {$pre}special_chars"), - array(3, 'FSDFJSLKFFSDFDSF', 2, "{$pre}lowercase_letters, {$pre}numbers, {$pre}special_chars"), - array(3, 'fjsfjdljfsjsjjlsj', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars"), + [3, 'wee6eak', 2, "{$pre}uppercase_letters, {$pre}special_chars, {$pre}length"], + [3, 'foobar!', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}length"], + [3, 'Foobar', 2, "{$pre}numbers, {$pre}special_chars, {$pre}length"], + [3, '123456!', 2, "{$pre}letters, {$pre}length"], + [3, '7857375923752947', 2, "{$pre}letters, {$pre}special_chars"], + [3, 'FSDFJSLKFFSDFDSF', 2, "{$pre}lowercase_letters, {$pre}numbers, {$pre}special_chars"], + [3, 'fjsfjdljfsjsjjlsj', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars"], // Medium - array(4, 'Foobar!', 3, "{$pre}numbers, {$pre}length"), - array(4, 'foo-b0r!', 3, "{$pre}uppercase_letters, {$pre}length"), - array(4, 'fjsfjdljfsjsjjls1', 3, "{$pre}uppercase_letters, {$pre}special_chars"), - array(4, '785737592375294b', 3, "{$pre}uppercase_letters, {$pre}special_chars"), - ); + [4, 'Foobar!', 3, "{$pre}numbers, {$pre}length"], + [4, 'foo-b0r!', 3, "{$pre}uppercase_letters, {$pre}length"], + [4, 'fjsfjdljfsjsjjls1', 3, "{$pre}uppercase_letters, {$pre}special_chars"], + [4, '785737592375294b', 3, "{$pre}uppercase_letters, {$pre}special_chars"], + ]; } public function getWeakPasswordsUnicode() @@ -111,61 +110,61 @@ public function getWeakPasswordsUnicode() // \u{FD3E} = ﴾ = Arabic ornate left parenthesis - return array( + return [ // Very weak - array(2, 'weaker', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"), - array(2, '123456', 1, "{$pre}letters, {$pre}special_chars, {$pre}length"), - array(2, '²²²²²²', 1, "{$pre}letters, {$pre}special_chars, {$pre}length"), - array(2, 'foobar', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"), - array(2, 'ömgwat', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"), - array(2, '!.!.!.', 1, "{$pre}letters, {$pre}numbers, {$pre}length"), - array(2, '!.!.!﴾', 1, "{$pre}letters, {$pre}numbers, {$pre}length"), + [2, 'weaker', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"], + [2, '123456', 1, "{$pre}letters, {$pre}special_chars, {$pre}length"], + [2, '²²²²²²', 1, "{$pre}letters, {$pre}special_chars, {$pre}length"], + [2, 'foobar', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"], + [2, 'ömgwat', 1, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars, {$pre}length"], + [2, '!.!.!.', 1, "{$pre}letters, {$pre}numbers, {$pre}length"], + [2, '!.!.!﴾', 1, "{$pre}letters, {$pre}numbers, {$pre}length"], // Weak - array(3, 'wee6eak', 2, "{$pre}uppercase_letters, {$pre}special_chars, {$pre}length"), - array(3, 'foobar!', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}length"), - array(3, 'Foobar', 2, "{$pre}numbers, {$pre}special_chars, {$pre}length"), - array(3, '123456!', 2, "{$pre}letters, {$pre}length"), - array(3, '7857375923752947', 2, "{$pre}letters, {$pre}special_chars"), - array(3, 'FSDFJSLKFFSDFDSF', 2, "{$pre}lowercase_letters, {$pre}numbers, {$pre}special_chars"), - array(3, 'FÜKFJSLKFFSDFDSF', 2, "{$pre}lowercase_letters, {$pre}numbers, {$pre}special_chars"), - array(3, 'fjsfjdljfsjsjjlsj', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars"), + [3, 'wee6eak', 2, "{$pre}uppercase_letters, {$pre}special_chars, {$pre}length"], + [3, 'foobar!', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}length"], + [3, 'Foobar', 2, "{$pre}numbers, {$pre}special_chars, {$pre}length"], + [3, '123456!', 2, "{$pre}letters, {$pre}length"], + [3, '7857375923752947', 2, "{$pre}letters, {$pre}special_chars"], + [3, 'FSDFJSLKFFSDFDSF', 2, "{$pre}lowercase_letters, {$pre}numbers, {$pre}special_chars"], + [3, 'FÜKFJSLKFFSDFDSF', 2, "{$pre}lowercase_letters, {$pre}numbers, {$pre}special_chars"], + [3, 'fjsfjdljfsjsjjlsj', 2, "{$pre}uppercase_letters, {$pre}numbers, {$pre}special_chars"], // Medium - array(4, 'Foobar﴾', 3, "{$pre}numbers, {$pre}length"), - array(4, 'foo-b0r!', 3, "{$pre}uppercase_letters, {$pre}length"), - array(4, 'fjsfjdljfsjsjjls1', 3, "{$pre}uppercase_letters, {$pre}special_chars"), - array(4, '785737592375294b', 3, "{$pre}uppercase_letters, {$pre}special_chars"), - ); + [4, 'Foobar﴾', 3, "{$pre}numbers, {$pre}length"], + [4, 'foo-b0r!', 3, "{$pre}uppercase_letters, {$pre}length"], + [4, 'fjsfjdljfsjsjjls1', 3, "{$pre}uppercase_letters, {$pre}special_chars"], + [4, '785737592375294b', 3, "{$pre}uppercase_letters, {$pre}special_chars"], + ]; } public static function getStrongPasswords() { - return array( - array('Foobar!55!'), - array('Foobar$55'), - array('Foobar€55'), - array('Foobar€55'), - ); + return [ + ['Foobar!55!'], + ['Foobar$55'], + ['Foobar€55'], + ['Foobar€55'], + ]; } public static function getVeryStrongPasswords() { - return array( - array('Foobar$55_4&F'), - array('L33RoyJ3Jenkins!'), - ); + return [ + ['Foobar$55_4&F'], + ['L33RoyJ3Jenkins!'], + ]; } public function testShortPasswordWillNotPass() { - $constraint = new PasswordStrength(array('minStrength' => 5, 'minLength' => 6)); + $constraint = new PasswordStrength(['minStrength' => 5, 'minLength' => 6]); $this->validator->validate('foo', $constraint); - $parameters = array( + $parameters = [ '{{length}}' => 6, - ); + ]; $this->buildViolation('Your password must be at least {{length}} characters long.') ->setParameters($parameters) @@ -174,13 +173,13 @@ public function testShortPasswordWillNotPass() public function testShortPasswordInMultiByteWillNotPass() { - $constraint = new PasswordStrength(array('minStrength' => 5, 'minLength' => 7)); + $constraint = new PasswordStrength(['minStrength' => 5, 'minLength' => 7]); $this->validator->validate('foöled', $constraint); - $parameters = array( + $parameters = [ '{{length}}' => 7, - ); + ]; $this->buildViolation('Your password must be at least {{length}} characters long.') ->setParameters($parameters) @@ -192,16 +191,16 @@ public function testShortPasswordInMultiByteWillNotPass() */ public function testWeakPasswordsWillNotPass($minStrength, $value, $currentStrength, $tips = '') { - $constraint = new PasswordStrength(array('minStrength' => $minStrength, 'minLength' => 6)); + $constraint = new PasswordStrength(['minStrength' => $minStrength, 'minLength' => 6]); $this->validator->validate($value, $constraint); - $parameters = array( + $parameters = [ '{{ length }}' => 6, '{{ min_strength }}' => 'rollerworks_password.strength_level.'.self::$levelToLabel[$minStrength], '{{ current_strength }}' => 'rollerworks_password.strength_level.'.self::$levelToLabel[$currentStrength], '{{ strength_tips }}' => $tips, - ); + ]; $this->buildViolation('password_too_weak') ->setParameters($parameters) @@ -213,16 +212,16 @@ public function testWeakPasswordsWillNotPass($minStrength, $value, $currentStren */ public function testWeakPasswordsWithUnicodeWillNotPass($minStrength, $value, $currentStrength, $tips = '') { - $constraint = new PasswordStrength(array('minStrength' => $minStrength, 'minLength' => 6, 'unicodeEquality' => true)); + $constraint = new PasswordStrength(['minStrength' => $minStrength, 'minLength' => 6, 'unicodeEquality' => true]); $this->validator->validate($value, $constraint); - $parameters = array( + $parameters = [ '{{ length }}' => 6, '{{ min_strength }}' => 'rollerworks_password.strength_level.'.self::$levelToLabel[$minStrength], '{{ current_strength }}' => 'rollerworks_password.strength_level.'.self::$levelToLabel[$currentStrength], '{{ strength_tips }}' => $tips, - ); + ]; $this->buildViolation('password_too_weak') ->setParameters($parameters) @@ -253,16 +252,16 @@ public function testParametersAreTranslatedWhenTranslatorIsMissing() $this->validator = new PasswordStrengthValidator(); $this->validator->initialize($this->context); - $constraint = new PasswordStrength(array('minStrength' => 5, 'minLength' => 6)); + $constraint = new PasswordStrength(['minStrength' => 5, 'minLength' => 6]); $this->validator->validate('FD43f.!', $constraint); - $parameters = array( + $parameters = [ '{{ length }}' => 6, '{{ current_strength }}' => 'Strong', '{{ min_strength }}' => 'Very strong', '{{ strength_tips }}' => 'add more characters', - ); + ]; $this->buildViolation('password_too_weak') ->setParameters($parameters)