feat: firsts endpoints and firsts tests
This commit is contained in:
parent
89570ad951
commit
6bc3696190
38
tests/Domain/Scraping/Adapter/InMemoryMessageBus.php
Normal file
38
tests/Domain/Scraping/Adapter/InMemoryMessageBus.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Domain\Scraping\Adapter;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
class InMemoryMessageBus implements MessageBusInterface
|
||||
{
|
||||
/** @var array<object> */
|
||||
public static array $messages = [];
|
||||
|
||||
public function dispatch(object $message, array $stamps = []): Envelope
|
||||
{
|
||||
self::$messages[] = $message;
|
||||
return new Envelope($message);
|
||||
}
|
||||
|
||||
public function getDispatchedMessages(): array
|
||||
{
|
||||
return self::$messages;
|
||||
}
|
||||
|
||||
public function clear(): void
|
||||
{
|
||||
self::$messages = [];
|
||||
}
|
||||
|
||||
public function hasMessageOfType(string $messageClass): bool
|
||||
{
|
||||
foreach (self::$messages as $message) {
|
||||
if ($message instanceof $messageClass) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -8,21 +8,21 @@ use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
||||
class InMemoryScrapingJobRepository implements ScrapingJobRepositoryInterface
|
||||
{
|
||||
/** @var ScrapingJob[] */
|
||||
private array $jobs = [];
|
||||
private static array $jobs = [];
|
||||
|
||||
public function save(ScrapingJob $job): void
|
||||
{
|
||||
$this->jobs[] = $job;
|
||||
self::$jobs[] = $job;
|
||||
}
|
||||
|
||||
public function getJobs(): array
|
||||
{
|
||||
return $this->jobs;
|
||||
return self::$jobs;
|
||||
}
|
||||
|
||||
public function findById(string $id): ?ScrapingJob
|
||||
{
|
||||
foreach ($this->jobs as $job) {
|
||||
foreach (self::$jobs as $job) {
|
||||
if ($job->getId() === $id) {
|
||||
return $job;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class InMemoryScrapingJobRepository implements ScrapingJobRepositoryInterface
|
||||
|
||||
public function findByChapterId(string $chapterId): ?ScrapingJob
|
||||
{
|
||||
foreach ($this->jobs as $job) {
|
||||
foreach (self::$jobs as $job) {
|
||||
if ($job->getChapterId() === $chapterId) {
|
||||
return $job;
|
||||
}
|
||||
@@ -41,4 +41,9 @@ class InMemoryScrapingJobRepository implements ScrapingJobRepositoryInterface
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function clear(): void
|
||||
{
|
||||
self::$jobs = [];
|
||||
}
|
||||
}
|
||||
@@ -40,17 +40,14 @@ class ScrapeChapterHandlerTest extends TestCase
|
||||
|
||||
$this->handler->handle($command);
|
||||
|
||||
// Vérifier que le job a été créé
|
||||
$scrapingJobs = $this->scraper->getJobs();
|
||||
$this->assertCount(1, $scrapingJobs);
|
||||
$job = $scrapingJobs[0];
|
||||
|
||||
// Vérifier que le job a été sauvegardé
|
||||
$savedJobs = $this->repository->getJobs();
|
||||
$this->assertCount(1, $savedJobs);
|
||||
$this->assertSame($job, $savedJobs[0]);
|
||||
|
||||
// Vérifier que l'événement a été dispatché
|
||||
$dispatchedMessages = $this->eventBus->getDispatchedMessages();
|
||||
$this->assertCount(1, $dispatchedMessages);
|
||||
$this->assertInstanceOf(ChapterScrapingStarted::class, $dispatchedMessages[0]);
|
||||
@@ -74,7 +71,6 @@ class ScrapeChapterHandlerTest extends TestCase
|
||||
try {
|
||||
$this->handler->handle($command);
|
||||
} finally {
|
||||
// Vérifier que l'événement d'échec a été dispatché
|
||||
$dispatchedMessages = $this->eventBus->getDispatchedMessages();
|
||||
$this->assertCount(1, $dispatchedMessages);
|
||||
$this->assertInstanceOf(ChapterScrapingFailed::class, $dispatchedMessages[0]);
|
||||
|
||||
Reference in New Issue
Block a user