messageBus = new InMemoryMessageBus(); $this->container->set(MessageBusInterface::class, $this->messageBus); $this->messageBus->clear(); } public function testInitiateChapterScraping(): void { // Given $payload = [ 'chapterId' => 'chapter-123', ]; // When $response = static::createClient()->request('POST', '/api/scraping/chapters', [ 'json' => $payload, 'headers' => ['Accept' => 'application/json'], ]); // Then $this->assertResponseStatusCodeSame(202); $messages = $this->messageBus->getDispatchedMessages(); $this->assertCount(1, $messages, 'Un message devrait ĂȘtre dispatchĂ©'); /** @var ScrapeChapter $message */ $message = $messages[0]; $this->assertInstanceOf(ScrapeChapter::class, $message); $this->assertEquals('chapter-123', $message->chapterId); } public function testInitiateChapterScrapingWithInvalidPayload(): void { // Given $payload = [ 'chapterId' => '', ]; // When $response = static::createClient()->request('POST', '/api/scraping/chapters', [ 'json' => $payload, 'headers' => ['Accept' => 'application/json'], ]); // Then $this->assertResponseStatusCodeSame(422); $this->assertJsonContains([ 'violations' => [ [ 'propertyPath' => 'chapterId', 'message' => 'This value should not be blank.', ], ], ]); } protected function tearDown(): void { parent::tearDown(); $this->messageBus->clear(); } }