Refactoring in the Book samples

This commit is contained in:
Carlos Buenosvinos
2022-02-02 16:06:28 +01:00
parent fd17ed2191
commit c9b6158835
32 changed files with 222 additions and 110 deletions

View File

@@ -6,12 +6,12 @@ namespace Cheeper\AllChapters\Infrastructure\Persistence;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Doctrine\ORM\EntityManagerInterface;
//snippet doctrine-orm-authors
final class DoctrineOrmAuthors implements Authors
final class DoctrineOrmAuthorRepository implements AuthorRepository
{
public function __construct(
private EntityManagerInterface $em

View File

@@ -6,12 +6,12 @@ namespace Cheeper\AllChapters\Infrastructure\Persistence;
use Cheeper\AllChapters\DomainModel\Cheep\Cheep;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\AllChapters\DomainModel\Cheep\Cheeps;
use Cheeper\AllChapters\DomainModel\Cheep\CheepRepository;
use Doctrine\ORM\EntityManagerInterface;
use Ramsey\Uuid\Uuid;
//snippet doctrine-orm-cheeps
final class DoctrineOrmCheeps implements Cheeps
final class DoctrineOrmCheepRepository implements CheepRepository
{
//ignore
public function __construct(

View File

@@ -4,14 +4,14 @@ declare(strict_types=1);
namespace Cheeper\AllChapters\Infrastructure\Persistence;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\Chapter2\Author;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
use function Functional\head;
use function Functional\select;
final class InMemoryAuthors implements Authors
final class InMemoryAuthorRepository implements AuthorRepository
{
public array $authors;

View File

@@ -4,12 +4,12 @@ declare(strict_types=1);
namespace Cheeper\AllChapters\Infrastructure\Persistence;
use Cheeper\AllChapters\DomainModel\Cheep\Cheep;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\AllChapters\DomainModel\Cheep\Cheeps;
use Cheeper\Chapter2\Cheep;
use Cheeper\Chapter2\Hexagonal\DomainModel\CheepRepository;
//snippet inmemory-cheeps
final class InMemoryCheeps implements Cheeps
final class InMemoryCheepRepository implements CheepRepository
{
/** @var Cheep[] */
private array $items = [];

View File

@@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Cheeper\Chapter2;
use Cheeper\Chapter2\Layered\Authors;
use Cheeper\Chapter2\Layered\CheepDAO;
//snippet cheep-service
final class CheepService
{
public function __construct(
private Authors $authors,
private CheepDAO $cheepDao,
) {
}
public function postCheep(string $username, string $message): Cheep
{
$author = $this->authors->byUsername($username);
if (null === $author) {
throw new \RuntimeException(sprintf('%s username not found', $username));
}
$cheep = $author->compose($message);
$this->cheepDao->add($cheep);
return $cheep;
}
}
//end-snippet

View File

@@ -2,25 +2,27 @@
declare(strict_types=1);
namespace Cheeper\Chapter2;
namespace Cheeper\Chapter2\Hexagonal\Application;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\Chapter2\Author;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
//snippet author-service
use Cheeper\Chapter2\Layered\Authors;
final class AuthorService
{
public function __construct(
private Authors $authors
private AuthorRepository $authorRepository
) {
}
public function update(
int $id,
string $id,
string $username,
?string $website,
?string $bio
): Author {
$author = $this->authors->byId($id);
$author = $this->authorRepository->ofId(AuthorId::fromString($id));
if (null === $author) {
throw new \RuntimeException(sprintf('%s author not found', $username));
@@ -30,7 +32,7 @@ final class AuthorService
$author->setWebsite($website);
$author->setBio($bio);
$this->authors->save($author);
$this->authorRepository->add($author);
return $author;
}

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Cheeper\Chapter2\Hexagonal\Application;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\Chapter2\Cheep;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
use Cheeper\Chapter2\Hexagonal\DomainModel\CheepRepository;
//snippet cheep-service
final class CheepService
{
public function __construct(
private AuthorRepository $authorRepository,
private CheepRepository $cheepRepository,
) {
}
public function postCheep(string $username, string $message): Cheep
{
$author = $this->authorRepository->ofUserName(UserName::pick($username));
if (null === $author) {
throw new \RuntimeException(sprintf('%s username not found', $username));
}
$cheep = $author->compose($message);
$this->cheepRepository->add($cheep);
return $cheep;
}
}
//end-snippet

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Cheeper\Chapter2\Hexagonal\DomainModel;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\Chapter2\Author;
//snippet authors
interface AuthorRepository
{
public function ofId(AuthorId $authorId): ?Author;
public function ofUserName(UserName $userName): ?Author;
public function add(Author $author): void;
}
//end-snippet

View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Cheeper\Chapter2\Hexagonal\DomainModel;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\Chapter2\Cheep;
//snippet snippet
interface CheepRepository
{
public function add(Cheep $cheep): void;
public function ofId(CheepId $cheepId): ?Cheep;
}
//end-snippet

View File

@@ -2,14 +2,14 @@
declare(strict_types=1);
namespace Cheeper\Chapter2;
namespace Cheeper\Chapter2\Hexagonal\DomainModel\CheepRepositoryWithLotsOfFinders;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Cheep\Cheep;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\Chapter2\Author;
use Cheeper\Chapter2\Cheep;
use DateTimeInterface;
//snippet cheeps-with-a-lot-of-finders
//snippet snippet
interface CheepRepository
{
public function add(Cheep $cheep): void;

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Cheeper\Chapter2\Hexagonal\Infrastructure\DomainModel;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\Chapter2\Author;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
use Doctrine\ORM\EntityManagerInterface;
//snippet doctrine-orm-authors
final class DoctrineOrmAuthorRepository implements AuthorRepository
{
public function __construct(
private EntityManagerInterface $em
) {
}
public function ofId(AuthorId $authorId): ?Author
{
return $this->em
->getRepository(Author::class)
->findOneBy([
'authorId' => $authorId->id(),
]);
}
public function ofUserName(UserName $userName): ?Author
{
return $this->em
->getRepository(Author::class)
->findOneBy(['userName' => $userName->userName()]);
}
public function add(Author $author): void
{
$this->em->persist($author);
}
}
//end-snippet

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Cheeper\Chapter2\Hexagonal\Infrastructure\DomainModel;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\Chapter2\Cheep;
use Cheeper\Chapter2\Hexagonal\DomainModel\CheepRepository;
use Doctrine\ORM\EntityManagerInterface;
use Ramsey\Uuid\Uuid;
//snippet doctrine-orm-cheeps
final class DoctrineOrmCheepRepository implements CheepRepository
{
//ignore
public function __construct(
private EntityManagerInterface $em
) {
}
public function add(Cheep $cheep): void
{
$this->em->persist($cheep);
}
//end-ignore
public function ofId(CheepId $cheepId): ?Cheep
{
return $this->em->find(Cheep::class, Uuid::fromString($cheepId->id()));
}
}
//end-snippet

View File

@@ -9,7 +9,7 @@ use function mimic\hydrate;
use PDO;
//snippet authors
class Authors
class AuthorDAO
{
private PDO $db;

View File

@@ -10,7 +10,7 @@ final class CheepService
{
public function postCheep(string $username, string $message): Cheep
{
if (!$author = (new Authors())->byUsername($username)) {
if (!$author = (new AuthorDAO())->byUsername($username)) {
throw new AuthorNotFound($username);
}

View File

@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Cheeper\Chapter4\Application\Author\Command;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\DomainModel\Follow\Follow as FollowAggregate;
use Cheeper\AllChapters\DomainModel\Follow\FollowId;
@@ -14,8 +14,8 @@ use Cheeper\AllChapters\DomainModel\Follow\Follows;
final class FollowCommandHandler
{
public function __construct(
private Authors $authors,
private Follows $follows,
private AuthorRepository $authors,
private Follows $follows,
) {
}

View File

@@ -7,11 +7,11 @@ namespace Cheeper\Chapter4\Application\Author\Command\SignUpWithEvents;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorAlreadyExists;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\BirthDate;
use Cheeper\AllChapters\DomainModel\Author\EmailAddress;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\DomainModel\Author\Website;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter6\Application\Event\EventBus;
@@ -19,8 +19,8 @@ use Cheeper\Chapter6\Application\Event\EventBus;
final class SignUpCommandHandler
{
public function __construct(
private Authors $authors,
private EventBus $eventBus
private AuthorRepository $authors,
private EventBus $eventBus
) {
}

View File

@@ -7,17 +7,17 @@ namespace Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorAlreadyExists;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\BirthDate;
use Cheeper\AllChapters\DomainModel\Author\EmailAddress;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\DomainModel\Author\Website;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
//snippet sign-up-handler
final class SignUpCommandHandler
{
public function __construct(
private Authors $authors
private AuthorRepository $authors
) {
}

View File

@@ -7,20 +7,20 @@ namespace Cheeper\Chapter4\Application\Cheep\Command;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\AllChapters\DomainModel\Cheep\Cheep;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\AllChapters\DomainModel\Cheep\CheepMessage;
use Cheeper\AllChapters\DomainModel\Cheep\Cheeps;
use Cheeper\AllChapters\DomainModel\Cheep\CheepRepository;
use Cheeper\Chapter6\Application\Event\EventBus;
//snippet post-cheep-handler
final class PostCheepCommandHandler
{
public function __construct(
private Authors $authors,
private Cheeps $cheeps,
private EventBus $eventBus
private AuthorRepository $authors,
private CheepRepository $cheeps,
private EventBus $eventBus
) {
}

View File

@@ -7,13 +7,13 @@ namespace Cheeper\Chapter4\Application\Cheep\Command;
use Cheeper\AllChapters\DomainModel\Cheep\CheepDoesNotExist;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\AllChapters\DomainModel\Cheep\CheepMessage;
use Cheeper\AllChapters\DomainModel\Cheep\Cheeps;
use Cheeper\AllChapters\DomainModel\Cheep\CheepRepository;
//snippet recompose-cheep-handler
final class UpdateCheepMessageCommandHandler
{
public function __construct(
private Cheeps $cheeps
private CheepRepository $cheeps
) {
}

View File

@@ -6,7 +6,7 @@ namespace Cheeper\Chapter5\Application\Query\CountFollowersHandlerWithRepositori
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\Chapter5\Application\Query\CountFollowers;
use Cheeper\Chapter5\Application\Query\CountFollowersResponse;
use Cheeper\Chapter5\DomainModel\Follow\Followers;
@@ -16,7 +16,7 @@ final class CountFollowersHandler
{
public function __construct(
private Followers $followers,
private Authors $authors
private AuthorRepository $authors
) {
}

View File

@@ -7,7 +7,7 @@ namespace Cheeper\Chapter6\Application\Command\Author\WithDomainEvents;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\AllChapters\DomainModel\Follow\Follows;
use Cheeper\Chapter6\Application\Command\Author\Follow;
use Cheeper\Chapter6\Application\Event\EventBus;
@@ -16,10 +16,10 @@ use Cheeper\Chapter6\Application\Event\EventBus;
final class FollowHandler
{
public function __construct(
private Authors $authors,
private Follows $follows,
private AuthorRepository $authors,
private Follows $follows,
// leanpub-start-insert
private EventBus $eventBus
private EventBus $eventBus
// leanpub-end-insert
) {
}

View File

@@ -7,7 +7,7 @@ namespace Cheeper\Chapter6\Application\Command\Author\WithIdempotency;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\AllChapters\DomainModel\Follow\Follows;
use Cheeper\Chapter6\Application\Command\Author\Follow;
use Cheeper\Chapter6\Application\Event\EventBus;
@@ -15,10 +15,10 @@ use Cheeper\Chapter6\Application\Event\EventBus;
final class FollowHandler
{
public function __construct(
private Authors $authors,
private Follows $follows,
private AuthorRepository $authors,
private Follows $follows,
// leanpub-start-insert
private EventBus $eventBus
private EventBus $eventBus
// leanpub-end-insert
) {
}

View File

@@ -7,7 +7,7 @@ namespace Cheeper\Chapter6\Application\Command\Author\WithoutDomainEvents;
use Cheeper\AllChapters\DomainModel\Author\Author;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\AuthorRepository;
use Cheeper\AllChapters\DomainModel\Follow\Follows;
use Cheeper\Chapter6\Application\Command\Author\Follow;
@@ -15,8 +15,8 @@ use Cheeper\Chapter6\Application\Command\Author\Follow;
final class FollowHandler
{
public function __construct(
private Authors $authors,
private Follows $follows
private AuthorRepository $authors,
private Follows $follows
) {
}

View File

@@ -1,4 +1,4 @@
{% extends "src/CheeperLayered/templates/base.html.twig" %}
{% extends "../base.html.twig" %}
{% block content %}
<table>

View File

@@ -6,7 +6,7 @@ namespace Cheeper\Tests\Chapter2;
use Cheeper\Chapter2\Author;
use Cheeper\Chapter2\CheepService;
use Cheeper\Chapter2\Layered\Authors;
use Cheeper\Chapter2\Layered\AuthorDAO;
use Cheeper\Chapter2\Layered\CheepDAO;
use PHPUnit\Framework\TestCase;
@@ -14,13 +14,13 @@ use PHPUnit\Framework\TestCase;
final class CheepServiceTest extends TestCase
{
private CheepDAO $cheeps;
private Authors $authors;
private AuthorDAO $authors;
private CheepService $cheepService;
public function setUp(): void
{
$this->cheeps = \Mockery::mock(CheepDAO::class);
$this->authors = \Mockery::mock(Authors::class);
$this->authors = \Mockery::mock(AuthorDAO::class);
$this->cheepService = new CheepService($this->authors, $this->cheeps);
}

View File

@@ -7,7 +7,7 @@ namespace Cheeper\Tests\Chapter4\Application\Author\Command\SignUpWithEvents;
use Cheeper\AllChapters\DomainModel\Author\AuthorAlreadyExists;
use Cheeper\AllChapters\DomainModel\Author\NewAuthorSigned;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthorRepository;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithEvents\SignUpCommandHandler;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter6\Infrastructure\Application\Event\InMemoryEventBus;
@@ -22,7 +22,7 @@ final class SignUpCommandHandlerTest extends TestCase
$this->expectException(AuthorAlreadyExists::class);
$this->expectExceptionMessage('Author with name "johndoe" already exists');
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpCommandHandler(
@@ -62,7 +62,7 @@ final class SignUpCommandHandlerTest extends TestCase
/** @test */
public function givenValidUserDataWhenSignUpWithOnlyMandatoryFieldsThenAValidUserShouldBeCreated(): void
{
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpCommandHandler(
$authors,
@@ -97,7 +97,7 @@ final class SignUpCommandHandlerTest extends TestCase
/** @test */
public function givenValidUserDataWhenSignUpWithAllFieldsThenAValidUserShouldBeCreated(): void
{
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpCommandHandler(
$authors,
@@ -146,7 +146,7 @@ final class SignUpCommandHandlerTest extends TestCase
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid email not-a-valid-email');
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpCommandHandler(
$authors,
@@ -181,7 +181,7 @@ final class SignUpCommandHandlerTest extends TestCase
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid URL given');
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpCommandHandler(
$authors,

View File

@@ -5,9 +5,8 @@ declare(strict_types=1);
namespace Cheeper\Tests\Chapter4\Application\Author\Command\SignUpWithoutEvents;
use Cheeper\AllChapters\DomainModel\Author\AuthorAlreadyExists;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthorRepository;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommandHandler;
use PHPUnit\Framework\TestCase;
@@ -21,7 +20,7 @@ final class SignUpCommandHandlerTest extends TestCase
$this->expectException(AuthorAlreadyExists::class);
$this->expectExceptionMessage('Author with name "johndoe" already exists');
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
//snippet sign-up-handler-usage
$signUpHandler = new SignUpCommandHandler($authors);
@@ -57,7 +56,7 @@ final class SignUpCommandHandlerTest extends TestCase
/** @test */
public function givenValidUserDataWithOnlyMandatoryFieldsWhenSignUpThenAValidUserShouldBeCreated(): void
{
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$signUpHandler = new SignUpCommandHandler($authors);
@@ -86,7 +85,7 @@ final class SignUpCommandHandlerTest extends TestCase
/** @test */
public function givenValidUserDataWhenSignUpThenAValidUserShouldBeCreated(): void
{
$authors = new InMemoryAuthors();
$authors = new InMemoryAuthorRepository();
$signUpHandler = new SignUpCommandHandler($authors);

View File

@@ -15,7 +15,7 @@ use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Follow\FollowId;
use Cheeper\AllChapters\DomainModel\Author\EmailAddress;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthorRepository;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryFollows;
use Cheeper\Tests\Helper\SendsCommands;
use PHPUnit\Framework\TestCase;

View File

@@ -13,7 +13,7 @@ use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\DomainModel\Follow\FollowId;
use Cheeper\AllChapters\DomainModel\Author\EmailAddress;
use Cheeper\AllChapters\DomainModel\Author\UserName;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthorRepository;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryFollows;
use Cheeper\Tests\Helper\SendsCommands;
use PHPUnit\Framework\TestCase;

View File

@@ -5,33 +5,33 @@ declare(strict_types=1);
namespace Cheeper\Tests\Helper;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthorRepository;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryCheepRepository;
use Cheeper\Chapter2\Hexagonal\DomainModel\AuthorRepository;
use Cheeper\Chapter2\Hexagonal\DomainModel\CheepRepository;
use Cheeper\Chapter4\Application\Cheep\Command\PostCheepCommand;
use Cheeper\Chapter4\Application\Cheep\Command\PostCheepCommandHandler;
use Cheeper\Chapter6\Infrastructure\Application\Event\InMemoryEventBus;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Cheep\Cheeps;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryCheeps;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryFollows;
trait SendsCommands
{
private Authors $authors;
private Cheeps $cheeps;
private AuthorRepository $authors;
private CheepRepository $cheeps;
private InMemoryFollows $follows;
private InMemoryEventBus $eventBus;
/** @before */
final protected function makeUserRepository(): void
{
$this->authors = new InMemoryAuthors();
$this->authors = new InMemoryAuthorRepository();
}
//snippet setup-cheeps-repository
/** @before */
final protected function makeCheepsRepository(): void
{
$this->cheeps = new InMemoryCheeps();
$this->cheeps = new InMemoryCheepRepository();
}
//end-snippet