cheepRepository = new InMemoryCheepRepository(); $this->authorRepository = new InMemoryAuthorRepository(); $this->cheepService = new CheepApplicationService($this->authorRepository, $this->cheepRepository); } /** @test */ public function itRaisesExceptionWhenAuthorNotFound(): void { $this->expectException(AuthorDoesNotExist::class); $this->cheepService->postCheep('irrelevant', 'irrelevant'); } /** @test */ public function itShouldAddCheep(): void { $author = AuthorTestDataBuilder::anAuthor()->build(); $this->authorRepository->add($author); $cheep = $this->cheepService->postCheep($author->userName()->userName, 'message'); // Retrieve cheep by ID in order to make sure it has been persisted into the persistence store $cheep = $this->cheepService->getCheep($cheep->cheepId()->id); $this->assertNotNull($cheep); $this->assertNotNull($cheep->authorId()); $this->assertEquals('message', $cheep->cheepMessage()->message); } /** @test */ public function givenATimelineRequestWhenTheAuthorDoesNotExistThenAnExceptionShouldBeThrown(): void { $this->expectException(AuthorDoesNotExist::class); $this->cheepService->timelineFrom(AuthorTestDataBuilder::anAuthorIdentity()->id, 0, 1); } /** @test */ public function givenATimelineRequestWhenExecutionGoesWellThenAListOfCheepsShouldBeReturned(): void { $author = AuthorTestDataBuilder::anAuthor()->build(); $this->authorRepository->add($author); $cheeps = [ CheepTestDataBuilder::aCheep()->withAMessage("test1")->build(), CheepTestDataBuilder::aCheep()->withAMessage("test2")->build(), CheepTestDataBuilder::aCheep()->withAMessage("test3")->build(), ]; Iter\apply($cheeps, fn(Cheep $c) => $this->cheepRepository->add($c)); $this->assertCount( count($cheeps), $this->cheepService->timelineFrom($author->authorId()->id, 0, 10) ); } }