cheepRepository = new InMemoryCheepRepository(); $this->authorRepository = new InMemoryAuthorRepository(); $this->eventBus = new InMemoryEventBus(); } /** @test */ public function whenCheepDoesNotExistThenAnExceptionShouldBeThrown(): void { $cheepId = Uuid::uuid4()->toString(); $this->expectException(CheepDoesNotExist::class); $this->expectExceptionMessage(sprintf("Cheep with ID %s does not exist", $cheepId)); $this->updateCheepMessage($cheepId, "new cheep message"); } /** @test */ public function shouldRecomposeCheepSuccessfully(): void { $cheepId = Uuid::uuid4()->toString(); $authorId = Uuid::uuid4()->toString(); $this->signUpAuthorWith( $authorId, 'test', 'test@email.com', 'test', 'test', 'test', 'https://test.com', '1983-01-07' ); $this->postNewCheep($authorId, $cheepId, 'Cheep message'); $this->updateCheepMessage($cheepId, "new cheep message"); $cheep = $this->cheepRepository->ofId(CheepId::fromString($cheepId)); $this->assertSame("new cheep message", $cheep->message()->message()); } private function postNewCheep(string $authorId, string $cheepId, string $message): void { (new PostCheepCommandHandler( $this->authorRepository, $this->cheepRepository, $this->eventBus ))( PostCheepCommand::fromArray([ 'author_id' => $authorId, 'cheep_id' => $cheepId, 'message' => $message, ]) ); } private function signUpAuthorWith(string $authorId, string $userName, string $email, string $name, string $biography, string $location, string $website, string $birthDate): void { (new SignUpCommandHandler( $this->authorRepository ))( new SignUpCommand( $authorId, $userName, $email, $name, $biography, $location, $website, $birthDate ) ); } private function updateCheepMessage(string $cheepId, string $message): void { $updateCheepMessageHandler = new UpdateCheepMessageCommandHandler( $this->cheepRepository ); $updateCheepMessageHandler( new UpdateCheepMessageCommand( $cheepId, $message ) ); } } //end-snippet