Esempio n. 1
0
 /**
  * @return StoryId
  */
 public function storyId()
 {
     if (null === $this->storyId) {
         $this->storyId = StoryId::fromString($this->aggregateId());
     }
     return $this->storyId;
 }
Esempio n. 2
0
 /**
  * @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]);
 }
Esempio n. 3
0
 /**
  * @param StoryId $storyId
  * @return Story
  */
 public function get(StoryId $storyId)
 {
     return $this->getAggregateRoot($storyId->toString());
 }
Esempio n. 4
0
 /**
  * @return \Prooph\Done\Shared\ChapterNumber
  */
 private function getChapterNumber()
 {
     return ChapterNumber::first(StoryId::generateNew());
 }
Esempio n. 5
0
 /**
  * @param Message $message
  * @param StoryId $ownStoryId
  * @param StoryId $otherStoryId
  * @return Story
  */
 public static function receivedMessageForDifferentStory(Message $message, StoryId $ownStoryId, StoryId $otherStoryId)
 {
     return new self(sprintf('Story %s received message %s (%s) for different story %s', $ownStoryId->toString(), $message->messageName(), $message->uuid()->toString(), $otherStoryId->toString()));
 }
Esempio n. 6
0
 /**
  * @return string representation of the unique identifier of the aggregate root
  */
 protected function aggregateId()
 {
     return $this->storyId->toString();
 }