readonly(s) and some tests fixes

This commit is contained in:
Carlos Buenosvinos
2022-11-26 19:19:15 +01:00
parent aaeb363b82
commit bf2e9416aa
4 changed files with 18 additions and 13 deletions

View File

@@ -66,7 +66,8 @@
"allow-plugins": { "allow-plugins": {
"composer/package-versions-deprecated": true, "composer/package-versions-deprecated": true,
"symfony/flex": true, "symfony/flex": true,
"symfony/runtime": true "symfony/runtime": true,
"infection/extension-installer": true
} }
}, },
"autoload": { "autoload": {

View File

@@ -14,9 +14,9 @@ use Cheeper\Chapter7\DomainModel\Follow\FollowRepository;
final class FollowCommandHandler final class FollowCommandHandler
{ {
public function __construct( public function __construct(
private AuthorRepository $authors, private readonly AuthorRepository $authors,
private FollowRepository $follows, private readonly FollowRepository $follows,
private EventBus $eventBus private readonly EventBus $eventBus
) { ) {
} }
@@ -53,11 +53,11 @@ final class FollowCommandHandler
private function notifyEvents(FollowCommand $command, array $domainEvents): void private function notifyEvents(FollowCommand $command, array $domainEvents): void
{ {
$stamppedEvents = array_map( $stampedEvents = array_map(
static fn ($event) => $event->stampAsResponseTo($command), static fn ($event) => $event->stampAsResponseTo($command),
$domainEvents $domainEvents
); );
$this->eventBus->notifyAll($stamppedEvents); $this->eventBus->notifyAll($stampedEvents);
} }
} }

View File

@@ -18,8 +18,8 @@ use Cheeper\Chapter7\DomainModel\Author\AuthorRepository;
final class SignUpCommandHandler final class SignUpCommandHandler
{ {
public function __construct( public function __construct(
private AuthorRepository $authors, private readonly AuthorRepository $authors,
private EventBus $eventBus private readonly EventBus $eventBus
) { ) {
} }
@@ -72,8 +72,14 @@ final class SignUpCommandHandler
return null !== $inputWebsite ? Website::fromString($inputWebsite) : null; return null !== $inputWebsite ? Website::fromString($inputWebsite) : null;
} }
private function signUpAuthor(AuthorId $authorId, UserName $userName, EmailAddress $email, SignUpCommand $command, ?Website $website, ?BirthDate $birthDate): Author private function signUpAuthor(
{ AuthorId $authorId,
UserName $userName,
EmailAddress $email,
SignUpCommand $command,
?Website $website,
?BirthDate $birthDate)
: Author {
return Author::signUp( return Author::signUp(
$authorId, $authorId,
$userName, $userName,

View File

@@ -32,8 +32,6 @@ final class SignUpCommandHandlerTest extends TestCase
$this->expectException(AuthorAlreadyExists::class); $this->expectException(AuthorAlreadyExists::class);
$this->expectExceptionMessage('Author with name "johndoe" already exists'); $this->expectExceptionMessage('Author with name "johndoe" already exists');
$eventBus = new InMemoryEventBus();
$signUpHandler = new SignUpCommandHandler( $signUpHandler = new SignUpCommandHandler(
$this->authorRepository, $this->authorRepository,
$this->eventBus $this->eventBus
@@ -52,7 +50,7 @@ final class SignUpCommandHandlerTest extends TestCase
) )
); );
$eventBus->reset(); $this->eventBus->reset();
$signUpHandler( $signUpHandler(
new SignUpCommand( new SignUpCommand(