authorRepository = new InMemoryAuthorRepository(); $this->authorApplicationService = new AuthorApplicationService($this->authorRepository); } /** @test */ public function givenAuthorSignUpWhenAuthorUsernameIsAlreadyPickedUpThenAnExceptionShouldBeThrown(): void { $this->expectException(AuthorAlreadyExists::class); $id = Uuid::uuid4()->toString(); $username = 'irrelevant'; $email = 'test@gmail.com'; $name = 'irrelevant'; $biography = 'biography'; $location = 'location'; $website = 'https://google.com'; $birthDate = (new \DateTimeImmutable())->format('Y-m-d'); $this->assertNotEmpty($birthDate); $this->authorRepository->add( AuthorTestDataBuilder::anAuthor()->build() ); $this->authorApplicationService->signUp( $id, $username, $email, $name, $biography, $location, $website, $birthDate, ); } /** @test */ public function givenAuthorSignUpWhenExecutedWithValidDataThenANewAuthorShouldBeCreated(): void { $id = Uuid::uuid4()->toString(); $username = 'irrelevant'; $email = 'test@gmail.com'; $name = 'irrelevant'; $biography = 'biography'; $location = 'location'; $website = 'https://google.com'; $birthDate = (new \DateTimeImmutable())->format('Y-m-d'); $this->assertNotEmpty($birthDate); $this->authorApplicationService->signUp( $id, $username, $email, $name, $biography, $location, $website, $birthDate, ); $author = $this->authorRepository->ofUserName(UserName::pick('irrelevant')); $this->assertNotNull($author); $this->assertSame($website, $author->website()?->uri); $this->assertSame($birthDate, $author->birthDate()?->date()->format('Y-m-d')); } /** @test */ public function itReturnsAllAuthors(): void { $this->authorRepository->add( AuthorTestDataBuilder::anAuthor()->build() ); $authors = $this->authorApplicationService->getAuthors(); $this->assertCount(1, $authors); $this->assertContainsOnlyInstancesOf(Author::class, $authors); } }