Skip to content

Commit

Permalink
chore: update tests for phpunit 10 and 11 (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud authored Dec 7, 2024
1 parent a6f8c86 commit 715edf9
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions tests/CryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PHPUnit\Framework\TestCase;
use Rancoud\Crypt\Crypt;
use Rancoud\Crypt\CryptException;
Expand All @@ -12,6 +14,7 @@
* @runTestsInSeparateProcesses
* Class CryptTest.
*/
#[RunTestsInSeparateProcesses]
class CryptTest extends TestCase
{
// region Set specific algo
Expand All @@ -35,19 +38,19 @@ public function testUseArgon2id(): void

// region Hash / Verify / Needs Rehash

public function dataCasesGeneric(): array
public static function dataCasesGeneric(): array
{
return [
'Argon2id' => [
'use_algo' => 'useArgon2id',
'useAlgo' => 'useArgon2id',
'password' => 'my_password_argon_2id',
],
'Argon2i' => [
'use_algo' => 'useArgon2i',
'useAlgo' => 'useArgon2i',
'password' => 'my_password_argon_2i',
],
'Bcrypt' => [
'use_algo' => 'useBcrypt',
'useAlgo' => 'useBcrypt',
'password' => 'my_password_bcrypt',
],
];
Expand All @@ -61,6 +64,7 @@ public function dataCasesGeneric(): array
*
* @throws CryptException
*/
#[DataProvider('dataCasesGeneric')]
public function testHash(string $useAlgo, string $password): void
{
Crypt::$useAlgo();
Expand All @@ -76,6 +80,7 @@ public function testHash(string $useAlgo, string $password): void
*
* @throws CryptException
*/
#[DataProvider('dataCasesGeneric')]
public function testVerifyValid(string $useAlgo, string $password): void
{
Crypt::$useAlgo();
Expand All @@ -94,6 +99,7 @@ public function testVerifyValid(string $useAlgo, string $password): void
*
* @throws CryptException
*/
#[DataProvider('dataCasesGeneric')]
public function testVerifyInvalid(string $useAlgo, string $password): void
{
Crypt::$useAlgo();
Expand All @@ -112,6 +118,7 @@ public function testVerifyInvalid(string $useAlgo, string $password): void
*
* @throws CryptException
*/
#[DataProvider('dataCasesGeneric')]
public function testNeedsRehash(string $useAlgo, string $password): void
{
Crypt::$useAlgo();
Expand All @@ -133,23 +140,23 @@ public function testNeedsRehash(string $useAlgo, string $password): void
static::assertTrue($needsRehash);
}

public function dataCasesHashFailure(): array
public static function dataCasesHashFailure(): array
{
return [
'Argon2id' => [
'use_algo' => 'useArgon2id',
'password' => 'my_password_argon_2id',
'error_message' => 'Hash Failure',
'useAlgo' => 'useArgon2id',
'password' => 'my_password_argon_2id',
'errorMessage' => 'Hash Failure',
],
'Argon2i' => [
'use_algo' => 'useArgon2i',
'password' => 'my_password_argon_2i',
'error_message' => 'Hash Failure',
'useAlgo' => 'useArgon2i',
'password' => 'my_password_argon_2i',
'errorMessage' => 'Hash Failure',
],
'Bcrypt' => [
'use_algo' => 'useBcrypt',
'password' => 'azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiop',
'error_message' => 'Password too long',
'useAlgo' => 'useBcrypt',
'password' => 'azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiop',
'errorMessage' => 'Password too long',
]
];
}
Expand All @@ -163,6 +170,7 @@ public function dataCasesHashFailure(): array
*
* @throws CryptException
*/
#[DataProvider('dataCasesHashFailure')]
public function testHashFailure(string $useAlgo, string $password, string $errorMessage): void
{
Crypt::$useAlgo();
Expand Down

0 comments on commit 715edf9

Please sign in to comment.