Working state but no uploads
This commit is contained in:
@@ -18,6 +18,7 @@ use Tests\ControllerTestCase;
|
||||
* mots de passe non identiques, mot de passe faible, mot de passe actuel
|
||||
* incorrect, erreur inattendue et succès.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class AccountControllerTest extends ControllerTestCase
|
||||
{
|
||||
/** @var \Slim\Views\Twig&MockObject */
|
||||
|
||||
@@ -18,6 +18,7 @@ use Tests\ControllerTestCase;
|
||||
* AuthService, FlashService et Twig sont mockés — aucune session PHP,
|
||||
* aucune base de données, aucun serveur HTTP n'est requis.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class AuthControllerTest extends ControllerTestCase
|
||||
{
|
||||
/** @var \Slim\Views\Twig&MockObject */
|
||||
|
||||
@@ -19,6 +19,7 @@ use PHPUnit\Framework\TestCase;
|
||||
* - MAX_ATTEMPTS = 5 : nombre d'échecs avant verrouillage
|
||||
* - LOCK_MINUTES = 15 : durée du verrouillage en minutes
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class AuthServiceRateLimitTest extends TestCase
|
||||
{
|
||||
/** @var UserRepositoryInterface&MockObject */
|
||||
|
||||
@@ -21,6 +21,7 @@ use PHPUnit\Framework\TestCase;
|
||||
* Les dépendances sont remplacées par des mocks via leurs interfaces pour
|
||||
* isoler le service.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class AuthServiceTest extends TestCase
|
||||
{
|
||||
/** @var UserRepositoryInterface&MockObject */
|
||||
@@ -58,7 +59,7 @@ final class AuthServiceTest extends TestCase
|
||||
$password = 'motdepasse1';
|
||||
$user = $this->makeUser('alice', 'alice@example.com', $password);
|
||||
|
||||
$this->userRepository->method('findByUsername')->with('alice')->willReturn($user);
|
||||
$this->userRepository->expects($this->once())->method('findByUsername')->with('alice')->willReturn($user);
|
||||
|
||||
$result = $this->service->authenticate('alice', $password);
|
||||
|
||||
@@ -73,7 +74,7 @@ final class AuthServiceTest extends TestCase
|
||||
$password = 'motdepasse1';
|
||||
$user = $this->makeUser('alice', 'alice@example.com', $password);
|
||||
|
||||
$this->userRepository->method('findByUsername')->with('alice')->willReturn($user);
|
||||
$this->userRepository->expects($this->once())->method('findByUsername')->with('alice')->willReturn($user);
|
||||
|
||||
$result = $this->service->authenticate('ALICE', $password);
|
||||
|
||||
@@ -116,7 +117,7 @@ final class AuthServiceTest extends TestCase
|
||||
$password = 'ancienmdp1';
|
||||
$user = $this->makeUser('alice', 'alice@example.com', $password, 1);
|
||||
|
||||
$this->userRepository->method('findById')->with(1)->willReturn($user);
|
||||
$this->userRepository->expects($this->once())->method('findById')->with(1)->willReturn($user);
|
||||
$this->userRepository->expects($this->once())->method('updatePassword')->with(1);
|
||||
|
||||
$this->service->changePassword(1, $password, 'nouveaumdp1');
|
||||
|
||||
@@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase;
|
||||
* PDO et PDOStatement sont mockés pour isoler complètement
|
||||
* le dépôt de la base de données.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class LoginAttemptRepositoryTest extends TestCase
|
||||
{
|
||||
/** @var PDO&MockObject */
|
||||
|
||||
@@ -15,6 +15,8 @@ use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Slim\Psr7\Factory\ServerRequestFactory;
|
||||
use Slim\Psr7\Response;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class MiddlewareTest extends TestCase
|
||||
{
|
||||
/** @var SessionManagerInterface&MockObject */
|
||||
|
||||
@@ -27,6 +27,7 @@ use Tests\ControllerTestCase;
|
||||
* - showReset() valide le token avant d'afficher le formulaire
|
||||
* - reset() couvre 5 chemins de sortie (token vide, mismatch, trop court, invalide, succès)
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class PasswordResetControllerTest extends ControllerTestCase
|
||||
{
|
||||
/** @var \Slim\Views\Twig&MockObject */
|
||||
|
||||
@@ -19,6 +19,7 @@ use PHPUnit\Framework\TestCase;
|
||||
* PDO et PDOStatement sont mockés pour isoler complètement
|
||||
* le dépôt de la base de données.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class PasswordResetRepositoryTest extends TestCase
|
||||
{
|
||||
/** @var PDO&MockObject */
|
||||
@@ -60,7 +61,7 @@ final class PasswordResetRepositoryTest extends TestCase
|
||||
$expiresAt = date('Y-m-d H:i:s', time() + 3600);
|
||||
$stmt = $this->stmtOk();
|
||||
|
||||
$this->db->method('prepare')
|
||||
$this->db->expects($this->once())->method('prepare')
|
||||
->with($this->stringContains('INSERT INTO password_resets'))
|
||||
->willReturn($stmt);
|
||||
|
||||
@@ -162,7 +163,7 @@ final class PasswordResetRepositoryTest extends TestCase
|
||||
$userId = 42;
|
||||
$stmt = $this->stmtOk();
|
||||
|
||||
$this->db->method('prepare')
|
||||
$this->db->expects($this->once())->method('prepare')
|
||||
->with($this->stringContains('UPDATE password_resets'))
|
||||
->willReturn($stmt);
|
||||
|
||||
@@ -200,7 +201,7 @@ final class PasswordResetRepositoryTest extends TestCase
|
||||
public function testInvalidateByUserIdNeverCallsDelete(): void
|
||||
{
|
||||
$stmt = $this->stmtOk();
|
||||
$this->db->method('prepare')
|
||||
$this->db->expects($this->once())->method('prepare')
|
||||
->with($this->stringContains('UPDATE'))
|
||||
->willReturn($stmt);
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ use App\User\UserRepository;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class PasswordResetServiceIntegrationTest extends TestCase
|
||||
{
|
||||
private PDO $db;
|
||||
|
||||
@@ -20,6 +20,7 @@ use PHPUnit\Framework\TestCase;
|
||||
* Vérifie la génération de token, la validation et la réinitialisation
|
||||
* du mot de passe. Les dépendances sont mockées via leurs interfaces.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class PasswordResetServiceTest extends TestCase
|
||||
{
|
||||
/** @var PasswordResetRepositoryInterface&MockObject */
|
||||
@@ -95,7 +96,7 @@ final class PasswordResetServiceTest extends TestCase
|
||||
$this->resetRepository->method('invalidateByUserId');
|
||||
$this->resetRepository->expects($this->once())
|
||||
->method('create')
|
||||
->with($user->getId(), $this->isType('string'), $this->isType('string'));
|
||||
->with($user->getId(), $this->callback('is_string'), $this->callback('is_string'));
|
||||
$this->mailService->method('send');
|
||||
|
||||
$this->service->requestReset('alice@example.com', 'https://blog.exemple.com');
|
||||
@@ -116,9 +117,9 @@ final class PasswordResetServiceTest extends TestCase
|
||||
->method('send')
|
||||
->with(
|
||||
'alice@example.com',
|
||||
$this->isType('string'),
|
||||
$this->callback('is_string'),
|
||||
'emails/password-reset.twig',
|
||||
$this->isType('array'),
|
||||
$this->callback('is_array'),
|
||||
);
|
||||
|
||||
$this->service->requestReset('alice@example.com', 'https://blog.exemple.com');
|
||||
@@ -173,7 +174,7 @@ final class PasswordResetServiceTest extends TestCase
|
||||
$tokenRaw = 'montokenbrut';
|
||||
$tokenHash = hash('sha256', $tokenRaw);
|
||||
|
||||
$this->resetRepository->method('findActiveByHash')->with($tokenHash)->willReturn([
|
||||
$this->resetRepository->expects($this->once())->method('findActiveByHash')->with($tokenHash)->willReturn([
|
||||
'user_id' => 1,
|
||||
'token_hash' => $tokenHash,
|
||||
'expires_at' => date('Y-m-d H:i:s', time() - 3600),
|
||||
@@ -194,13 +195,13 @@ final class PasswordResetServiceTest extends TestCase
|
||||
$tokenRaw = 'montokenbrut';
|
||||
$tokenHash = hash('sha256', $tokenRaw);
|
||||
|
||||
$this->resetRepository->method('findActiveByHash')->with($tokenHash)->willReturn([
|
||||
$this->resetRepository->expects($this->once())->method('findActiveByHash')->with($tokenHash)->willReturn([
|
||||
'user_id' => $user->getId(),
|
||||
'token_hash' => $tokenHash,
|
||||
'expires_at' => date('Y-m-d H:i:s', time() + 3600),
|
||||
'used_at' => null,
|
||||
]);
|
||||
$this->userRepository->method('findById')->with($user->getId())->willReturn($user);
|
||||
$this->userRepository->expects($this->once())->method('findById')->with($user->getId())->willReturn($user);
|
||||
|
||||
$result = $this->service->validateToken($tokenRaw);
|
||||
|
||||
@@ -224,8 +225,8 @@ final class PasswordResetServiceTest extends TestCase
|
||||
'used_at' => null,
|
||||
];
|
||||
|
||||
$this->resetRepository->method('findActiveByHash')->willReturn($row);
|
||||
$this->userRepository->method('findById')->with(999)->willReturn(null);
|
||||
$this->resetRepository->expects($this->once())->method('findActiveByHash')->willReturn($row);
|
||||
$this->userRepository->expects($this->once())->method('findById')->with(999)->willReturn(null);
|
||||
|
||||
$result = $this->service->validateToken('token-valide-mais-user-supprime');
|
||||
|
||||
@@ -282,7 +283,7 @@ final class PasswordResetServiceTest extends TestCase
|
||||
|
||||
$this->resetRepository->expects($this->once())
|
||||
->method('consumeActiveToken')
|
||||
->with($tokenHash, $this->isType('string'))
|
||||
->with($tokenHash, $this->callback('is_string'))
|
||||
->willReturn([
|
||||
'user_id' => $user->getId(),
|
||||
'token_hash' => $tokenHash,
|
||||
|
||||
Reference in New Issue
Block a user