/** * @test */ public function it_uses_is_done_condition_to_check_if_chapter_is_done_based_on_received_message() { $fileWasUploaded = new FileWasUploaded(); $startCondition = $this->prophesize(MessageCondition::class); $isDoneCondition = $this->prophesize(MessageCondition::class); $isDoneCondition->isTrueFor(Argument::is($fileWasUploaded))->willReturn(true); $commandTemplate = new MessageTemplate(ProcessFile::class, new FQCNMessageFactory()); $chapterTemplate = new ChapterTemplate(ChapterName::fromString('File Processor'), $commandTemplate, $startCondition->reveal(), $isDoneCondition->reveal()); $this->assertTrue($chapterTemplate->isDoneBy($fileWasUploaded)); }
/** * @param ChapterStatus $chapterStatus * @param ChapterTemplate $chapterTemplate * @param Message $receivedMessage * @param MessageConverter $messageConverter * @param MessageFactory $messageFactory * @param StoryName $storyName */ private function handleFailedChapter(ChapterStatus $chapterStatus, ChapterTemplate $chapterTemplate, Message $receivedMessage, MessageConverter $messageConverter, MessageFactory $messageFactory, StoryName $storyName) { $failedStatus = $chapterStatus->markChapterAsFailed(); $this->recordThat(ChapterFailed::withStatusByMessage($failedStatus, $messageConverter->convertToArray($receivedMessage))); if ($failedStatus->isRetryPossible()) { $retryStatus = $failedStatus->retry(); $startMessage = $this->getOriginalStartMessageForChapterNumber($retryStatus->chapterNumber(), $messageFactory); $chapterCommand = $chapterTemplate->startChapter($storyName, $retryStatus->chapterNumber(), $startMessage); $this->recordThat(ChapterRetryWasStarted::withStatusByMessage($retryStatus, $messageConverter->convertToArray($chapterCommand))); $this->nextCommands[] = $chapterCommand; return; } $this->recordThat(StoryFailed::withStoryIdAndName($failedStatus->chapterNumber()->storyId(), $storyName)); }