diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Aggregate/User.php b/application/monolith/code/src/BoundedContext/Identity/User/Aggregate/User.php index f87def29..f84f718e 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Aggregate/User.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Aggregate/User.php @@ -39,13 +39,13 @@ public function accountDetails(): AccountDetails } public static function fromProperties( - Id $id, + Id $aggregateId, int $aggregateVersion, VerifiedEmail|UnverifiedEmail|VerifiedButRequestedNewEmail $primaryEmailStatus, HashedPassword $hashedPassword, AccountDetails $accountDetails ): User { - $user = new self($id, $aggregateVersion); + $user = new self($aggregateId, $aggregateVersion); $user->primaryEmailStatus = $primaryEmailStatus; $user->hashedPassword = $hashedPassword; diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Command/SignUp.php b/application/monolith/code/src/BoundedContext/Identity/User/Command/SignUp.php index ae6a5ea7..48096921 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Command/SignUp.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Command/SignUp.php @@ -12,7 +12,7 @@ class SignUp public string $username; - public string $termsOfUseAccepted; + public bool $termsOfUseAccepted; public array $metadata; } diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Command/VerifyPrimaryEmail.php b/application/monolith/code/src/BoundedContext/Identity/User/Command/VerifyPrimaryEmail.php index 37546a98..906761fa 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Command/VerifyPrimaryEmail.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Command/VerifyPrimaryEmail.php @@ -6,13 +6,7 @@ class VerifyPrimaryEmail { - /** - * @var array - */ - public $metadata; + public array $metadata; - /** - * @var string - */ - public $verificationCode; + public string $verificationCode; } diff --git a/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChange/RequestPrimaryEmailChangeHandler.php b/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChange/RequestPrimaryEmailChangeHandler.php index b7c219b6..c8a231ef 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChange/RequestPrimaryEmailChangeHandler.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChange/RequestPrimaryEmailChangeHandler.php @@ -7,6 +7,7 @@ use Galeas\Api\BoundedContext\Identity\User\Aggregate\User; use Galeas\Api\BoundedContext\Identity\User\Command\RequestPrimaryEmailChange; use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\SignUpHandler; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\VerifyPrimaryEmail\NoUserFoundForCode; use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailChangeRequested; use Galeas\Api\BoundedContext\Identity\User\ValueObject\VerifiedButRequestedNewEmail; use Galeas\Api\BoundedContext\Identity\User\ValueObject\UnverifiedEmail; @@ -18,21 +19,16 @@ use Galeas\Api\Common\Id\Id; use Galeas\Api\Common\Id\InvalidId; use Galeas\Api\Primitive\PrimitiveComparison\Email\AreEmailsEquivalent; +use Galeas\Api\Primitive\PrimitiveCreation\Email\EmailVerificationCodeCreator; use Galeas\Api\Primitive\PrimitiveValidation\Email\EmailValidator; use Galeas\Api\Service\EventStore\EventStore; use Galeas\Api\Service\Queue\Queue; class RequestPrimaryEmailChangeHandler { - /** - * @var EventStore - */ - private $eventStore; + private EventStore $eventStore; - /** - * @var IsEmailTaken - */ - private $isEmailTaken; + private IsEmailTaken $isEmailTaken; public function __construct( EventStore $eventStore, @@ -55,10 +51,14 @@ public function handle(RequestPrimaryEmailChange $command): void { $this->eventStore->beginTransaction(); - $user = $this->eventStore->find($command->authenticatedUserId); + $aggregateAndEventIds = $this->eventStore->find($command->authenticatedUserId); + if (null === $aggregateAndEventIds) { + throw new NoUserFoundForCode(); + } + $user = $aggregateAndEventIds->aggregate(); if (!($user instanceof User)) { - throw new UserNotFound(); + throw new NoUserFoundForCode(); } if ( @@ -113,11 +113,16 @@ public function handle(RequestPrimaryEmailChange $command): void throw new InvalidEmail(); } - $event = PrimaryEmailChangeRequested::fromProperties( - Id::fromId($command->authenticatedUserId), - Id::fromId($command->authenticatedUserId), + $event = PrimaryEmailChangeRequested::new( + Id::createNew(), + $user->aggregateId(), + $user->aggregateVersion() + 1, + $aggregateAndEventIds->lastEventId(), + $aggregateAndEventIds->firstEventId(), + new \DateTimeImmutable("now"), $command->metadata, $command->newEmailRequested, + EmailVerificationCodeCreator::create(), $user->hashedPassword()->hash() ); diff --git a/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmail/VerifyPrimaryEmailHandler.php b/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmail/VerifyPrimaryEmailHandler.php index 3bcd38ce..44ef65e9 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmail/VerifyPrimaryEmailHandler.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmail/VerifyPrimaryEmailHandler.php @@ -15,23 +15,15 @@ use Galeas\Api\Common\ExceptionBase\EventStoreCannotRead; use Galeas\Api\Common\ExceptionBase\EventStoreCannotWrite; use Galeas\Api\Common\ExceptionBase\ProjectionCannotRead; -use Galeas\Api\Common\ExceptionBase\QueuingFailure; use Galeas\Api\Common\Id\Id; use Galeas\Api\Common\Id\InvalidId; use Galeas\Api\Service\EventStore\EventStore; -use Galeas\Api\Service\Queue\Queue; class VerifyPrimaryEmailHandler { - /** - * @var EventStore - */ - private $eventStore; + private EventStore $eventStore; - /** - * @var UserIdFromPrimaryEmailVerificationCode - */ - private $userIdFromVerificationCode; + private UserIdFromPrimaryEmailVerificationCode $userIdFromVerificationCode; public function __construct( EventStore $eventStore, @@ -58,12 +50,14 @@ public function handle(VerifyPrimaryEmail $command): void throw new NoUserFoundForCode(); } - $authenticatedUserId = $userId; - $this->eventStore->beginTransaction(); - $user = $this->eventStore->find($userId); + $aggregateAndEventIds = $this->eventStore->find($userId); + if (null === $aggregateAndEventIds) { + throw new NoUserFoundForCode(); + } + $user = $aggregateAndEventIds->aggregate(); if (!($user instanceof User)) { throw new NoUserFoundForCode(); } @@ -87,8 +81,12 @@ public function handle(VerifyPrimaryEmail $command): void } $event = PrimaryEmailVerified::new( - Id::fromId($userId), - Id::fromId($authenticatedUserId), + Id::createNew(), + $user->aggregateId(), + $user->aggregateVersion() + 1, + $aggregateAndEventIds->lastEventId(), + $aggregateAndEventIds->firstEventId(), + new \DateTimeImmutable("now"), $command->metadata, $command->verificationCode ); diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCode.php b/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCode.php index b97f7f7c..275686ab 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCode.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCode.php @@ -6,15 +6,9 @@ class PrimaryEmailVerificationCode { - /** - * @var string - */ - private $id; + private string $id; - /** - * @var string|null - */ - private $primaryEmailVerificationCode; + private ?string $primaryEmailVerificationCode; private function __construct() { @@ -30,19 +24,13 @@ public function getPrimaryEmailVerificationCode(): ?string return $this->primaryEmailVerificationCode; } - /** - * @return $this - */ - public function updateVerificationCode(?string $primaryEmailVerificationCode) + public function updateVerificationCode(?string $primaryEmailVerificationCode): self { $this->primaryEmailVerificationCode = $primaryEmailVerificationCode; return $this; } - /** - * @return PrimaryEmailVerificationCode - */ public static function fromUserIdAndVerificationCode(string $userId, ?string $primaryEmailVerificationCode): self { $primaryEmailVerificationCodeObject = new self(); diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProcessor.php b/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProjector.php similarity index 88% rename from application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProcessor.php rename to application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProjector.php index c3e4b677..fb6d0db0 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProcessor.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProjector.php @@ -10,24 +10,18 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class PrimaryEmailVerificationCodeProcessor implements ProjectionEventProcessor +class PrimaryEmailVerificationCodeProjector implements EventProjector { - /** - * @var DocumentManager - */ - private $projectionDocumentManager; + private DocumentManager $projectionDocumentManager; public function __construct(DocumentManager $projectionDocumentManager) { $this->projectionDocumentManager = $projectionDocumentManager; } - /** - * {@inheritdoc} - */ - public function process(Event $event): void + public function project(Event $event): void { try { if ($event instanceof SignedUp) { diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCode.php b/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCode.php index 9a3b015d..a3913316 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCode.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCode.php @@ -10,10 +10,7 @@ class UserIdFromPrimaryEmailVerificationCode implements UserIdFromPrimaryEmailVerificationCodeVPE { - /** - * @var DocumentManager - */ - private $projectionDocumentManager; + private DocumentManager $projectionDocumentManager; public function __construct(DocumentManager $projectionDocumentManager) { diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProcessor.php b/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProjector.php similarity index 94% rename from application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProcessor.php rename to application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProjector.php index 0a9c7df3..a155de3f 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProcessor.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProjector.php @@ -10,9 +10,9 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class TakenEmailProcessor implements ProjectionEventProcessor +class TakenEmailProjector implements EventProjector { /** * @var DocumentManager @@ -27,7 +27,7 @@ public function __construct(DocumentManager $projectionDocumentManager) /** * {@inheritdoc} */ - public function process(Event $event): void + public function project(Event $event): void { try { if ( diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProcessor.php b/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProjector.php similarity index 90% rename from application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProcessor.php rename to application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProjector.php index 3d2ec41d..89f5b76d 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProcessor.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProjector.php @@ -8,9 +8,9 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class TakenUsernameProcessor implements ProjectionEventProcessor +class TakenUsernameProjector implements EventProjector { /** * @var DocumentManager @@ -25,7 +25,7 @@ public function __construct(DocumentManager $projectionDocumentManager) /** * {@inheritdoc} */ - public function process(Event $event): void + public function project(Event $event): void { try { if ($event instanceof SignedUp) { diff --git a/application/monolith/code/src/BoundedContext/Identity/User/Reaction/SendPrimaryEmailVerification/SendPrimaryEmailVerificationReactor.php b/application/monolith/code/src/BoundedContext/Identity/User/Reaction/SendPrimaryEmailVerification/SendPrimaryEmailVerificationReactor.php index 275f66a7..0f1a544a 100644 --- a/application/monolith/code/src/BoundedContext/Identity/User/Reaction/SendPrimaryEmailVerification/SendPrimaryEmailVerificationReactor.php +++ b/application/monolith/code/src/BoundedContext/Identity/User/Reaction/SendPrimaryEmailVerification/SendPrimaryEmailVerificationReactor.php @@ -4,6 +4,8 @@ namespace Galeas\Api\BoundedContext\Identity\User\Reaction\SendPrimaryEmailVerification; +use Galeas\Api\BoundedContext\Identity\User\Aggregate\User; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\VerifyPrimaryEmail\NoUserFoundForCode; use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailChangeRequested; use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailVerificationCodeSent; use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; @@ -11,12 +13,12 @@ use Galeas\Api\Common\ExceptionBase\EventStoreCannotRead; use Galeas\Api\Common\ExceptionBase\EventStoreCannotWrite; use Galeas\Api\Common\ExceptionBase\ProjectionCannotRead; -use Galeas\Api\Common\ExceptionBase\QueuingFailure; use Galeas\Api\Common\Id\Id; use Galeas\Api\Service\Email\Emailer; use Galeas\Api\Service\EventStore\EventStore; +use Galeas\Api\Service\QueueProcessor\EventReactor; -class SendPrimaryEmailVerificationReactor +class SendPrimaryEmailVerificationReactor implements EventReactor { private EventStore $eventStore; @@ -29,7 +31,7 @@ public function __construct(EventStore $eventStore, Emailer $emailer) { /** * @throws PrimaryEmailVerificationAlreadySent - * @throws ProjectionCannotRead|EventStoreCannotRead|EventStoreCannotWrite|QueuingFailure + * @throws ProjectionCannotRead|EventStoreCannotRead|EventStoreCannotWrite */ public function react(Event $event): void { @@ -47,32 +49,47 @@ public function react(Event $event): void $newEventId = Id::createNewByHashing( "Identity/User/PrimaryEmailVerificationSent:" . $event->eventId()->id() ); - $existingEvent = $this->eventStore->findEvent($newEventId->id()); - - if ($existingEvent instanceof Event) { + $existingReaction = $this->eventStore->findEvent($newEventId->id()); + if ($existingReaction instanceof Event) { throw new PrimaryEmailVerificationAlreadySent(); } + $fromEmailAddress = "system.development-application.example.com"; + $subjectLine = "Your Verification Code"; + $emailContents = "This is your verification code: https://example.com/page/?verificationCode=" . $verificationCode; $this->emailer->send( - "email@example.com", - "https://domain.example/frontend/verifyEmail?verificationCode=verificationCode", - "text" + $sendToEmailAddress, + $subjectLine, + $emailContents, + $fromEmailAddress ); - $event = PrimaryEmailVerificationCodeSent::fromProperties( - $newEventId, - $event->aggregateId(), - $event->eventId(), + $aggregateAndEventIds = $this->eventStore->find($existingReaction->aggregateId()->id()); + if (null === $aggregateAndEventIds) { + throw new NoUserFoundForCode(); + } + + $user = $aggregateAndEventIds->aggregate(); + if (!($user instanceof User)) { + throw new NoUserFoundForCode(); + } + + $newEvent = PrimaryEmailVerificationCodeSent::new( + Id::createNew(), + $user->aggregateId(), + $user->aggregateVersion() + 1, + $aggregateAndEventIds->lastEventId(), + $aggregateAndEventIds->firstEventId(), + new \DateTimeImmutable("now"), [], + $verificationCode, $sendToEmailAddress, - "This is your verification code: https://example.com/page/?verificationCodeode=" . $verificationCode + $emailContents, + $fromEmailAddress, + $subjectLine ); - $this->eventStore->save($event); - try { - $this->eventStore->completeTransaction(); - } catch (\Exception $e) { - // todo , duplicates -> return success - } + $this->eventStore->save($newEvent); + $this->eventStore->completeTransaction(); } } diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Aggregate/Session.php b/application/monolith/code/src/BoundedContext/Security/Session/Aggregate/Session.php index 34620959..319181a6 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Aggregate/Session.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Aggregate/Session.php @@ -33,12 +33,12 @@ public function sessionIsSignedOut(): ?SessionIsSignedOut } public static function fromProperties( - Id $id, - int $aggregateVersion, - SessionDetails $sessionDetails, + Id $aggregateId, + int $aggregateVersion, + SessionDetails $sessionDetails, ?SessionIsSignedOut $sessionIsSignedOut, ): self { - $session = new self($id, $aggregateVersion); + $session = new self($aggregateId, $aggregateVersion); $session->sessionDetails = $sessionDetails; $session->sessionIsSignedOut = $sessionIsSignedOut; diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Command/RefreshToken.php b/application/monolith/code/src/BoundedContext/Security/Session/Command/RefreshToken.php index 2d0fa442..d142e8a0 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Command/RefreshToken.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Command/RefreshToken.php @@ -6,23 +6,11 @@ class RefreshToken { - /** - * @var string - */ - public $authenticatedUserId; + public string $authenticatedUserId; - /** - * @var string - */ - public $withIp; + public string $withIp; - /** - * @var string - */ - public $withSessionToken; + public string $withSessionToken; - /** - * @var array - */ - public $metadata; + public array $metadata; } diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Command/SignOut.php b/application/monolith/code/src/BoundedContext/Security/Session/Command/SignOut.php index acd27489..64fce3a0 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Command/SignOut.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Command/SignOut.php @@ -6,23 +6,11 @@ class SignOut { - /** - * @var string - */ - public $authenticatedUserId; + public string $authenticatedUserId; - /** - * @var string - */ - public $withIp; + public string $withIp; - /** - * @var string - */ - public $withSessionToken; + public string $withSessionToken; - /** - * @var array - */ - public $metadata; + public array $metadata; } diff --git a/application/monolith/code/src/BoundedContext/Security/Session/CommandHandler/RefreshToken/RefreshTokenHandler.php b/application/monolith/code/src/BoundedContext/Security/Session/CommandHandler/RefreshToken/RefreshTokenHandler.php index e154cbd4..b69589d5 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/CommandHandler/RefreshToken/RefreshTokenHandler.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/CommandHandler/RefreshToken/RefreshTokenHandler.php @@ -12,20 +12,15 @@ use Galeas\Api\Common\ExceptionBase\ProjectionCannotRead; use Galeas\Api\Common\Id\Id; use Galeas\Api\Common\Id\InvalidId; +use Galeas\Api\Primitive\PrimitiveCreation\SessionToken\SessionTokenCreator; use Galeas\Api\Primitive\PrimitiveValidation\Ip\IpV4AndV6Validator; use Galeas\Api\Service\EventStore\EventStore; class RefreshTokenHandler { - /** - * @var EventStore - */ - private $eventStore; + private EventStore $eventStore; - /** - * @var SessionIdFromSessionToken - */ - private $sessionIdFromSessionToken; + private SessionIdFromSessionToken $sessionIdFromSessionToken; public function __construct( EventStore $eventStore, @@ -51,8 +46,13 @@ public function handle(RefreshToken $command): array $this->eventStore->beginTransaction(); - $session = $this->eventStore->find($sessionId); + $aggregateAndEventIds = $this->eventStore->find($command->authenticatedUserId); + if (null === $aggregateAndEventIds) { + throw new NoSessionFound(); + } + + $session = $aggregateAndEventIds->aggregate(); if (!($session instanceof Session)) { throw new NoSessionFound(); } @@ -69,12 +69,17 @@ public function handle(RefreshToken $command): array throw new InvalidIp(); } - $event = TokenRefreshed::fromProperties( + $event = TokenRefreshed::new( + Id::createNew(), $session->aggregateId(), - Id::fromId($command->authenticatedUserId), + $session->aggregateVersion() + 1, + $aggregateAndEventIds->lastEventId(), + $aggregateAndEventIds->firstEventId(), + new \DateTimeImmutable("now"), $command->metadata, $command->withIp, - $command->withSessionToken + $command->withSessionToken, + SessionTokenCreator::create() ); $this->eventStore->save($event); diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProcessor.php b/application/monolith/code/src/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProjector.php similarity index 91% rename from application/monolith/code/src/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProcessor.php rename to application/monolith/code/src/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProjector.php index 5d1ea30b..507dac58 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProcessor.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProjector.php @@ -8,9 +8,9 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class HashedPasswordProcessor implements ProjectionEventProcessor +class HashedPasswordProjector implements EventProjector { /** * @var DocumentManager @@ -25,7 +25,7 @@ public function __construct(DocumentManager $projectionDocumentManager) /** * {@inheritdoc} */ - public function process(Event $event): void + public function project(Event $event): void { try { $userId = null; diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Projection/Session/SessionProcessor.php b/application/monolith/code/src/BoundedContext/Security/Session/Projection/Session/SessionProjector.php similarity index 96% rename from application/monolith/code/src/BoundedContext/Security/Session/Projection/Session/SessionProcessor.php rename to application/monolith/code/src/BoundedContext/Security/Session/Projection/Session/SessionProjector.php index 6961f007..776cdb84 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Projection/Session/SessionProcessor.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Projection/Session/SessionProjector.php @@ -11,9 +11,9 @@ use Galeas\Api\BoundedContext\Security\Session\Event\TokenRefreshed; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class SessionProcessor implements ProjectionEventProcessor +class SessionProjector implements EventProjector { /** * @var DocumentManager @@ -28,7 +28,7 @@ public function __construct(DocumentManager $projectionDocumentManager) /** * {@inheritdoc} */ - public function process(Event $event): void + public function project(Event $event): void { try { if ($event instanceof SignedIn) { diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProcessor.php b/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProjector.php similarity index 95% rename from application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProcessor.php rename to application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProjector.php index 041c33dc..78c70a66 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProcessor.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProjector.php @@ -10,9 +10,9 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class UserWithEmailProcessor implements ProjectionEventProcessor +class UserWithEmailProjector implements EventProjector { /** * @var DocumentManager @@ -27,7 +27,7 @@ public function __construct(DocumentManager $projectionDocumentManager) /** * {@inheritdoc} */ - public function process(Event $event): void + public function project(Event $event): void { try { if ( diff --git a/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProcessor.php b/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProjector.php similarity index 91% rename from application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProcessor.php rename to application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProjector.php index 0e387365..00044ab1 100644 --- a/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProcessor.php +++ b/application/monolith/code/src/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProjector.php @@ -8,9 +8,9 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -use Galeas\Api\Service\QueueProcessor\ProjectionEventProcessor; +use Galeas\Api\Service\QueueProcessor\EventProjector; -class UserWithUsernameProcessor implements ProjectionEventProcessor +class UserWithUsernameProjector implements EventProjector { /** * @var DocumentManager @@ -25,7 +25,7 @@ public function __construct(DocumentManager $projectionDocumentManager) /** * {@inheritdoc} */ - public function process(Event $event): void + public function project(Event $event): void { try { $userId = null; diff --git a/application/monolith/code/src/Service/EventStore/AggregateAndEventIds.php b/application/monolith/code/src/Service/EventStore/AggregateAndEventIds.php new file mode 100644 index 00000000..c00b6fe0 --- /dev/null +++ b/application/monolith/code/src/Service/EventStore/AggregateAndEventIds.php @@ -0,0 +1,46 @@ +aggregate = $aggregate; + $aggregateAndEventIds->firstEventId = $firstEventId; + $aggregateAndEventIds->lastEventId = $lastEventId; + + return $aggregateAndEventIds; + } + + public function aggregate(): Aggregate + { + return $this->aggregate; + } + + public function firstEventId(): Id + { + return $this->firstEventId; + } + + public function lastEventId(): Id + { + return $this->lastEventId; + } + +} \ No newline at end of file diff --git a/application/monolith/code/src/Service/EventStore/EventStore.php b/application/monolith/code/src/Service/EventStore/EventStore.php index 1514bfa7..d399eed7 100644 --- a/application/monolith/code/src/Service/EventStore/EventStore.php +++ b/application/monolith/code/src/Service/EventStore/EventStore.php @@ -4,7 +4,6 @@ namespace Galeas\Api\Service\EventStore; -use Galeas\Api\Common\Aggregate\Aggregate; use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\EventStoreCannotRead; use Galeas\Api\Common\ExceptionBase\EventStoreCannotWrite; @@ -29,7 +28,7 @@ public function cancelTransaction(): void; /** * @throws EventStoreCannotRead */ - public function find(string $aggregateId): ?Aggregate; + public function find(string $aggregateId): ?AggregateAndEventIds; /** * @throws EventStoreCannotRead diff --git a/application/monolith/code/src/Service/EventStore/InMemoryEventStore.php b/application/monolith/code/src/Service/EventStore/InMemoryEventStore.php index 451baac1..e4af0f44 100644 --- a/application/monolith/code/src/Service/EventStore/InMemoryEventStore.php +++ b/application/monolith/code/src/Service/EventStore/InMemoryEventStore.php @@ -93,7 +93,7 @@ public function cancelTransaction(): void } } - public function find(string $aggregateId): ?Aggregate + public function find(string $aggregateId): ?AggregateAndEventIds { try { if (false === $this->isTransactionActive) { @@ -120,9 +120,14 @@ public function find(string $aggregateId): ?Aggregate return null; } - return AggregateFromEvents::aggregateFromEvents( - $creationEvent, - $transformationEvents + $count = count($transformationEvents); + return AggregateAndEventIds::fromProperties( + AggregateFromEvents::aggregateFromEvents( + $creationEvent, + $transformationEvents + ), + $creationEvent->eventId(), + $count > 0 ? $transformationEvents[$count - 1] : $creationEvent->eventId() ); } catch (\Throwable $exception) { throw new EventStoreCannotRead($exception); diff --git a/application/monolith/code/src/Service/EventStore/SQLEventStore.php b/application/monolith/code/src/Service/EventStore/SQLEventStore.php index 9368301b..a9e1ffe5 100644 --- a/application/monolith/code/src/Service/EventStore/SQLEventStore.php +++ b/application/monolith/code/src/Service/EventStore/SQLEventStore.php @@ -67,7 +67,7 @@ public function cancelTransaction(): void } } - public function find(string $aggregateId): ?Aggregate + public function find(string $aggregateId): ?AggregateAndEventIds { try { if (false === $this->connection->isTransactionActive()) { @@ -97,11 +97,17 @@ public function find(string $aggregateId): ?Aggregate }, $eventArrays); $creationEvent = array_shift($aggregateEvents); - $transformationEvents = $aggregateEvents; - - return AggregateFromEvents::aggregateFromEvents( - EventDeserializer::serializedEventsToEvents([$creationEvent])[0], - EventDeserializer::serializedEventsToEvents($transformationEvents) + $creationEvent = EventDeserializer::serializedEventsToEvents([$creationEvent])[0]; + $transformationEvents = EventDeserializer::serializedEventsToEvents($aggregateEvents); + + $count = count($transformationEvents); + return AggregateAndEventIds::fromProperties( + AggregateFromEvents::aggregateFromEvents( + $creationEvent, + $transformationEvents + ), + $creationEvent->eventId(), + $count > 0 ? $transformationEvents[$count - 1] : $creationEvent->eventId() ); } catch (\Throwable $exception) { throw new EventStoreCannotRead($exception); diff --git a/application/monolith/code/src/Service/QueueProcessor/ProjectionEventProcessor.php b/application/monolith/code/src/Service/QueueProcessor/EventProjector.php similarity index 73% rename from application/monolith/code/src/Service/QueueProcessor/ProjectionEventProcessor.php rename to application/monolith/code/src/Service/QueueProcessor/EventProjector.php index 5f01feb0..d4a81934 100644 --- a/application/monolith/code/src/Service/QueueProcessor/ProjectionEventProcessor.php +++ b/application/monolith/code/src/Service/QueueProcessor/EventProjector.php @@ -7,10 +7,10 @@ use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ProjectionCannotProcess; -interface ProjectionEventProcessor +interface EventProjector { /** * @throws ProjectionCannotProcess */ - public function process(Event $event): void; + public function project(Event $event): void; } diff --git a/application/monolith/code/src/Service/QueueProcessor/ReactionEventProcessor.php b/application/monolith/code/src/Service/QueueProcessor/EventReactor.php similarity index 73% rename from application/monolith/code/src/Service/QueueProcessor/ReactionEventProcessor.php rename to application/monolith/code/src/Service/QueueProcessor/EventReactor.php index 09d3c814..ee2432f2 100644 --- a/application/monolith/code/src/Service/QueueProcessor/ReactionEventProcessor.php +++ b/application/monolith/code/src/Service/QueueProcessor/EventReactor.php @@ -7,10 +7,10 @@ use Galeas\Api\Common\Event\Event; use Galeas\Api\Common\ExceptionBase\ReactionCannotProcess; -interface ReactionEventProcessor +interface EventReactor { /** * @throws ReactionCannotProcess */ - public function process(Event $event): void; + public function react(Event $event): void; } diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Aggregate/UserTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Aggregate/UserTest.php index b821a6dc..2abd13fc 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Aggregate/UserTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Aggregate/UserTest.php @@ -16,9 +16,6 @@ class UserTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $userId = Id::createNew(); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChangeHandlerTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChangeHandlerTest.php index 32d03279..330b571d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChangeHandlerTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/RequestPrimaryEmailChangeHandlerTest.php @@ -20,11 +20,6 @@ class RequestPrimaryEmailChangeHandlerTest extends HandlerTestBase { - /** - * @test - * - * @throws \Exception - */ public function testHandleForVerifiedEmail(): void { $signedUp = SignedUp::fromPropertiesAndDefaultOthers( @@ -103,9 +98,6 @@ function (string $email): bool { ); } - /** - * @test - */ public function testHandleForRequestedEmail(): void { $signedUp = SignedUp::fromPropertiesAndDefaultOthers( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/SignUpHandlerTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/SignUpHandlerTest.php index b425082e..2dc01e9d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/SignUpHandlerTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/SignUpHandlerTest.php @@ -5,9 +5,15 @@ namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\Identity\User\CommandHandler; use Galeas\Api\BoundedContext\Identity\User\Command\SignUp; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\EmailIsTaken; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\InvalidEmail; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\InvalidPassword; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\InvalidUsername; use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\IsEmailTaken; use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\IsUsernameTaken; use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\SignUpHandler; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\TermsAreNotAgreedTo; +use Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\UsernameIsTaken; use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\HandlerTestBase; @@ -20,14 +26,10 @@ class SignUpHandlerTest extends HandlerTestBase { - /** - * @test - */ public function testHandle(): void { $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithCallback( IsEmailTaken::class, 'isEmailTaken', @@ -63,12 +65,6 @@ function (string $username): bool { /** @var SignedUp $storedEvent */ $storedEvent = $this->getInMemoryEventStore()->storedEvents()[0]; - $queuedEvent = $this->getInMemoryQueue()->queuedEvents()[0]; - - Assert::assertEquals( - $storedEvent, - $queuedEvent - ); Assert::assertEquals( $command->primaryEmail, @@ -92,6 +88,14 @@ function (string $username): bool { $command->metadata, $storedEvent->metadata() ); + Assert::assertEquals( + $storedEvent->eventId(), + $storedEvent->correlationId() + ); + Assert::assertEquals( + $storedEvent->eventId(), + $storedEvent->causationId() + ); Assert::assertEquals( [ 'userId' => $storedEvent->aggregateId()->id(), @@ -100,14 +104,11 @@ function (string $username): bool { ); } - /** - * @expectedException \Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\InvalidEmail - */ public function testInvalidEmail(): void { + $this->expectException(InvalidEmail::class); $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithReturnValue( IsEmailTaken::class, 'isEmailTaken', @@ -130,14 +131,11 @@ public function testInvalidEmail(): void $handler->handle($command); } - /** - * @expectedException \Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\InvalidPassword - */ public function testInvalidPassword(): void { + $this->expectException(InvalidPassword::class); $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithReturnValue( IsEmailTaken::class, 'isEmailTaken', @@ -160,14 +158,11 @@ public function testInvalidPassword(): void $handler->handle($command); } - /** - * @expectedException \Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\InvalidUsername - */ public function testInvalidUsername(): void { + $this->expectException(InvalidUsername::class); $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithReturnValue( IsEmailTaken::class, 'isEmailTaken', @@ -190,14 +185,11 @@ public function testInvalidUsername(): void $handler->handle($command); } - /** - * @expectedException \Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\TermsAreNotAgreedTo - */ public function testTermsAreNotAgreedTo(): void { + $this->expectException(TermsAreNotAgreedTo::class); $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithReturnValue( IsEmailTaken::class, 'isEmailTaken', @@ -220,14 +212,11 @@ public function testTermsAreNotAgreedTo(): void $handler->handle($command); } - /** - * @expectedException \Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\EmailIsTaken - */ public function testEmailIsTaken(): void { + $this->expectException(EmailIsTaken::class); $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithReturnValue( IsEmailTaken::class, 'isEmailTaken', @@ -250,14 +239,11 @@ public function testEmailIsTaken(): void $handler->handle($command); } - /** - * @expectedException \Galeas\Api\BoundedContext\Identity\User\CommandHandler\SignUp\UsernameIsTaken - */ public function testUsernameIsTaken(): void { + $this->expectException(UsernameIsTaken::class); $handler = new SignUpHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithReturnValue( IsEmailTaken::class, 'isEmailTaken', diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmailHandlerTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmailHandlerTest.php index 66f4644c..7a98fd49 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmailHandlerTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/CommandHandler/VerifyPrimaryEmailHandlerTest.php @@ -17,23 +17,13 @@ use Tests\Galeas\Api\UnitAndIntegration\Primitive\PrimitiveValidation\Email\ValidVerificationCodes; use Tests\Galeas\Api\UnitAndIntegration\Primitive\PrimitiveValidation\Security\ValidPasswords; use Tests\Galeas\Api\UnitAndIntegration\Primitive\PrimitiveValidation\Username\ValidUsernames; +use Tests\Galeas\Api\UnitAndIntegration\Util\SampleEvents; class VerifyPrimaryEmailHandlerTest extends HandlerTestBase { - /** - * @test - * - * @throws \Exception - */ public function testHandleUnverifiedEmail(): void { - $signedUp = SignedUp::fromPropertiesAndDefaultOthers( - $this->mockMetadata(), - ValidEmails::listValidEmails()[0], - ValidPasswords::listValidPasswords()[0], - ValidUsernames::listValidUsernames()[0], - true - ); + $signedUp = SampleEvents::signedUp(); $eventStore = $this->getInMemoryEventStore(); $eventStore->beginTransaction(); $eventStore->save($signedUp); @@ -41,7 +31,6 @@ public function testHandleUnverifiedEmail(): void $handler = new VerifyPrimaryEmailHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithCallback( UserIdFromPrimaryEmailVerificationCode::class, 'userIdFromPrimaryEmailVerificationCode', @@ -57,33 +46,20 @@ function (string $primaryEmailVerificationCode) use ($signedUp): ?string { $command = new VerifyPrimaryEmail(); $command->verificationCode = $signedUp->primaryEmailVerificationCode(); - $command->metadata = $this->mockMetadata(); + $command->metadata = $signedUp->metadata(); $handler->handle($command); $storedEvent = $this->getInMemoryEventStore()->storedEvents()[1]; - $queuedEvent = $this->getInMemoryQueue()->queuedEvents()[0]; - if ( - null === $storedEvent->authenticatedUserId() || - (!($storedEvent instanceof PrimaryEmailVerified)) || - (!($queuedEvent instanceof PrimaryEmailVerified)) - ) { + if (!$storedEvent instanceof PrimaryEmailVerified) { throw new \Exception(); } - Assert::assertEquals( - $storedEvent, - $queuedEvent - ); Assert::assertEquals( $command->verificationCode, $storedEvent->verifiedWithCode() ); - Assert::assertEquals( - $signedUp->aggregateId()->id(), - $storedEvent->authenticatedUserId()->id() - ); Assert::assertEquals( $signedUp->aggregateId()->id(), $storedEvent->aggregateId()->id() @@ -94,23 +70,14 @@ function (string $primaryEmailVerificationCode) use ($signedUp): ?string { ); } - /** - * @test - */ public function testHandleRequestedEmail(): void { - $signedUp = SignedUp::fromPropertiesAndDefaultOthers( - $this->mockMetadata(), - ValidEmails::listValidEmails()[0], - ValidPasswords::listValidPasswords()[0], - ValidUsernames::listValidUsernames()[0], - true - ); - $primaryEmailVerified = PrimaryEmailVerified::new( + $signedUp = SampleEvents::signedUp(); + $primaryEmailVerified = SampleEvents::primaryEmailVerified( $signedUp->aggregateId(), - $signedUp->aggregateId(), - $this->mockMetadata(), - $signedUp->primaryEmailVerificationCode() + 2, + $signedUp->eventId(), + $signedUp->eventId() ); $requestedEmail = PrimaryEmailChangeRequested::fromProperties( $signedUp->aggregateId(), @@ -129,7 +96,6 @@ public function testHandleRequestedEmail(): void $handler = new VerifyPrimaryEmailHandler( $this->getInMemoryEventStore(), - $this->getInMemoryQueue(), $this->mockForCommandHandlerWithCallback( UserIdFromPrimaryEmailVerificationCode::class, 'userIdFromPrimaryEmailVerificationCode', @@ -150,13 +116,8 @@ function (string $primaryEmailVerificationCode) use ($requestedEmail): ?string { $handler->handle($command); $storedEvent = $this->getInMemoryEventStore()->storedEvents()[3]; - $queuedEvent = $this->getInMemoryQueue()->queuedEvents()[0]; - if ( - null === $storedEvent->authenticatedUserId() || - (!($storedEvent instanceof PrimaryEmailVerified)) || - (!($queuedEvent instanceof PrimaryEmailVerified)) - ) { + if (!$storedEvent instanceof PrimaryEmailVerified) { throw new \Exception(); } diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProjectorTest.php similarity index 88% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProjectorTest.php index 69c03a55..5f00315d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeProjectorTest.php @@ -8,22 +8,17 @@ use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailVerified; use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\BoundedContext\Identity\User\Projection\PrimaryEmailVerificationCode\PrimaryEmailVerificationCode; -use Galeas\Api\BoundedContext\Identity\User\Projection\PrimaryEmailVerificationCode\PrimaryEmailVerificationCodeProcessor; +use Galeas\Api\BoundedContext\Identity\User\Projection\PrimaryEmailVerificationCode\PrimaryEmailVerificationCodeProjector; use Galeas\Api\Common\Id\Id; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class PrimaryEmailVerificationCodeProcessorTest extends KernelTestBase +class PrimaryEmailVerificationCodeProjectorTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testProcessSignedUp(): void { $processorService = $this->getContainer() - ->get(PrimaryEmailVerificationCodeProcessor::class); + ->get(PrimaryEmailVerificationCodeProjector::class); $signedUp = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -47,15 +42,10 @@ public function testProcessSignedUp(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessPrimaryEmailChangeRequested(): void { $processorService = $this->getContainer() - ->get(PrimaryEmailVerificationCodeProcessor::class); + ->get(PrimaryEmailVerificationCodeProjector::class); $primaryEmailChangeRequested = PrimaryEmailChangeRequested::fromProperties( Id::createNew(), @@ -79,15 +69,10 @@ public function testProcessPrimaryEmailChangeRequested(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessPrimaryEmailVerifiedAfterSignedUp(): void { $processorService = $this->getContainer() - ->get(PrimaryEmailVerificationCodeProcessor::class); + ->get(PrimaryEmailVerificationCodeProjector::class); $signedUp = SignedUp::fromPropertiesAndDefaultOthers( [], diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeTest.php index 098b8a3d..9b83e807 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/PrimaryEmailVerificationCodeTest.php @@ -10,9 +10,6 @@ class PrimaryEmailVerificationCodeTest extends UnitTestBase { - /** - * @test - */ public function testPrimaryEmailVerificationCode(): void { // start with code_123_test diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCodeTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCodeTest.php index 715d6402..8cc0e877 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCodeTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/PrimaryEmailVerificationCode/UserIdFromPrimaryEmailVerificationCodeTest.php @@ -11,11 +11,6 @@ class UserIdFromPrimaryEmailVerificationCodeTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testUserIdFromPrimaryEmailVerificationCode(): void { $userIdService = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/IsEmailTakenTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/IsEmailTakenTest.php index 10b1d0f8..3a1aed26 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/IsEmailTakenTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/IsEmailTakenTest.php @@ -11,11 +11,6 @@ class IsEmailTakenTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testIsEmailTaken(): void { $isEmailTakenService = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProjectorTest.php similarity index 82% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProjectorTest.php index 545aca96..f86ab37f 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailProjectorTest.php @@ -8,22 +8,17 @@ use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailVerified; use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\BoundedContext\Identity\User\Projection\TakenEmail\TakenEmail; -use Galeas\Api\BoundedContext\Identity\User\Projection\TakenEmail\TakenEmailProcessor; +use Galeas\Api\BoundedContext\Identity\User\Projection\TakenEmail\TakenEmailProjector; use Galeas\Api\Common\Id\Id; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class TakenEmailProcessorTest extends KernelTestBase +class TakenEmailProjectorTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testProcessSignedUp(): void { - $takenEmailProcessorService = $this->getContainer() - ->get(TakenEmailProcessor::class); + $TakenEmailProjectorService = $this->getContainer() + ->get(TakenEmailProjector::class); $signedUp = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -33,7 +28,7 @@ public function testProcessSignedUp(): void false ); $userId = $signedUp->aggregateId()->id(); - $takenEmailProcessorService->process($signedUp); + $TakenEmailProjectorService->process($signedUp); Assert::assertEquals( [ @@ -47,15 +42,10 @@ public function testProcessSignedUp(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessSignedUpForTwoUsers(): void { - $takenEmailProcessorService = $this->getContainer() - ->get(TakenEmailProcessor::class); + $TakenEmailProjectorService = $this->getContainer() + ->get(TakenEmailProjector::class); $signedUp1 = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -73,8 +63,8 @@ public function testProcessSignedUpForTwoUsers(): void ); $userId1 = $signedUp1->aggregateId()->id(); $userId2 = $signedUp2->aggregateId()->id(); - $takenEmailProcessorService->process($signedUp1); - $takenEmailProcessorService->process($signedUp2); + $TakenEmailProjectorService->process($signedUp1); + $TakenEmailProjectorService->process($signedUp2); Assert::assertEquals( [ @@ -98,15 +88,10 @@ public function testProcessSignedUpForTwoUsers(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessPrimaryEmailVerified(): void { - $takenEmailProcessorService = $this->getContainer() - ->get(TakenEmailProcessor::class); + $TakenEmailProjectorService = $this->getContainer() + ->get(TakenEmailProjector::class); $takenEmail = TakenEmail::fromUserIdAndEmails( Id::createNew()->id(), @@ -123,7 +108,7 @@ public function testProcessPrimaryEmailVerified(): void 'code' ); $userId = $signedUp->aggregateId()->id(); - $takenEmailProcessorService->process($signedUp); + $TakenEmailProjectorService->process($signedUp); Assert::assertEquals( [ @@ -137,15 +122,10 @@ public function testProcessPrimaryEmailVerified(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessPrimaryEmailChangeRequested(): void { - $takenEmailProcessorService = $this->getContainer() - ->get(TakenEmailProcessor::class); + $TakenEmailProjectorService = $this->getContainer() + ->get(TakenEmailProjector::class); $takenEmail = TakenEmail::fromUserIdAndEmails( Id::createNew()->id(), @@ -163,7 +143,7 @@ public function testProcessPrimaryEmailChangeRequested(): void 'fake_hashed_password' ); $userId = $signedUp->aggregateId()->id(); - $takenEmailProcessorService->process($signedUp); + $TakenEmailProjectorService->process($signedUp); Assert::assertEquals( [ diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailTest.php index a50e7e7b..72b77d92 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenEmail/TakenEmailTest.php @@ -10,9 +10,6 @@ class TakenEmailTest extends UnitTestBase { - /** - * @test - */ public function testTakenEmail(): void { $takenEmail = TakenEmail::fromUserIdAndEmails( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/IsUsernameTakenTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/IsUsernameTakenTest.php index 8b1c452a..d7fbe458 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/IsUsernameTakenTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/IsUsernameTakenTest.php @@ -11,11 +11,6 @@ class IsUsernameTakenTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testIsUsernameTaken(): void { $isUsernameTakenService = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProjectorTest.php similarity index 84% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProjectorTest.php index a0bfd00a..65daeb65 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameProjectorTest.php @@ -6,21 +6,16 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\BoundedContext\Identity\User\Projection\TakenUsername\TakenUsername; -use Galeas\Api\BoundedContext\Identity\User\Projection\TakenUsername\TakenUsernameProcessor; +use Galeas\Api\BoundedContext\Identity\User\Projection\TakenUsername\TakenUsernameProjector; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class TakenUsernameProcessorTest extends KernelTestBase +class TakenUsernameProjectorTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testProcessSignedUpWithTwoUsers(): void { - $takenUsernameProcessorService = $this->getContainer() - ->get(TakenUsernameProcessor::class); + $TakenUsernameProjectorService = $this->getContainer() + ->get(TakenUsernameProjector::class); $signedUp1 = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -39,8 +34,8 @@ public function testProcessSignedUpWithTwoUsers(): void $userId1 = $signedUp1->aggregateId()->id(); $userId2 = $signedUp2->aggregateId()->id(); - $takenUsernameProcessorService->process($signedUp1); - $takenUsernameProcessorService->process($signedUp2); + $TakenUsernameProjectorService->process($signedUp1); + $TakenUsernameProjectorService->process($signedUp2); $takenUsernames = $this->findTakenUsernames($userId1); Assert::assertEquals( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameTest.php index 422c5ad3..d2caa3c3 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/Projection/TakenUsername/TakenUsernameTest.php @@ -10,9 +10,6 @@ class TakenUsernameTest extends UnitTestBase { - /** - * @test - */ public function testTakenUsername(): void { $takenUsername = TakenUsername::fromUserIdAndUsername( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/AccountDetailsTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/AccountDetailsTest.php index f0edd8dc..e49836b1 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/AccountDetailsTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/AccountDetailsTest.php @@ -10,9 +10,6 @@ class AccountDetailsTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $accountDetails = AccountDetails::fromDetails( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/EmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/EmailTest.php index 64be1670..eec48a18 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/EmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/EmailTest.php @@ -10,9 +10,6 @@ class EmailTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $email = Email::fromEmail('test@example.com'); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/HashedPasswordTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/HashedPasswordTest.php index edd689ec..62b49ced 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/HashedPasswordTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/HashedPasswordTest.php @@ -10,9 +10,6 @@ class HashedPasswordTest extends UnitTestBase { - /** - * @test - */ public function testValid(): void { $hashedPassword = HashedPassword::fromHash('0123456789abcdef'); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/RequestedNewEmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/RequestedNewEmailTest.php index 424c6732..e225d117 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/RequestedNewEmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/RequestedNewEmailTest.php @@ -12,9 +12,6 @@ class RequestedNewEmailTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $verifiedEmail = Email::fromEmail('test@example.com'); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/UnverifiedEmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/UnverifiedEmailTest.php index 788940c1..723d6963 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/UnverifiedEmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/UnverifiedEmailTest.php @@ -12,9 +12,6 @@ class UnverifiedEmailTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $email = Email::fromEmail('test@example.com'); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerificationCodeTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerificationCodeTest.php index 843f1025..13ba6fde 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerificationCodeTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerificationCodeTest.php @@ -10,9 +10,6 @@ class VerificationCodeTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $verificationCode = VerificationCode::fromVerificationCode('abchan1237123'); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerifiedEmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerifiedEmailTest.php index c81c90cd..3120e0fb 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerifiedEmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Identity/User/ValueObject/VerifiedEmailTest.php @@ -11,9 +11,6 @@ class VerifiedEmailTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $email = Email::fromEmail('test@example.com'); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/RefreshTokenHandlerTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/RefreshTokenHandlerTest.php index e800dd78..8e62feb6 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/RefreshTokenHandlerTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/RefreshTokenHandlerTest.php @@ -19,9 +19,6 @@ class RefreshTokenHandlerTest extends HandlerTestBase { - /** - * @test - */ public function testHandle(): void { $signedIn = SignedIn::fromProperties( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignInHandlerTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignInHandlerTest.php index 1a882b16..c5aecbcc 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignInHandlerTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignInHandlerTest.php @@ -22,11 +22,6 @@ class SignInHandlerTest extends HandlerTestBase { - /** - * @test - * - * @throws \Exception - */ public function testHandleWithUsername(): void { $userIdFromSignInUsername = Id::createNew(); @@ -117,11 +112,6 @@ function (string $userId) use ($userIdFromSignInUsername, $hashedPassword): ?str ); } - /** - * @test - * - * @throws \Exception - */ public function testHandleWithEmail(): void { $userIdFromSignInEmail = Id::createNew(); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignOutHandlerTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignOutHandlerTest.php index 1255d64f..65faa076 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignOutHandlerTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/CommandHandler/SignOutHandlerTest.php @@ -18,11 +18,6 @@ class SignOutHandlerTest extends HandlerTestBase { - /** - * @test - * - * @throws \Exception - */ public function testHandle(): void { $signedIn = SignedIn::fromProperties( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedInTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedInTest.php index ba4e395b..5b7984f3 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedInTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedInTest.php @@ -4,6 +4,7 @@ namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\Security\Session\Event; +use Galeas\Api\BoundedContext\Security\Session\Aggregate\Session; use Galeas\Api\BoundedContext\Security\Session\Event\SignedIn; use Galeas\Api\BoundedContext\Security\Session\ValueObject\SessionDetails; use Galeas\Api\Common\Id\Id; @@ -12,9 +13,6 @@ class SignedInTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $eventId = Id::createNew(); @@ -25,7 +23,7 @@ public function testCreate(): void $signedIn = SignedIn::new( $eventId, $aggregateId, - 1432, + 1, $causationId, $correlationId, new \DateTimeImmutable("2024-01-03 10:35:23"), @@ -40,46 +38,81 @@ public function testCreate(): void ); Assert::assertEquals( - - ); - } - - /** - * @test - */ - public function testCreateAggregate(): void - { - $signedIn = SignedIn::fromProperties( - [1, 2, 3], - Id::createNew(), - 'test_username', - 'test_email', - 'test_hashed_password', - 'by_device_label', - '127.0.0.1' - ); - - $session = $signedIn->createSession(); - - Assert::assertEquals( - $signedIn->aggregateId(), - $session->id() - ); - Assert::assertEquals( - SessionDetails::fromProperties( + [ + $eventId, + $aggregateId, + 1, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + $userId, + 'UserNameBob', + null, + 'HashedPassword819', + 'DeviceIphoneFrom2023', + "201.201.20.201", + "SessionTokenCreatedForSessionblablabla909090" + ], + [ + $signedIn->eventId(), + $signedIn->aggregateId(), + $signedIn->aggregateVersion(), + $signedIn->causationId(), + $signedIn->correlationId(), + $signedIn->recordedOn(), + $signedIn->metadata(), $signedIn->asUser(), $signedIn->withUsername(), $signedIn->withEmail(), $signedIn->withHashedPassword(), $signedIn->byDeviceLabel(), $signedIn->withIp(), - $signedIn->sessionTokenCreated() - ), - $session->sessionDetails() + $signedIn->sessionTokenCreated(), + ] ); - Assert::assertEquals( + } + + public function testCreateAggregate(): void + { + $eventId = Id::createNew(); + $aggregateId = Id::createNew(); + $causationId = $eventId; + $correlationId = $eventId; + $userId = Id::createNew(); + $signedIn = SignedIn::new( + $eventId, + $aggregateId, + 1, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + $userId, + 'UserNameBob', null, - $session->sessionIsSignedOut() + 'HashedPassword819', + 'DeviceIphoneFrom2023', + "201.201.20.201", + "SessionTokenCreatedForSessionblablabla909090" + ); + + Assert::assertEquals( + $signedIn->createSession(), + Session::fromProperties( + $signedIn->aggregateId(), + $signedIn->aggregateVersion(), + SessionDetails::fromProperties( + $signedIn->asUser(), + $signedIn->withUsername(), + $signedIn->withEmail(), + $signedIn->withHashedPassword(), + $signedIn->byDeviceLabel(), + $signedIn->withIp(), + $signedIn->sessionTokenCreated(), + ), + null + ) ); } } diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedOutTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedOutTest.php index f01f0b02..89b94553 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedOutTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/SignedOutTest.php @@ -5,48 +5,67 @@ namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\Security\Session\Event; use Galeas\Api\BoundedContext\Security\Session\Aggregate\Session; +use Galeas\Api\BoundedContext\Security\Session\Event\SignedIn; use Galeas\Api\BoundedContext\Security\Session\Event\SignedOut; +use Galeas\Api\BoundedContext\Security\Session\Event\TokenRefreshed; use Galeas\Api\BoundedContext\Security\Session\ValueObject\SessionDetails; use Galeas\Api\BoundedContext\Security\Session\ValueObject\SessionIsSignedOut; use Galeas\Api\Common\Id\Id; +use Galeas\Api\Primitive\PrimitiveValidation\Session\SessionTokenValidator; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\UnitTestBase; class SignedOutTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { + $eventId = Id::createNew(); $aggregateId = Id::createNew(); - $authenticatedUserId = Id::createNew(); - $metadata = [1, 2, 3]; - $withIp = '127.0.0.1'; - $withSessionToken = 'session_token'; - - $signedOut = SignedOut::fromProperties( + $causationId = $eventId; + $correlationId = $eventId; + $signedOut = SignedOut::new( + $eventId, $aggregateId, - $authenticatedUserId, - $metadata, - $withIp, - $withSessionToken + 1, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + "201.201.20.201", + 'existingSessionToken', + ); + + Assert::assertEquals( + [ + $eventId, + $aggregateId, + 1, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + "201.201.20.201", + 'existingSessionToken', + ], + [ + $signedOut->eventId(), + $signedOut->aggregateId(), + $signedOut->aggregateVersion(), + $signedOut->causationId(), + $signedOut->correlationId(), + $signedOut->recordedOn(), + $signedOut->metadata(), + $signedOut->withIp(), + $signedOut->withSessionToken(), + ] ); - - Assert::assertEquals($aggregateId, $signedOut->aggregateId()); - Assert::assertEquals($authenticatedUserId, $signedOut->authenticatedUserId()); - Assert::assertEquals($metadata, $signedOut->metadata()); - Assert::assertEquals($withIp, $signedOut->withIp()); - Assert::assertEquals($withSessionToken, $signedOut->withSessionToken()); } - /** - * @test - */ public function testTransformAggregate(): void { $session = Session::fromProperties( Id::createNew(), + 1, SessionDetails::fromProperties( Id::createNew(), 'test_username', @@ -54,35 +73,40 @@ public function testTransformAggregate(): void 'test_hashed_password', 'by_device_label', '127.0.0.1', - 'with_session_token' + 'old_session_token' ), null ); - $signedOut = SignedOut::fromProperties( - Id::createNew(), - Id::createNew(), - [1, 2, 3], - '127.0.0.2', - 'new_session_token' + $eventId = Id::createNew(); + $aggregateId = Id::createNew(); + $causationId = $eventId; + $correlationId = $eventId; + $signedOut = SignedOut::new( + $eventId, + $aggregateId, + 2, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + "201.201.20.201", + 'new_session_token', ); $transformedSession = $signedOut->transformSession($session); Assert::assertEquals( - $session->aggregateId(), - $transformedSession->id() - ); - Assert::assertEquals( - $session->sessionDetails(), - $transformedSession->sessionDetails() - ); - Assert::assertEquals( - SessionIsSignedOut::fromProperties( - $signedOut->withSessionToken(), - $signedOut->withIp() + Session::fromProperties( + $session->aggregateId(), + 2, + $session->sessionDetails(), + SessionIsSignedOut::fromProperties( + $signedOut->withSessionToken(), + $signedOut->withIp() + ) ), - $transformedSession->sessionIsSignedOut() + $transformedSession ); } } diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/TokenRefreshedTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/TokenRefreshedTest.php index 32915af6..28bc94b9 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/TokenRefreshedTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Event/TokenRefreshedTest.php @@ -5,6 +5,7 @@ namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\Security\Session\Event; use Galeas\Api\BoundedContext\Security\Session\Aggregate\Session; +use Galeas\Api\BoundedContext\Security\Session\Event\SignedIn; use Galeas\Api\BoundedContext\Security\Session\Event\TokenRefreshed; use Galeas\Api\BoundedContext\Security\Session\ValueObject\SessionDetails; use Galeas\Api\Common\Id\Id; @@ -14,46 +15,58 @@ class TokenRefreshedTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { + $eventId = Id::createNew(); $aggregateId = Id::createNew(); - $authenticatedUserId = Id::createNew(); - $metadata = [1, 2, 3]; - $withIp = '127.0.0.1'; - $withSessionToken = 'session_token'; - - $tokenRefreshed = TokenRefreshed::fromProperties( + $causationId = $eventId; + $correlationId = $eventId; + $tokenRefreshed = TokenRefreshed::new( + $eventId, $aggregateId, - $authenticatedUserId, - $metadata, - $withIp, - $withSessionToken + 1, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + "201.201.20.201", + 'existingSessionToken', + 'refreshedSessionToken', ); - - Assert::assertEquals($aggregateId, $tokenRefreshed->aggregateId()); - Assert::assertEquals($authenticatedUserId, $tokenRefreshed->authenticatedUserId()); - Assert::assertEquals($metadata, $tokenRefreshed->metadata()); - Assert::assertEquals($withIp, $tokenRefreshed->withIp()); - Assert::assertEquals($withSessionToken, $tokenRefreshed->withExistingSessionToken()); - Assert::assertTrue( - SessionTokenValidator::isValid( - $tokenRefreshed->refreshedSessionToken() - ) + + Assert::assertEquals( + [ + $eventId, + $aggregateId, + 1, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + "201.201.20.201", + 'existingSessionToken', + 'refreshedSessionToken', + ], + [ + $tokenRefreshed->eventId(), + $tokenRefreshed->aggregateId(), + $tokenRefreshed->aggregateVersion(), + $tokenRefreshed->causationId(), + $tokenRefreshed->correlationId(), + $tokenRefreshed->recordedOn(), + $tokenRefreshed->metadata(), + $tokenRefreshed->withIp(), + $tokenRefreshed->withExistingSessionToken(), + $tokenRefreshed->refreshedSessionToken(), + ] ); - Assert::assertNotEquals( - $tokenRefreshed->withExistingSessionToken(), $tokenRefreshed->refreshedSessionToken()); } - /** - * @test - */ public function testTransformAggregate(): void { $session = Session::fromProperties( Id::createNew(), + 1, SessionDetails::fromProperties( Id::createNew(), 'test_username', @@ -66,35 +79,41 @@ public function testTransformAggregate(): void null ); - $signedOut = TokenRefreshed::fromProperties( - Id::createNew(), - Id::createNew(), - [1, 2, 3], - '127.0.0.2', - 'new_session_token' + $eventId = Id::createNew(); + $aggregateId = Id::createNew(); + $causationId = $eventId; + $correlationId = $eventId; + $tokenRefreshed = TokenRefreshed::new( + $eventId, + $aggregateId, + 2, + $causationId, + $correlationId, + new \DateTimeImmutable("2024-01-03 10:35:23"), + ["metadataField" => "hello world 123"], + "201.201.20.201", + 'existingSessionToken', + 'refreshedSessionToken', ); - $transformedSession = $signedOut->transformSession($session); + $transformedSession = $tokenRefreshed->transformSession($session); Assert::assertEquals( - $session->aggregateId(), - $transformedSession->id() - ); - Assert::assertEquals( - SessionDetails::fromProperties( - $session->sessionDetails()->asUser(), - $session->sessionDetails()->withUsername(), - $session->sessionDetails()->withEmail(), - $session->sessionDetails()->withHashedPassword(), - $session->sessionDetails()->byDeviceLabel(), - $signedOut->withIp(), - $signedOut->refreshedSessionToken() + Session::fromProperties( + $session->aggregateId(), + 2, + SessionDetails::fromProperties( + $session->sessionDetails()->asUser(), + $session->sessionDetails()->withUsername(), + $session->sessionDetails()->withEmail(), + $session->sessionDetails()->withHashedPassword(), + $session->sessionDetails()->byDeviceLabel(), + $tokenRefreshed->withIp(), + $tokenRefreshed->refreshedSessionToken() + ), + $session->sessionIsSignedOut() ), - $transformedSession->sessionDetails() - ); - Assert::assertEquals( - $session->sessionIsSignedOut(), - $transformedSession->sessionIsSignedOut() + $transformedSession ); } } diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordFromUserIdTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordFromUserIdTest.php index 5859905e..6a0b173c 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordFromUserIdTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordFromUserIdTest.php @@ -11,9 +11,6 @@ class HashedPasswordFromUserIdTest extends KernelTestBase { - /** - * @test - */ public function testHashedPasswordFromUserId(): void { $hashedPasswordFromUserIdService = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProjectorTest.php similarity index 88% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProjectorTest.php index e6d0d0eb..e3c3997c 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordProjectorTest.php @@ -6,19 +6,16 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\BoundedContext\Security\Session\Projection\HashedPassword\HashedPassword; -use Galeas\Api\BoundedContext\Security\Session\Projection\HashedPassword\HashedPasswordProcessor; +use Galeas\Api\BoundedContext\Security\Session\Projection\HashedPassword\HashedPasswordProjector; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class HashedPasswordProcessorTest extends KernelTestBase +class HashedPasswordProjectorTest extends KernelTestBase { - /** - * @test - */ - public function testHashedPasswordProcessor(): void + public function testHashedPasswordProjector(): void { - $hashedPasswordProcessor = $this->getContainer() - ->get(HashedPasswordProcessor::class); + $HashedPasswordProjector = $this->getContainer() + ->get(HashedPasswordProjector::class); $signedUp1 = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -48,8 +45,8 @@ public function testHashedPasswordProcessor(): void ) ); - $hashedPasswordProcessor->process($signedUp1); - $hashedPasswordProcessor->process($signedUp1); // test idempotency + $HashedPasswordProjector->process($signedUp1); + $HashedPasswordProjector->process($signedUp1); // test idempotency Assert::assertCount( 1, $this->findHashedPasswordsByUserId( @@ -75,7 +72,7 @@ public function testHashedPasswordProcessor(): void ) ); - $hashedPasswordProcessor->process($signedUp2); + $HashedPasswordProjector->process($signedUp2); Assert::assertCount( 1, $this->findHashedPasswordsByUserId( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordTest.php index b1ff2ece..eaeb4392 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/HashedPassword/HashedPasswordTest.php @@ -10,9 +10,6 @@ class HashedPasswordTest extends UnitTestBase { - /** - * @test - */ public function testHashedPassword(): void { $hashedPassword = HashedPassword::fromUserIdAndHashedPassword( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionIdFromSessionTokenTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionIdFromSessionTokenTest.php index 862be1a7..0a466a02 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionIdFromSessionTokenTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionIdFromSessionTokenTest.php @@ -11,9 +11,6 @@ class SessionIdFromSessionTokenTest extends KernelTestBase { - /** - * @test - */ public function testSessionIdFromSessionToken(): void { $sessionIdFromSessionToken = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionProjectorTest.php similarity index 91% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionProjectorTest.php index c737e890..1330625b 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionProjectorTest.php @@ -8,19 +8,16 @@ use Galeas\Api\BoundedContext\Security\Session\Event\SignedOut; use Galeas\Api\BoundedContext\Security\Session\Event\TokenRefreshed; use Galeas\Api\BoundedContext\Security\Session\Projection\Session\Session; -use Galeas\Api\BoundedContext\Security\Session\Projection\Session\SessionProcessor; +use Galeas\Api\BoundedContext\Security\Session\Projection\Session\SessionProjector; use Galeas\Api\Common\Id\Id; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class SessionProcessorTest extends KernelTestBase +class SessionProjectorTest extends KernelTestBase { - /** - * @test - */ public function testProcessSignedIn(): void { - $sessionProcessor = $this->getContainer() - ->get(SessionProcessor::class); + $SessionProjector = $this->getContainer() + ->get(SessionProjector::class); $signedIn = SignedIn::fromProperties( [], @@ -32,7 +29,7 @@ public function testProcessSignedIn(): void '127.128.129.130' ); - $sessionProcessor->process($signedIn); + $SessionProjector->process($signedIn); // This make sure mongo is restoring DateTimeImmutable correctly. // The Session object with DateTimeImmutable gets recreated and rehydrated. // It's not necessary in every test, but having it here makes sure that @@ -73,7 +70,7 @@ public function testProcessSignedIn(): void ); // test idempotency - $sessionProcessor->process($signedIn); + $SessionProjector->process($signedIn); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -109,13 +106,10 @@ public function testProcessSignedIn(): void ); } - /** - * @test - */ public function testProcessTokenRefreshed(): void { - $sessionProcessor = $this->getContainer() - ->get(SessionProcessor::class); + $SessionProjector = $this->getContainer() + ->get(SessionProjector::class); $sessionId = Id::createNew(); $asUser = Id::createNew(); @@ -129,7 +123,7 @@ public function testProcessTokenRefreshed(): void $existingSessionToken ); - $sessionProcessor->process($tokenRefreshed); + $SessionProjector->process($tokenRefreshed); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -165,7 +159,7 @@ public function testProcessTokenRefreshed(): void ); // test idempotency - $sessionProcessor->process($tokenRefreshed); + $SessionProjector->process($tokenRefreshed); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -201,13 +195,10 @@ public function testProcessTokenRefreshed(): void ); } - /** - * @test - */ public function testProcessSignedInThenTokenRefreshed(): void { - $sessionProcessor = $this->getContainer() - ->get(SessionProcessor::class); + $SessionProjector = $this->getContainer() + ->get(SessionProjector::class); $signedIn = SignedIn::fromProperties( [], @@ -226,8 +217,8 @@ public function testProcessSignedInThenTokenRefreshed(): void $signedIn->sessionTokenCreated() ); - $sessionProcessor->process($signedIn); - $sessionProcessor->process($tokenRefreshed); + $SessionProjector->process($signedIn); + $SessionProjector->process($tokenRefreshed); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -263,7 +254,7 @@ public function testProcessSignedInThenTokenRefreshed(): void ); // test idempotency - $sessionProcessor->process($tokenRefreshed); + $SessionProjector->process($tokenRefreshed); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -299,13 +290,10 @@ public function testProcessSignedInThenTokenRefreshed(): void ); } - /** - * @test - */ public function testProcessSignedOut(): void { - $sessionProcessor = $this->getContainer() - ->get(SessionProcessor::class); + $SessionProjector = $this->getContainer() + ->get(SessionProjector::class); $sessionId = Id::createNew(); $asUser = Id::createNew(); @@ -319,7 +307,7 @@ public function testProcessSignedOut(): void $existingSessionToken ); - $sessionProcessor->process($signedOut); + $SessionProjector->process($signedOut); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -355,7 +343,7 @@ public function testProcessSignedOut(): void ); // test idempotency - $sessionProcessor->process($signedOut); + $SessionProjector->process($signedOut); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -391,13 +379,10 @@ public function testProcessSignedOut(): void ); } - /** - * @test - */ public function testProcessSignedInThenSignedOut(): void { - $sessionProcessor = $this->getContainer() - ->get(SessionProcessor::class); + $SessionProjector = $this->getContainer() + ->get(SessionProjector::class); $signedIn = SignedIn::fromProperties( [], @@ -416,8 +401,8 @@ public function testProcessSignedInThenSignedOut(): void $signedIn->sessionTokenCreated() ); - $sessionProcessor->process($signedIn); - $sessionProcessor->process($signedOut); + $SessionProjector->process($signedIn); + $SessionProjector->process($signedOut); $allSessions = $this->findAllSessions(); $this->assertCount( @@ -453,7 +438,7 @@ public function testProcessSignedInThenSignedOut(): void ); // test idempotency - $sessionProcessor->process($signedOut); + $SessionProjector->process($signedOut); $allSessions = $this->findAllSessions(); $this->assertCount( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionTest.php index 445116fe..7326d6a7 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/SessionTest.php @@ -10,9 +10,6 @@ class SessionTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $lastRefreshedAt = new \DateTimeImmutable(); @@ -76,9 +73,6 @@ public function testCreate(): void ); } - /** - * @test - */ public function testChangeProperties(): void { $lastRefreshedAt = new \DateTimeImmutable(); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/UserIdFromSignedInSessionTokenTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/UserIdFromSignedInSessionTokenTest.php index 383e8512..5f3946ea 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/UserIdFromSignedInSessionTokenTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/Session/UserIdFromSignedInSessionTokenTest.php @@ -11,11 +11,6 @@ class UserIdFromSignedInSessionTokenTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testUserIdFromSignedInSessionToken(): void { $userIdFromSignedInSessionToken = $this->getContainer() @@ -150,11 +145,6 @@ public function testUserIdFromSignedInSessionToken(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testUserIdFromSignedInSessionTokenWithSignedOutTrue(): void { $userIdFromSignedInSessionToken = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserIdFromSignInEmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserIdFromSignInEmailTest.php index 32cc0efb..1a1ccfd0 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserIdFromSignInEmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserIdFromSignInEmailTest.php @@ -14,11 +14,6 @@ class UserIdFromSignInEmailTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testUnverified(): void { $userIdFromEmailService = $this->getContainer() @@ -61,11 +56,6 @@ public function testUnverified(): void Assert::assertEquals('user_id_2', $userIdFromEmailService->userIdFromSignInEmail('xyZ@galeas.com')); } - /** - * @test - * - * @throws \Exception - */ public function testVerified(): void { $userIdFromEmailService = $this->getContainer() @@ -108,11 +98,6 @@ public function testVerified(): void Assert::assertEquals(null, $userIdFromEmailService->userIdFromSignInEmail('xYz@galeas.com')); } - /** - * @test - * - * @throws \Exception - */ public function testRequestedChange(): void { $userIdFromEmailService = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProjectorTest.php similarity index 82% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProjectorTest.php index 959bfa44..6268f562 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailProjectorTest.php @@ -10,23 +10,18 @@ use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithEmail\RequestedChange; use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithEmail\Unverified; use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithEmail\UserWithEmail; -use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithEmail\UserWithEmailProcessor; +use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithEmail\UserWithEmailProjector; use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithEmail\Verified; use Galeas\Api\Common\Id\Id; use PHPUnit\Framework\Assert; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class UserWithEmailProcessorTest extends KernelTestBase +class UserWithEmailProjectorTest extends KernelTestBase { - /** - * @test - * - * @throws \Exception - */ public function testProcessSignedUp(): void { - $userWithEmailProcessorService = $this->getContainer() - ->get(UserWithEmailProcessor::class); + $UserWithEmailProjectorService = $this->getContainer() + ->get(UserWithEmailProjector::class); $signedUp = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -36,7 +31,7 @@ public function testProcessSignedUp(): void false ); $userId = $signedUp->aggregateId()->id(); - $userWithEmailProcessorService->process($signedUp); + $UserWithEmailProjectorService->process($signedUp); Assert::assertEquals( [ @@ -51,15 +46,10 @@ public function testProcessSignedUp(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessPrimaryEmailVerifiedWhenUnverified(): void { - $userWithEmailProcessorService = $this->getContainer() - ->get(UserWithEmailProcessor::class); + $UserWithEmailProjectorService = $this->getContainer() + ->get(UserWithEmailProjector::class); $userId = Id::createNew(); $this->getProjectionDocumentManager() @@ -79,7 +69,7 @@ public function testProcessPrimaryEmailVerifiedWhenUnverified(): void [], 'fake_code' ); - $userWithEmailProcessorService->process($primaryEmailVerified); + $UserWithEmailProjectorService->process($primaryEmailVerified); Assert::assertEquals( [ @@ -94,15 +84,10 @@ public function testProcessPrimaryEmailVerifiedWhenUnverified(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessPrimaryEmailVerifiedWhenChangeRequested(): void { - $userWithEmailProcessorService = $this->getContainer() - ->get(UserWithEmailProcessor::class); + $UserWithEmailProjectorService = $this->getContainer() + ->get(UserWithEmailProjector::class); $userId = Id::createNew(); $this->getProjectionDocumentManager() @@ -122,7 +107,7 @@ public function testProcessPrimaryEmailVerifiedWhenChangeRequested(): void [], 'fake_code' ); - $userWithEmailProcessorService->process($primaryEmailVerified); + $UserWithEmailProjectorService->process($primaryEmailVerified); Assert::assertEquals( [ @@ -137,15 +122,10 @@ public function testProcessPrimaryEmailVerifiedWhenChangeRequested(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessChangeRequestedWhenUnverified(): void { - $userWithEmailProcessorService = $this->getContainer() - ->get(UserWithEmailProcessor::class); + $UserWithEmailProjectorService = $this->getContainer() + ->get(UserWithEmailProjector::class); $userId = Id::createNew(); $this->getProjectionDocumentManager() @@ -166,7 +146,7 @@ public function testProcessChangeRequestedWhenUnverified(): void 'new@galeas.com', 'fake_hashed_password' ); - $userWithEmailProcessorService->process($primaryEmailChangeRequested); + $UserWithEmailProjectorService->process($primaryEmailChangeRequested); Assert::assertEquals( [ @@ -181,15 +161,10 @@ public function testProcessChangeRequestedWhenUnverified(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessChangeRequestedWhenVerified(): void { - $userWithEmailProcessorService = $this->getContainer() - ->get(UserWithEmailProcessor::class); + $UserWithEmailProjectorService = $this->getContainer() + ->get(UserWithEmailProjector::class); $userId = Id::createNew(); $this->getProjectionDocumentManager() @@ -210,7 +185,7 @@ public function testProcessChangeRequestedWhenVerified(): void 'new_requested@galeas.com', 'fake_hashed_password' ); - $userWithEmailProcessorService->process($primaryEmailChangeRequested); + $UserWithEmailProjectorService->process($primaryEmailChangeRequested); Assert::assertEquals( [ @@ -225,15 +200,10 @@ public function testProcessChangeRequestedWhenVerified(): void ); } - /** - * @test - * - * @throws \Exception - */ public function testProcessChangeRequestedWhenChangeRequested(): void { - $userWithEmailProcessorService = $this->getContainer() - ->get(UserWithEmailProcessor::class); + $UserWithEmailProjectorService = $this->getContainer() + ->get(UserWithEmailProjector::class); $userId = Id::createNew(); $this->getProjectionDocumentManager() @@ -254,7 +224,7 @@ public function testProcessChangeRequestedWhenChangeRequested(): void 'new_requested@galeas.com', 'fake_hashed_password' ); - $userWithEmailProcessorService->process($primaryEmailChangeRequested); + $UserWithEmailProjectorService->process($primaryEmailChangeRequested); Assert::assertEquals( [ diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailTest.php index 8c389246..cf11145b 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithEmail/UserWithEmailTest.php @@ -12,9 +12,6 @@ class UserWithEmailTest extends UnitTestBase { - /** - * @test - */ public function testUserWithEmail(): void { $userWithEmail = UserWithEmail::fromUserIdAndEmails( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserIdFromSignInUsernameTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserIdFromSignInUsernameTest.php index 5cce9050..41877d0d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserIdFromSignInUsernameTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserIdFromSignInUsernameTest.php @@ -11,9 +11,6 @@ class UserIdFromSignInUsernameTest extends KernelTestBase { - /** - * @test - */ public function testUserIdFromUsernameTest(): void { $userIdFromUsername = $this->getContainer() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProcessorTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProjectorTest.php similarity index 86% rename from application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProcessorTest.php rename to application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProjectorTest.php index aa975bd6..adc6bd8d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProcessorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameProjectorTest.php @@ -6,18 +6,15 @@ use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithUsername\UserWithUsername; -use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithUsername\UserWithUsernameProcessor; +use Galeas\Api\BoundedContext\Security\Session\Projection\UserWithUsername\UserWithUsernameProjector; use Tests\Galeas\Api\UnitAndIntegration\KernelTestBase; -class UserWithUsernameProcessorTest extends KernelTestBase +class UserWithUsernameProjectorTest extends KernelTestBase { - /** - * @test - */ - public function testSessionProcessor(): void + public function testSessionProjector(): void { - $userWithUsernameProcessor = $this->getContainer() - ->get(UserWithUsernameProcessor::class); + $UserWithUsernameProjector = $this->getContainer() + ->get(UserWithUsernameProjector::class); $signedUp1 = SignedUp::fromPropertiesAndDefaultOthers( [], @@ -53,8 +50,8 @@ public function testSessionProcessor(): void // SignedUp 1 - $userWithUsernameProcessor->process($signedUp1); - $userWithUsernameProcessor->process($signedUp1); // test idempotency + $UserWithUsernameProjector->process($signedUp1); + $UserWithUsernameProjector->process($signedUp1); // test idempotency $userWithUsernameArray1 = $this->findUsersById( $signedUp1->aggregateId()->id() @@ -81,8 +78,8 @@ public function testSessionProcessor(): void // SignedUp 2 - $userWithUsernameProcessor->process($signedUp2); - $userWithUsernameProcessor->process($signedUp2); // test idempotency + $UserWithUsernameProjector->process($signedUp2); + $UserWithUsernameProjector->process($signedUp2); // test idempotency $userWithUsernameArray1 = $this->findUsersById( $signedUp1->aggregateId()->id() diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameTest.php index c1b35615..e04c24f4 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/Projection/UserWithUsername/UserWithUsernameTest.php @@ -10,9 +10,6 @@ class UserWithUsernameTest extends UnitTestBase { - /** - * @test - */ public function testUserWithUsername(): void { $userWithUsername = UserWithUsername::fromProperties( diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionDetailsTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionDetailsTest.php index 4b65bd08..93faf3c3 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionDetailsTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionDetailsTest.php @@ -11,9 +11,6 @@ class SessionDetailsTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $asUser = Id::createNew(); diff --git a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionIsSignedOutTest.php b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionIsSignedOutTest.php index a67b6aa5..448647ef 100644 --- a/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionIsSignedOutTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/BoundedContext/Security/Session/ValueObject/SessionIsSignedOutTest.php @@ -10,9 +10,6 @@ class SessionIsSignedOutTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { $withSessionToken = 'with_session_token'; diff --git a/application/monolith/code/tests/UnitAndIntegration/HandlerTestBase.php b/application/monolith/code/tests/UnitAndIntegration/HandlerTestBase.php index 212ef97e..dab7262f 100644 --- a/application/monolith/code/tests/UnitAndIntegration/HandlerTestBase.php +++ b/application/monolith/code/tests/UnitAndIntegration/HandlerTestBase.php @@ -18,26 +18,14 @@ */ abstract class HandlerTestBase extends TestCase { - /** - * @var InMemoryEventStore - */ - private $inMemoryEventStore; + private InMemoryEventStore $inMemoryEventStore; - /** - * @var InMemoryQueue - */ - private $inMemoryQueue; protected function getInMemoryEventStore(): InMemoryEventStore { return $this->inMemoryEventStore; } - protected function getInMemoryQueue(): InMemoryQueue - { - return $this->inMemoryQueue; - } - /** * @param mixed $methodWillReturnValue */ @@ -70,23 +58,22 @@ protected function mockMetadata(): array return []; } - private function clearStoreAndQueue(): void + private function clearEventStore(): void { $this->inMemoryEventStore = new InMemoryEventStore(); - $this->inMemoryQueue = new InMemoryQueue(); } public function setUp(): void { parent::setUp(); - $this->clearStoreAndQueue(); + $this->clearEventStore(); } public function tearDown(): void { parent::tearDown(); - $this->clearStoreAndQueue(); + $this->clearEventStore(); } } diff --git a/application/monolith/code/tests/UnitAndIntegration/KernelTestBase.php b/application/monolith/code/tests/UnitAndIntegration/KernelTestBase.php index 8bf9b8b1..c7924d48 100644 --- a/application/monolith/code/tests/UnitAndIntegration/KernelTestBase.php +++ b/application/monolith/code/tests/UnitAndIntegration/KernelTestBase.php @@ -4,19 +4,24 @@ namespace Tests\Galeas\Api\UnitAndIntegration; +use Doctrine\DBAL\Connection; +use Doctrine\ODM\MongoDB\DocumentManager; use Galeas\Api\Kernel; +use Galeas\Api\Service\EventStore\SQLEventStoreConnection; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; abstract class KernelTestBase extends TestCase { - private $kernel; + private ?Kernel $kernel; - private $container; + private ?Container $container; public function setUp(): void { - if (null !== $this->kernel) { + if (null !== $this->kernel && null !== $this->container) { $this->kernel->boot(); $this->container = $this->containerFromKernel($this->kernel); @@ -34,8 +39,39 @@ public function setUp(): void $this->container = $this->containerFromKernel($this->kernel); } - protected function getKernel(): Kernel { - return $this->kernel; + public function tearDown(): void + { + parent::tearDown(); + + $this->deleteDatabasesAndCloseConnections(); + $this->kernel->shutdown(); + + $this->container->reset(); + } + + protected function kernelHandleRequest(Request $request): Response + { + return $this->kernel->handle($request); + } + + protected function getContainer(): Container + { + return $this->container; + } + + protected function getProjectionDocumentManager(): DocumentManager + { + return $this->container->get('doctrine_mongodb.odm.projection_document_manager'); + } + + protected function getReactionDocumentManager(): DocumentManager + { + return $this->container->get('doctrine_mongodb.odm.reaction_document_manager'); + } + + protected function getEventStoreConnection(): Connection + { + return $this->container->get(SQLEventStoreConnection::class)->getConnection(); } private function containerFromKernel(Kernel $kernel): Container @@ -48,12 +84,36 @@ private function containerFromKernel(Kernel $kernel): Container throw new \RuntimeException(); } - public function tearDown(): void + private function deleteDatabasesAndCloseConnections(): void { - parent::tearDown(); + $projectionDocumentManager = self::getProjectionDocumentManager(); + $projectionDocumentManager->clear(); + $projectionDatabase = $projectionDocumentManager->getClient() + ->selectDatabase( + $this->container->getParameter('mongodb_projection_database_name') + ); + foreach ($projectionDatabase->listCollections() as $collection) { + $projectionDatabase->selectCollection( + $collection->getName() + )->deleteMany([]); + } - $this->kernel->shutdown(); + $reactionDocumentManager = self::getReactionDocumentManager(); + $reactionDocumentManager->clear(); + $reactionDatabase = $reactionDocumentManager->getClient() + ->selectDatabase( + $this->container->getParameter('mongodb_reaction_database_name') + ); + foreach ($reactionDatabase->listCollections() as $collection) { + $reactionDatabase->selectCollection( + $collection->getName() + )->deleteMany([]); + } - $this->container->reset(); + $eventStoreConnection = $this->getEventStoreConnection(); // connects to the test database + $eventStoreConnection->beginTransaction(); + $eventStoreConnection->executeStatement('TRUNCATE TABLE event'); + $eventStoreConnection->commit(); + $eventStoreConnection->close(); } } \ No newline at end of file diff --git a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveComparison/Email/AreEmailsEquivalentTest.php b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveComparison/Email/AreEmailsEquivalentTest.php index af230707..efebd17f 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveComparison/Email/AreEmailsEquivalentTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveComparison/Email/AreEmailsEquivalentTest.php @@ -10,9 +10,6 @@ class AreEmailsEquivalentTest extends UnitTestBase { - /** - * @test - */ public function testEquivalentEmails(): void { foreach (EquivalentEmails::validEmailPairsWhichAreTheSameAddress() as $pair) { @@ -28,9 +25,6 @@ public function testEquivalentEmails(): void Assert::assertTrue(true); // prevents flagging as risky test } - /** - * @test - */ public function testNonEquivalentEmails(): void { foreach (NonEquivalentEmails::validEmailPairsWhichAreNotTheSameAddress() as $pair) { diff --git a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Email/EmailVerificationCodeCreatorTest.php b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Email/EmailVerificationCodeCreatorTest.php index 52a9d48d..9d75ece3 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Email/EmailVerificationCodeCreatorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Email/EmailVerificationCodeCreatorTest.php @@ -11,9 +11,6 @@ class EmailVerificationCodeCreatorTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { for ($i = 0; $i < 20000; ++$i) { @@ -41,9 +38,6 @@ public function testCreate(): void Assert::assertTrue(true); // prevents flagging as risky test } - /** - * @test - */ public function testRandomnessStatistically(): void { $countVerificationCodesThatStartWithThreeZeros = 0; diff --git a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Id/IdCreatorTest.php b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Id/IdCreatorTest.php index 0331fbd1..c69e6c14 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Id/IdCreatorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/Id/IdCreatorTest.php @@ -11,9 +11,6 @@ class IdCreatorTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { for ($i = 0; $i < 20000; ++$i) { @@ -41,9 +38,6 @@ public function testCreate(): void Assert::assertTrue(true); // prevents flagging as risky test } - /** - * @test - */ public function testRandomnessStatistically(): void { $firstThreeCharactersArray = []; diff --git a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/SessionToken/SessionTokenCreatorTest.php b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/SessionToken/SessionTokenCreatorTest.php index b37c27dd..a1bb9ff5 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/SessionToken/SessionTokenCreatorTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveCreation/SessionToken/SessionTokenCreatorTest.php @@ -11,9 +11,6 @@ class SessionTokenCreatorTest extends UnitTestBase { - /** - * @test - */ public function testCreate(): void { for ($i = 0; $i < 20000; ++$i) { @@ -41,9 +38,6 @@ public function testCreate(): void Assert::assertTrue(true); // prevents flagging as risky test } - /** - * @test - */ public function testRandomnessStatistically(): void { $firstThreeCharactersArray = []; diff --git a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveTransformation/Hash/BCryptPasswordHashTest.php b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveTransformation/Hash/BCryptPasswordHashTest.php index 0e2384fe..1bf8099b 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveTransformation/Hash/BCryptPasswordHashTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/Primitive/PrimitiveTransformation/Hash/BCryptPasswordHashTest.php @@ -10,11 +10,6 @@ class BCryptPasswordHashTest extends UnitTestBase { - /** - * @test - * - * @throws \Exception - */ public function testHash(): void { $hash = BCryptPasswordHash::hash('HelloWorld22AHHH!', 11); diff --git a/application/monolith/code/tests/UnitAndIntegration/RequestTest.php b/application/monolith/code/tests/UnitAndIntegration/RequestTest.php index 56dac4a4..58b01d7a 100644 --- a/application/monolith/code/tests/UnitAndIntegration/RequestTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/RequestTest.php @@ -18,7 +18,7 @@ protected function requestGet(string $url, array $parameters): array { ['CONTENT_TYPE' => 'application/json'], null ); - $response = $this->getKernel()->handle($request); + $response = $this->kernelHandleRequest($request); return [ "content" => $response->getContent(), diff --git a/application/monolith/code/tests/UnitAndIntegration/Service/EventStore/InMemoryEventStoreTest.php b/application/monolith/code/tests/UnitAndIntegration/Service/EventStore/InMemoryEventStoreTest.php index a75357a8..1e57f02d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Service/EventStore/InMemoryEventStoreTest.php +++ b/application/monolith/code/tests/UnitAndIntegration/Service/EventStore/InMemoryEventStoreTest.php @@ -8,6 +8,7 @@ use Galeas\Api\BoundedContext\Identity\User\ValueObject\UnverifiedEmail; use Galeas\Api\Common\ExceptionBase\EventStoreCannotRead; use Galeas\Api\Common\ExceptionBase\EventStoreCannotWrite; +use Galeas\Api\Service\EventStore\AggregateAndEventIds; use Galeas\Api\Service\EventStore\Exception\CancellingTransactionRequiresActiveTransaction; use Galeas\Api\Service\EventStore\Exception\CompletingTransactionRequiresActiveTransaction; use Galeas\Api\Service\EventStore\Exception\FindingAggregateRequiresActiveTransaction; @@ -34,9 +35,13 @@ public function testPersistence(): void $inMemoryEventStore->completeTransaction(); $inMemoryEventStore->beginTransaction(); - $user = $inMemoryEventStore->find($signedUp->aggregateId()->id()); + $aggregateAndEventIds = $inMemoryEventStore->find($signedUp->aggregateId()->id()); $inMemoryEventStore->completeTransaction(); + if (!($aggregateAndEventIds instanceof AggregateAndEventIds)) { + throw new \Exception(); + } + $user = $aggregateAndEventIds->aggregate(); if (!($user instanceof User)) { throw new \Exception(); } diff --git a/application/monolith/code/tests/UnitAndIntegration/Util/SampleEvents.php b/application/monolith/code/tests/UnitAndIntegration/Util/SampleEvents.php index ca170ee2..a7d9553d 100644 --- a/application/monolith/code/tests/UnitAndIntegration/Util/SampleEvents.php +++ b/application/monolith/code/tests/UnitAndIntegration/Util/SampleEvents.php @@ -58,7 +58,7 @@ public static function signedUp(): SignedUp { ); } - private static function primaryEmailVerificationCodeSent( + public static function primaryEmailVerificationCodeSent( Id $aggregateId, int $aggregateVersion, Id $causationId, @@ -81,7 +81,7 @@ private static function primaryEmailVerificationCodeSent( ); } - private static function primaryEmailVerified( + public static function primaryEmailVerified( Id $aggregateId, int $aggregateVersion, Id $causationId, @@ -100,7 +100,7 @@ private static function primaryEmailVerified( ); } - private static function primaryEmailChangeRequested( + public static function primaryEmailChangeRequested( Id $aggregateId, int $aggregateVersion, Id $causationId, @@ -140,7 +140,7 @@ public static function sampleSessionEvents(): array { return [$event1, $event2, $event3]; } - private static function signedIn(): SignedIn { + public static function signedIn(): SignedIn { $eventId = Id::createNew(); $aggregateId = Id::createNew(); $asUser = Id::createNew(); @@ -162,7 +162,7 @@ private static function signedIn(): SignedIn { ); } - private static function tokenRefreshed( + public static function tokenRefreshed( Id $aggregateId, int $aggregateVersion, Id $causationId, @@ -184,7 +184,7 @@ private static function tokenRefreshed( ); } - private static function signedOut( + public static function signedOut( Id $aggregateId, int $aggregateVersion, Id $causationId,