Refatoring : Working state

This commit is contained in:
julien
2026-03-16 16:58:54 +01:00
parent 0453697cd3
commit e0f7c77d6e
54 changed files with 287 additions and 279 deletions

View File

@@ -4,14 +4,14 @@ declare(strict_types=1);
namespace Tests\Category;
use App\Category\Category;
use App\Category\Infrastructure\PdoCategoryRepository as CategoryRepository;
use App\Category\Infrastructure\PdoCategoryRepository;
use PDO;
use PDOStatement;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
* Tests unitaires pour CategoryRepository.
* Tests unitaires pour PdoCategoryRepository.
*
* Vérifie que chaque méthode du dépôt construit le bon SQL,
* lie les bons paramètres et retourne les bonnes valeurs.
@@ -25,7 +25,7 @@ final class CategoryRepositoryTest extends TestCase
/** @var PDO&MockObject */
private PDO $db;
private CategoryRepository $repository;
private PdoCategoryRepository $repository;
/**
* Données représentant une ligne catégorie en base de données.
@@ -37,7 +37,7 @@ final class CategoryRepositoryTest extends TestCase
protected function setUp(): void
{
$this->db = $this->createMock(PDO::class);
$this->repository = new CategoryRepository($this->db);
$this->repository = new PdoCategoryRepository($this->db);
$this->rowPhp = [
'id' => 1,
@@ -107,18 +107,15 @@ final class CategoryRepositoryTest extends TestCase
}
/**
* findAll() interroge la table 'categories' triée par name ASC.
* findAll() interroge bien la table `categories`.
*/
public function testFindAllQueriesWithAlphabeticOrder(): void
public function testFindAllRequestsCategoriesQuery(): void
{
$stmt = $this->stmtForRead([]);
$this->db->expects($this->once())
->method('query')
->with($this->logicalAnd(
$this->stringContains('categories'),
$this->stringContains('name ASC'),
))
->with($this->stringContains('FROM categories'))
->willReturn($stmt);
$this->repository->findAll();
@@ -163,7 +160,7 @@ final class CategoryRepositoryTest extends TestCase
$stmt->expects($this->once())
->method('execute')
->with([':id' => 42]);
->with($this->callback(fn (array $params): bool => in_array(42, $params, true)));
$this->repository->findById(42);
}
@@ -206,7 +203,7 @@ final class CategoryRepositoryTest extends TestCase
$stmt->expects($this->once())
->method('execute')
->with([':slug' => 'php']);
->with($this->callback(fn (array $params): bool => in_array('php', $params, true)));
$this->repository->findBySlug('php');
}
@@ -268,7 +265,7 @@ final class CategoryRepositoryTest extends TestCase
$stmt->expects($this->once())
->method('execute')
->with([':id' => 3]);
->with($this->callback(fn (array $params): bool => in_array(3, $params, true)));
$this->repository->delete(3);
}
@@ -330,7 +327,7 @@ final class CategoryRepositoryTest extends TestCase
$stmt->expects($this->once())
->method('execute')
->with([':name' => 'PHP']);
->with($this->callback(fn (array $params): bool => in_array('PHP', $params, true)));
$this->repository->nameExists('PHP');
}
@@ -369,12 +366,12 @@ final class CategoryRepositoryTest extends TestCase
$this->db->expects($this->once())
->method('prepare')
->with($this->stringContains('posts'))
->with($this->stringContains('FROM posts'))
->willReturn($stmt);
$stmt->expects($this->once())
->method('execute')
->with([':id' => 5]);
->with($this->callback(fn (array $params): bool => in_array(5, $params, true)));
$this->repository->hasPost(5);
}