authorRepository = new InMemoryAuthorRepository(); $this->cheepRepository = new InMemoryCheepRepository(); $this->eventBus = new InMemoryEventBus(); $this->postCheepCommandHandler = new PostCheepCommandHandler($this->authorRepository, $this->cheepRepository, $this->eventBus); } /** @test */ public function itRaisesExceptionWhenAuthorNotFound(): void { $this->expectException(AuthorDoesNotExist::class); ($this->postCheepCommandHandler)( new PostCheepCommand( Uuid::uuid6()->toString(), 'irrelevant', 'irrelevant' ) ); } /** @test */ public function itShouldAddCheep(): void { $author = AuthorTestDataBuilder::anAuthor()->build(); $this->authorRepository->add($author); $cheepId = Uuid::uuid6(); ($this->postCheepCommandHandler)( new PostCheepCommand( $cheepId->toString(), 'irrelevant', 'irrelevant' ) ); $cheep = $this->cheepRepository->ofId( CheepTestDataBuilder::aCheepIdentity($cheepId) ); $this->assertNotNull($cheep); $this->assertNotEmpty($this->eventBus->getEvents()); } }