skip bcrypt tests on incompatible platforms
Not all PHP versions before 5.3.7 have backported fixes that make it possible to use `password_hash()` function. Therefore, we have to skip tests on not supported platforms.
This commit is contained in:
parent
0c2f1d94de
commit
65eb18849a
@ -47,6 +47,8 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testResultLength()
|
public function testResultLength()
|
||||||
{
|
{
|
||||||
|
$this->skipIfPhpVersionIsNotSupported();
|
||||||
|
|
||||||
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
|
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
|
||||||
$result = $encoder->encodePassword(self::PASSWORD, null);
|
$result = $encoder->encodePassword(self::PASSWORD, null);
|
||||||
$this->assertEquals(60, strlen($result));
|
$this->assertEquals(60, strlen($result));
|
||||||
@ -54,6 +56,8 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidation()
|
public function testValidation()
|
||||||
{
|
{
|
||||||
|
$this->skipIfPhpVersionIsNotSupported();
|
||||||
|
|
||||||
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
|
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
|
||||||
$result = $encoder->encodePassword(self::PASSWORD, null);
|
$result = $encoder->encodePassword(self::PASSWORD, null);
|
||||||
$this->assertTrue($encoder->isPasswordValid($result, self::PASSWORD, null));
|
$this->assertTrue($encoder->isPasswordValid($result, self::PASSWORD, null));
|
||||||
@ -72,10 +76,19 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckPasswordLength()
|
public function testCheckPasswordLength()
|
||||||
{
|
{
|
||||||
|
$this->skipIfPhpVersionIsNotSupported();
|
||||||
|
|
||||||
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
|
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
|
||||||
$result = $encoder->encodePassword(str_repeat('a', 72), null);
|
$result = $encoder->encodePassword(str_repeat('a', 72), null);
|
||||||
|
|
||||||
$this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt'));
|
$this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt'));
|
||||||
$this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt'));
|
$this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function skipIfPhpVersionIsNotSupported()
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50307 && !\PasswordCompat\binary\check()) {
|
||||||
|
$this->markTestSkipped('Skipping test as this PHP version is not compatible with the ircmaxell/password-compat library.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user