/** * @test */ public function it_starts_a_new_chapter_by_providing_the_chapter_command() { $fileWasUploaded = new FileWasUploaded(); $startCondition = $this->prophesize(MessageCondition::class); $startCondition->isTrueFor($fileWasUploaded)->willReturn(true); $isDoneCondition = $this->prophesize(MessageCondition::class); $payloadGenerator = $this->prophesize(PayloadGenerator::class); $payloadGenerator->__invoke(Argument::any(), Argument::any(), Argument::any())->will(function ($args) { list($previousMessage, $payload, $metadata) = $args; $payload['filename'] = $previousMessage->payload()['filename']; }); $commandTemplate = new MessageTemplate(ProcessFile::class, new FQCNMessageFactory(), [], [], $payloadGenerator->reveal()); $chapterTemplate = new ChapterTemplate(ChapterName::fromString('File Processor'), $commandTemplate, $startCondition->reveal(), $isDoneCondition->reveal()); $storyId = StoryId::generateNew(); $chapterNumber = ChapterNumber::withNumber($storyId, 2); $chapterCommand = $chapterTemplate->startChapter(StoryName::fromString('Test Story'), $chapterNumber, $fileWasUploaded); $this->assertInstanceOf(ProcessFile::class, $chapterCommand); $this->assertEquals('some-file.csv', $chapterCommand->payload()['filename']); $this->assertEquals($chapterNumber->toString(), $chapterCommand->metadata()[Metadata::STORY_CHAPTER]); $this->assertEquals('Test Story', $chapterCommand->metadata()[Metadata::STORY_NAME]); }
/** * @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)); }