Marco Pivetta Foreword

This commit is contained in:
Carlos Buenosvinos
2022-01-31 08:06:00 +01:00
parent fb6b14ad85
commit fd17ed2191
9 changed files with 97043 additions and 92 deletions

96945
bin/phpunit.phar Normal file

File diff suppressed because one or more lines are too long

View File

@@ -76,9 +76,9 @@ final class SignUpCommandBuilder
return $this;
}
public function build(): SignUp
public function build(): SignUpCommand
{
return new SignUp(
return new SignUpCommand(
$this->authorId,
$this->userName,
$this->email,

View File

@@ -2,20 +2,20 @@
declare(strict_types=1);
namespace Cheeper\Tests\AllChapters\Application\Command\Author;
namespace Cheeper\Tests\Chapter4\Application\Author\Command;
use Cheeper\AllChapters\Application\Command\Author\FollowCommand;
use Cheeper\AllChapters\Application\Command\Author\FollowCommandHandler;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\AuthorId;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryFollows;
use Cheeper\Chapter4\Application\Author\Command\FollowCommand;
use Cheeper\Chapter4\Application\Author\Command\FollowCommandHandler;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommandHandler;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Tests\Helper\SendsCommands;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
final class FollowHandlerTest extends TestCase
final class FollowCommandHandlerTest extends TestCase
{
use SendsCommands;
@@ -48,6 +48,24 @@ final class FollowHandlerTest extends TestCase
$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->authors
))(
new SignUpCommand(
$authorId,
$userName,
$email,
$name,
$biography,
$location,
$website,
$birthDate
)
);
}
/** @test */
public function authorsCanFollowOtherAuthors(): void
{
@@ -82,4 +100,11 @@ final class FollowHandlerTest extends TestCase
$followers = $this->follows->numberOfFollowersFor(AuthorId::fromUuid($authorId));
$this->assertSame(1, $followers);
}
private function followAuthor(string $followee, string $followed): void
{
(new FollowCommandHandler($this->authors, $this->follows))(
FollowCommand::anAuthor($followed, $followee)
);
}
}

View File

@@ -2,14 +2,14 @@
declare(strict_types=1);
namespace Cheeper\Tests\AllChapters\Application\Command\Author;
namespace Cheeper\Tests\Chapter4\Application\Author\Command;
use Cheeper\AllChapters\Application\Command\Author\SignUp as SignUpCommand;
use Cheeper\AllChapters\Application\Command\Author\SignUpCommandBuilder;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommandBuilder;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
final class SignUp {
final class SignUpCommandBuilderMock {
//snippet builder-method
public static function builder(
string $authorId,
@@ -29,7 +29,7 @@ final class SignUpBuilderTest extends TestCase
{
//snippet basic-builder-usage
$authorId = Uuid::uuid4()->toString();
$command = SignUp::builder($authorId, 'johndoe', 'test@email.com')->build();
$command = SignUpCommandBuilderMock::builder($authorId, 'johndoe', 'test@email.com')->build();
//end-snippet
$this->assertInstanceOf(SignUpCommand::class, $command);
@@ -39,7 +39,7 @@ final class SignUpBuilderTest extends TestCase
public function itBuildsOptionalFields(): void
{
//snippet sophisticated-builder-usage
$command = SignUp::builder(Uuid::uuid4()->toString(), 'johndoe', 'test@email.com')
$command = SignUpCommandBuilderMock::builder(Uuid::uuid4()->toString(), 'johndoe', 'test@email.com')
->name('John Doe')
->website('https://johndoe.com')
->biography('An example author')

View File

@@ -2,19 +2,19 @@
declare(strict_types=1);
namespace Cheeper\Tests\AllChapters\Application\Command\Author\SignUpWithEvents;
namespace Cheeper\Tests\Chapter4\Application\Author\Command\SignUpWithEvents;
use Cheeper\AllChapters\Application\Command\Author\SignUp;
use Cheeper\AllChapters\Application\Command\Author\SignUpWithEvents\SignUpHandler;
use Cheeper\Chapter6\Infrastructure\Application\Event\InMemoryEventBus;
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\Chapter4\Application\Author\Command\SignUpWithEvents\SignUpCommandHandler;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter6\Infrastructure\Application\Event\InMemoryEventBus;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
final class SignUpHandlerTest extends TestCase
final class SignUpCommandHandlerTest extends TestCase
{
/** @test */
public function givenAUserNameThatAlreadyBelongsToAnExistingUserWhenSignUpThenAnExceptionShouldBeThrown(): void
@@ -25,13 +25,13 @@ final class SignUpHandlerTest extends TestCase
$authors = new InMemoryAuthors();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpHandler(
$signUpHandler = new SignUpCommandHandler(
$authors,
$eventBus
);
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
'johndoe',
'johndoe@example.com',
@@ -46,7 +46,7 @@ final class SignUpHandlerTest extends TestCase
$eventBus->reset();
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
'johndoe',
'johndoe@example.com',
@@ -64,7 +64,7 @@ final class SignUpHandlerTest extends TestCase
{
$authors = new InMemoryAuthors();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpHandler(
$signUpHandler = new SignUpCommandHandler(
$authors,
$eventBus
);
@@ -72,7 +72,7 @@ final class SignUpHandlerTest extends TestCase
$userName = 'johndoe';
$email = 'johndoe@example.com';
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
$userName,
$email,
@@ -99,7 +99,7 @@ final class SignUpHandlerTest extends TestCase
{
$authors = new InMemoryAuthors();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpHandler(
$signUpHandler = new SignUpCommandHandler(
$authors,
$eventBus
);
@@ -113,7 +113,7 @@ final class SignUpHandlerTest extends TestCase
$birthDate = (new \DateTimeImmutable())->format('Y-m-d');
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
$userName,
$email,
@@ -148,7 +148,7 @@ final class SignUpHandlerTest extends TestCase
$authors = new InMemoryAuthors();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpHandler(
$signUpHandler = new SignUpCommandHandler(
$authors,
$eventBus
);
@@ -162,7 +162,7 @@ final class SignUpHandlerTest extends TestCase
$birthDate = (new \DateTimeImmutable())->format('Y-m-d');
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
$userName,
$email,
@@ -183,7 +183,7 @@ final class SignUpHandlerTest extends TestCase
$authors = new InMemoryAuthors();
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpHandler(
$signUpHandler = new SignUpCommandHandler(
$authors,
$eventBus
);
@@ -197,7 +197,7 @@ final class SignUpHandlerTest extends TestCase
$birthDate = (new \DateTimeImmutable())->format('Y-m-d');
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
$userName,
$email,

View File

@@ -2,18 +2,18 @@
declare(strict_types=1);
namespace Cheeper\Tests\AllChapters\Application\Command\Author;
namespace Cheeper\Tests\Chapter4\Application\Author\Command\SignUpWithoutEvents;
use Cheeper\AllChapters\Application\Command\Author\SignUp;
use Cheeper\AllChapters\Application\Command\Author\SignUpCommandHandler;
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\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommandHandler;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
final class SignUpHandlerTest extends TestCase
final class SignUpCommandHandlerTest extends TestCase
{
/** @test */
public function givenAUserNameThatAlreadyBelongsToAnExistingUserWhenSignUpThenAnExceptionShouldBeThrown(): void
@@ -27,7 +27,7 @@ final class SignUpHandlerTest extends TestCase
$signUpHandler = new SignUpCommandHandler($authors);
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
'johndoe',
'johndoe@example.com',
@@ -41,7 +41,7 @@ final class SignUpHandlerTest extends TestCase
//end-snippet
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
'johndoe',
'johndoe@example.com',
@@ -65,7 +65,7 @@ final class SignUpHandlerTest extends TestCase
$email = 'johndoe@example.com';
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
$userName,
$email
@@ -99,7 +99,7 @@ final class SignUpHandlerTest extends TestCase
$birthDate = (new \DateTimeImmutable())->format('Y-m-d');
$signUpHandler(
new SignUp(
new SignUpCommand(
Uuid::uuid4()->toString(),
$userName,
$email,

View File

@@ -2,24 +2,20 @@
declare(strict_types=1);
namespace Cheeper\Tests\AllChapters\Application\Command\Cheep;
namespace Cheeper\Tests\Chapter4\Application\Cheep\Command;
use Cheeper\AllChapters\Application\Command\Cheep\PostCheep;
use Cheeper\AllChapters\Application\Command\Cheep\PostCheepHandler;
use Cheeper\AllChapters\DomainModel\Author\AuthorDoesNotExist;
use Cheeper\AllChapters\DomainModel\Author\Authors;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\AllChapters\DomainModel\Cheep\CheepPosted;
use Cheeper\AllChapters\DomainModel\Cheep\Cheeps;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryCheeps;
use Cheeper\Chapter4\Application\Cheep\Command\PostCheepCommand;
use Cheeper\Chapter4\Application\Cheep\Command\PostCheepCommandHandler;
use Cheeper\Tests\AllChapters\DomainModel\Author\AuthorTestDataBuilder;
use Cheeper\Tests\Helper\SendsCommands;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
//snippet post-cheep-handler-test
final class PostCheepHandlerTest extends TestCase
final class PostCheepCommandHandlerTest extends TestCase
{
use SendsCommands;
@@ -102,12 +98,12 @@ final class PostCheepHandlerTest extends TestCase
string $cheepId,
string $message
): void {
(new PostCheepHandler(
(new PostCheepCommandHandler(
$this->authors,
$this->cheeps,
$this->eventBus
))(
PostCheep::fromArray([
PostCheepCommand::fromArray([
'author_id' => $authorId,
'cheep_id' => $cheepId,
'message' => $message,

View File

@@ -2,12 +2,14 @@
declare(strict_types=1);
namespace Cheeper\Tests\AllChapters\Application\Command\Cheep;
namespace Cheeper\Tests\Chapter4\Application\Cheep\Command;
use Cheeper\AllChapters\Application\Command\Cheep\UpdateCheepMessage;
use Cheeper\AllChapters\Application\Command\Cheep\UpdateCheepMessageHandler;
use Cheeper\AllChapters\DomainModel\Cheep\CheepDoesNotExist;
use Cheeper\AllChapters\DomainModel\Cheep\CheepId;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommand;
use Cheeper\Chapter4\Application\Author\Command\SignUpWithoutEvents\SignUpCommandHandler;
use Cheeper\Chapter4\Application\Cheep\Command\UpdateCheepMessageCommand;
use Cheeper\Chapter4\Application\Cheep\Command\UpdateCheepMessageCommandHandler;
use Cheeper\Tests\Helper\SendsCommands;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
@@ -52,12 +54,30 @@ final class UpdateCheepMessageHandlerTest extends TestCase
$this->assertSame("new cheep message", $cheep->cheepMessage()->message());
}
private function signUpAuthorWith(string $authorId, string $userName, string $email, string $name, string $biography, string $location, string $website, string $birthDate): void
{
(new SignUpCommandHandler(
$this->authors
))(
new SignUpCommand(
$authorId,
$userName,
$email,
$name,
$biography,
$location,
$website,
$birthDate
)
);
}
private function updateCheepMessage(string $cheepId, string $message): void
{
$updateCheepMessageHandler = new UpdateCheepMessageHandler($this->cheeps);
$updateCheepMessageHandler = new UpdateCheepMessageCommandHandler($this->cheeps);
$updateCheepMessageHandler(
new UpdateCheepMessage(
new UpdateCheepMessageCommand(
$cheepId,
$message
)

View File

@@ -5,24 +5,14 @@ declare(strict_types=1);
namespace Cheeper\Tests\Helper;
use Cheeper\AllChapters\Application\Command\Author\FollowCommand;
use Cheeper\AllChapters\Application\Command\Author\FollowCommandHandler;
use Cheeper\AllChapters\Application\Command\Author\SignUp;
use Cheeper\AllChapters\Application\Command\Author\SignUpCommandHandler;
use Cheeper\AllChapters\Application\Command\Cheep\PostCheep;
use Cheeper\AllChapters\Application\Command\Cheep\PostCheepHandler;
use Cheeper\Chapter6\Application\Event\EventBus;
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\DomainModel\DomainEvent;
use Cheeper\AllChapters\DomainModel\Follow\Follows;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryAuthors;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryCheeps;
use Cheeper\AllChapters\Infrastructure\Persistence\InMemoryFollows;
use DateTimeImmutable;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
trait SendsCommands
{
@@ -57,36 +47,11 @@ trait SendsCommands
$this->eventBus = new InMemoryEventBus();
}
private function signUpAuthorWith(string $authorId, string $userName, string $email, string $name, string $biography, string $location, string $website, string $birthDate): void
{
(new SignUpCommandHandler(
$this->authors
))(
new SignUp(
$authorId,
$userName,
$email,
$name,
$biography,
$location,
$website,
$birthDate
)
);
}
private function followAuthor(string $followee, string $followed): void
{
(new FollowCommandHandler($this->authors, $this->follows))(
FollowCommand::anAuthor($followed, $followee)
);
}
//snippet post-new-cheep-tests
private function postNewCheep(string $authorId, string $cheepId, string $message): void
{
(new PostCheepHandler($this->authors, $this->cheeps, $this->eventBus))(
PostCheep::fromArray([
(new PostCheepCommandHandler($this->authors, $this->cheeps, $this->eventBus))(
PostCheepCommand::fromArray([
'author_id' => $authorId,
'cheep_id' => $cheepId,
'message' => $message,