Refatoring : Working state
This commit is contained in:
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Category;
|
||||
|
||||
use App\Category\Category;
|
||||
use App\Category\Http\CategoryController as CategoryController;
|
||||
use App\Category\Http\CategoryController;
|
||||
use App\Category\CategoryServiceInterface;
|
||||
use App\Shared\Http\FlashServiceInterface;
|
||||
use App\Shared\Pagination\PaginatedResult;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ namespace Tests\Category;
|
||||
|
||||
use App\Category\Category;
|
||||
use App\Category\CategoryRepositoryInterface;
|
||||
use App\Category\Application\CategoryApplicationService as CategoryService;
|
||||
use App\Category\Application\CategoryApplicationService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests unitaires pour CategoryService.
|
||||
* Tests unitaires pour CategoryApplicationService.
|
||||
*
|
||||
* Vérifie la création (génération de slug, unicité du nom, validation du modèle)
|
||||
* et la suppression (blocage si articles rattachés).
|
||||
@@ -22,12 +22,12 @@ final class CategoryServiceTest extends TestCase
|
||||
/** @var CategoryRepositoryInterface&MockObject */
|
||||
private CategoryRepositoryInterface $repository;
|
||||
|
||||
private CategoryService $service;
|
||||
private CategoryApplicationService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = $this->createMock(CategoryRepositoryInterface::class);
|
||||
$this->service = new CategoryService($this->repository);
|
||||
$this->service = new CategoryApplicationService($this->repository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user