authorRepository = new InMemoryAuthorRepository(); $this->followRepository = new InMemoryFollowRepository(); } /** @test */ public function whenFollowerDoesNotExistAnExceptionShouldBeThrown(): void { $this->expectException(AuthorDoesNotExist::class); $this->expectExceptionMessage('Author "abcd" does not exist'); $this->followAuthor('abcd', 'dcba'); } /** @test */ public function whenAuthorFollowedDoesNotExistAnExceptionShouldBeThrown(): void { $this->expectException(AuthorDoesNotExist::class); $this->expectExceptionMessage('Author "test2" does not exist'); $this->signUpAuthorWith( Uuid::uuid4()->toString(), 'test', 'test@email.com', 'test', 'test', 'test', 'http://google.com/', (new DateTimeImmutable())->format('Y-m-d') ); $this->followAuthor('test', 'test2'); } 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 ) ); } /** @test */ public function authorsCanFollowOtherAuthors(): void { $authorId = Uuid::uuid4(); $this->signUpAuthorWith( $authorId->toString(), 'test', 'test@gmail.com', 'test', 'test', 'test', 'https://google.com/', (new DateTimeImmutable())->format('Y-m-d') ); $followedId = Uuid::uuid4(); $this->signUpAuthorWith( $followedId->toString(), 'test2', 'test2@gmail.com', 'test2', 'test2', 'test2', 'https://bing.com/', (new DateTimeImmutable())->format('Y-m-d') ); $this->followAuthor('test', 'test2'); $followers = $this->followRepository->numberOfFollowersFor(AuthorId::fromUuid($authorId)); $this->assertSame(1, $followers); } private function followAuthor(string $followee, string $followed): void { (new FollowCommandHandler($this->authorRepository, $this->followRepository))( FollowCommand::anAuthor($followed, $followee) ); } }