diff --git a/config/autoload/doctrine.global.php b/config/autoload/doctrine.global.php index f592d15..fd165f9 100644 --- a/config/autoload/doctrine.global.php +++ b/config/autoload/doctrine.global.php @@ -2,7 +2,10 @@ declare(strict_types=1); +use Api\Admin\DBAL\Types\AdminStatusEnumType; use Api\App\Entity\EntityListenerResolver; +use Api\User\DBAL\Types\UserResetPasswordStatusEnumType; +use Api\User\DBAL\Types\UserStatusEnumType; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Dot\Cache\Adapter\ArrayAdapter; use Dot\Cache\Adapter\FilesystemAdapter; @@ -27,9 +30,12 @@ ], ], 'types' => [ - UuidType::NAME => UuidType::class, - UuidBinaryType::NAME => UuidBinaryType::class, - UuidBinaryOrderedTimeType::NAME => UuidBinaryOrderedTimeType::class, + UuidType::NAME => UuidType::class, + UuidBinaryType::NAME => UuidBinaryType::class, + UuidBinaryOrderedTimeType::NAME => UuidBinaryOrderedTimeType::class, + AdminStatusEnumType::NAME => AdminStatusEnumType::class, + UserStatusEnumType::NAME => UserStatusEnumType::class, + UserResetPasswordStatusEnumType::NAME => UserResetPasswordStatusEnumType::class, ], 'fixtures' => getcwd() . '/data/doctrine/fixtures', 'configuration' => [ diff --git a/data/doctrine/fixtures/AdminLoader.php b/data/doctrine/fixtures/AdminLoader.php index 107c338..bab9007 100644 --- a/data/doctrine/fixtures/AdminLoader.php +++ b/data/doctrine/fixtures/AdminLoader.php @@ -6,37 +6,35 @@ use Api\Admin\Entity\Admin; use Api\Admin\Entity\AdminRole; -use Api\User\Entity\User; +use Api\Admin\Enum\AdminStatusEnum; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; -/** - * Class AdminLoader - * @package Api\Fixtures - */ +use function assert; + class AdminLoader implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager): void { $adminRoleRepository = $manager->getRepository(AdminRole::class); - /** @var AdminRole $adminRole */ $adminRole = $adminRoleRepository->findOneBy([ 'name' => AdminRole::ROLE_ADMIN, ]); + assert($adminRole instanceof AdminRole); - /** @var AdminRole $superUserRole */ $superUserRole = $adminRoleRepository->findOneBy([ 'name' => AdminRole::ROLE_SUPERUSER, ]); + assert($superUserRole instanceof AdminRole); $admin = (new Admin()) ->setIdentity('admin') ->usePassword('dotkernel') ->setFirstName('DotKernel') ->setLastName('Admin') - ->setStatus(User::STATUS_ACTIVE) + ->setStatus(AdminStatusEnum::Active) ->addRole($adminRole) ->addRole($superUserRole); diff --git a/data/doctrine/fixtures/AdminRoleLoader.php b/data/doctrine/fixtures/AdminRoleLoader.php index 67d5483..1b4aaf6 100644 --- a/data/doctrine/fixtures/AdminRoleLoader.php +++ b/data/doctrine/fixtures/AdminRoleLoader.php @@ -8,10 +8,6 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; -/** - * Class AdminRoleLoader - * @package Api\Fixtures - */ class AdminRoleLoader implements FixtureInterface { public function load(ObjectManager $manager): void diff --git a/data/doctrine/fixtures/OAuthClientLoader.php b/data/doctrine/fixtures/OAuthClientLoader.php index 0b83df5..66e8519 100644 --- a/data/doctrine/fixtures/OAuthClientLoader.php +++ b/data/doctrine/fixtures/OAuthClientLoader.php @@ -9,10 +9,6 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; -/** - * Class OAuthClientLoader - * @package Api\Fixtures - */ class OAuthClientLoader extends AbstractFixture implements FixtureInterface { public function load(ObjectManager $manager): void diff --git a/data/doctrine/fixtures/OAuthScopeLoader.php b/data/doctrine/fixtures/OAuthScopeLoader.php index bf1dad1..7d0be9c 100644 --- a/data/doctrine/fixtures/OAuthScopeLoader.php +++ b/data/doctrine/fixtures/OAuthScopeLoader.php @@ -8,10 +8,6 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; -/** - * Class OAuthScopeLoader - * @package Api\Fixtures - */ class OAuthScopeLoader implements FixtureInterface { public function load(ObjectManager $manager): void diff --git a/data/doctrine/fixtures/UserLoader.php b/data/doctrine/fixtures/UserLoader.php index be7afb2..0c95692 100644 --- a/data/doctrine/fixtures/UserLoader.php +++ b/data/doctrine/fixtures/UserLoader.php @@ -7,34 +7,33 @@ use Api\User\Entity\User; use Api\User\Entity\UserDetail; use Api\User\Entity\UserRole; +use Api\User\Enum\UserStatusEnum; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; -/** - * Class UserLoader - * @package Api\Fixtures - */ +use function assert; + class UserLoader implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager): void { $userRoleRepository = $manager->getRepository(UserRole::class); - /** @var UserRole $guestRole */ $guestRole = $userRoleRepository->findOneBy([ 'name' => UserRole::ROLE_GUEST, ]); + assert($guestRole instanceof UserRole); - /** @var UserRole $userRole */ $userRole = $userRoleRepository->findOneBy([ 'name' => UserRole::ROLE_USER, ]); + assert($userRole instanceof UserRole); $user = (new User()) ->setIdentity('test@dotkernel.com') ->usePassword('dotkernel') - ->setStatus(User::STATUS_ACTIVE) + ->setStatus(UserStatusEnum::Active) ->setIsDeleted(false) ->setHash(User::generateHash()) ->addRole($guestRole) diff --git a/data/doctrine/fixtures/UserRoleLoader.php b/data/doctrine/fixtures/UserRoleLoader.php index 8b8d551..3bda555 100644 --- a/data/doctrine/fixtures/UserRoleLoader.php +++ b/data/doctrine/fixtures/UserRoleLoader.php @@ -8,10 +8,6 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; -/** - * Class UserRoleLoader - * @package Api\Fixtures - */ class UserRoleLoader implements FixtureInterface { public function load(ObjectManager $manager): void diff --git a/data/doctrine/migrations/Version20240613153602.php b/data/doctrine/migrations/Version20241030082958.php similarity index 90% rename from data/doctrine/migrations/Version20240613153602.php rename to data/doctrine/migrations/Version20241030082958.php index 5674afe..86ad9ea 100644 --- a/data/doctrine/migrations/Version20240613153602.php +++ b/data/doctrine/migrations/Version20241030082958.php @@ -10,7 +10,7 @@ /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240613153602 extends AbstractMigration +final class Version20241030082958 extends AbstractMigration { public function getDescription(): string { @@ -20,7 +20,7 @@ public function getDescription(): string public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE admin (uuid BINARY(16) NOT NULL, identity VARCHAR(100) NOT NULL, firstName VARCHAR(191) NOT NULL, lastName VARCHAR(191) NOT NULL, password VARCHAR(100) NOT NULL, status VARCHAR(20) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_880E0D766A95E9C4 (identity), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE admin (uuid BINARY(16) NOT NULL, identity VARCHAR(100) NOT NULL, firstName VARCHAR(191) NOT NULL, lastName VARCHAR(191) NOT NULL, password VARCHAR(100) NOT NULL, status ENUM(\'active\', \'inactive\') DEFAULT \'active\' NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_880E0D766A95E9C4 (identity), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE admin_roles (userUuid BINARY(16) NOT NULL, roleUuid BINARY(16) NOT NULL, INDEX IDX_1614D53DD73087E9 (userUuid), INDEX IDX_1614D53D88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE admin_role (uuid BINARY(16) NOT NULL, name VARCHAR(30) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_7770088A5E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE oauth_access_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, user_id VARCHAR(25) DEFAULT NULL, token VARCHAR(100) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL, client_id INT UNSIGNED DEFAULT NULL, INDEX IDX_CA42527C19EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4'); @@ -30,11 +30,11 @@ public function up(Schema $schema): void $this->addSql('CREATE TABLE oauth_clients (id INT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(40) NOT NULL, secret VARCHAR(100) DEFAULT NULL, redirect VARCHAR(191) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, isConfidential TINYINT(1) DEFAULT 0 NOT NULL, user_id BINARY(16) DEFAULT NULL, INDEX IDX_13CE8101A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE oauth_refresh_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL, access_token_id INT UNSIGNED DEFAULT NULL, INDEX IDX_5AB6872CCB2688 (access_token_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE oauth_scopes (id INT UNSIGNED AUTO_INCREMENT NOT NULL, scope VARCHAR(191) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4'); - $this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL, identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status VARCHAR(20) NOT NULL, isDeleted TINYINT(1) NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL, identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status ENUM(\'active\', \'pending\') DEFAULT \'pending\' NOT NULL, isDeleted TINYINT(1) NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_roles (userUuid BINARY(16) NOT NULL, roleUuid BINARY(16) NOT NULL, INDEX IDX_54FCD59FD73087E9 (userUuid), INDEX IDX_54FCD59F88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_avatar (uuid BINARY(16) NOT NULL, name VARCHAR(191) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_73256912D73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_detail (uuid BINARY(16) NOT NULL, firstName VARCHAR(191) DEFAULT NULL, lastName VARCHAR(191) DEFAULT NULL, email VARCHAR(191) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_4B5464AED73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); - $this->addSql('CREATE TABLE user_reset_password (uuid BINARY(16) NOT NULL, expires DATETIME NOT NULL, hash VARCHAR(64) NOT NULL, status VARCHAR(20) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_D21DE3BCD1B862B8 (hash), INDEX IDX_D21DE3BCD73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE user_reset_password (uuid BINARY(16) NOT NULL, expires DATETIME NOT NULL, hash VARCHAR(64) NOT NULL, status ENUM(\'completed\', \'requested\') DEFAULT \'requested\' NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_D21DE3BCD1B862B8 (hash), INDEX IDX_D21DE3BCD73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_role (uuid BINARY(16) NOT NULL, name VARCHAR(20) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_2DE8C6A35E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('ALTER TABLE admin_roles ADD CONSTRAINT FK_1614D53DD73087E9 FOREIGN KEY (userUuid) REFERENCES admin (uuid)'); $this->addSql('ALTER TABLE admin_roles ADD CONSTRAINT FK_1614D53D88446210 FOREIGN KEY (roleUuid) REFERENCES admin_role (uuid)'); diff --git a/src/Admin/src/DBAL/Types/AdminStatusEnumType.php b/src/Admin/src/DBAL/Types/AdminStatusEnumType.php new file mode 100644 index 0000000..ce6a1ea --- /dev/null +++ b/src/Admin/src/DBAL/Types/AdminStatusEnumType.php @@ -0,0 +1,23 @@ + AdminStatusEnum::Active])] + protected AdminStatusEnum $status = AdminStatusEnum::Active; #[ORM\ManyToMany(targetEntity: AdminRole::class)] #[ORM\JoinTable(name: "admin_roles")] @@ -122,12 +116,12 @@ public function setPassword(string $password): self return $this; } - public function getStatus(): string + public function getStatus(): AdminStatusEnum { return $this->status; } - public function setStatus(string $status): self + public function setStatus(AdminStatusEnum $status): self { $this->status = $status; @@ -178,21 +172,21 @@ public function hasRoles(): bool public function activate(): self { - $this->status = self::STATUS_ACTIVE; + $this->status = AdminStatusEnum::Active; return $this; } public function deactivate(): self { - $this->status = self::STATUS_INACTIVE; + $this->status = AdminStatusEnum::Inactive; return $this; } public function isActive(): bool { - return $this->status === self::STATUS_ACTIVE; + return $this->status === AdminStatusEnum::Active; } public function getIdentifier(): string diff --git a/src/Admin/src/Enum/AdminStatusEnum.php b/src/Admin/src/Enum/AdminStatusEnum.php new file mode 100644 index 0000000..c506544 --- /dev/null +++ b/src/Admin/src/Enum/AdminStatusEnum.php @@ -0,0 +1,11 @@ +getFilterChain() ->attachByName(StringTrim::class) - ->attachByName(StripTags::class); + ->attachByName(StripTags::class) + ->attach(fn($value) => $value === null ? AdminStatusEnum::Active : AdminStatusEnum::from($value)); $this->getValidatorChain() ->attachByName(InArray::class, [ - 'haystack' => Admin::STATUSES, + 'haystack' => AdminStatusEnum::cases(), 'message' => sprintf(Message::INVALID_VALUE, 'status'), ], true); } diff --git a/src/Admin/src/OpenAPI.php b/src/Admin/src/OpenAPI.php index 20ac50c..357136f 100644 --- a/src/Admin/src/OpenAPI.php +++ b/src/Admin/src/OpenAPI.php @@ -8,6 +8,7 @@ use Api\Admin\Collection\AdminRoleCollection; use Api\Admin\Entity\Admin; use Api\Admin\Entity\AdminRole; +use Api\Admin\Enum\AdminStatusEnum; use Api\Admin\Handler\AdminAccountHandler; use Api\Admin\Handler\AdminHandler; use Api\Admin\Handler\AdminRoleHandler; @@ -223,7 +224,7 @@ new OA\Property(property: 'passwordConfirm', type: 'string'), new OA\Property(property: 'firstName', type: 'string'), new OA\Property(property: 'lastName', type: 'string'), - new OA\Property(property: 'status', type: 'string', default: Admin::STATUS_ACTIVE), + new OA\Property(property: 'status', type: 'string', default: AdminStatusEnum::Active), new OA\Property( property: 'roles', type: 'array', @@ -291,7 +292,7 @@ new OA\Property(property: 'passwordConfirm', type: 'string'), new OA\Property(property: 'firstName', type: 'string'), new OA\Property(property: 'lastName', type: 'string'), - new OA\Property(property: 'status', type: 'string', default: Admin::STATUS_ACTIVE), + new OA\Property(property: 'status', type: 'string', default: AdminStatusEnum::Active), new OA\Property( property: 'roles', type: 'array', @@ -440,7 +441,7 @@ new OA\Property(property: 'identity', type: 'string'), new OA\Property(property: 'firstName', type: 'string'), new OA\Property(property: 'lastName', type: 'string'), - new OA\Property(property: 'status', type: 'string', example: Admin::STATUS_ACTIVE), + new OA\Property(property: 'status', type: 'string', example: AdminStatusEnum::Active), new OA\Property( property: 'roles', type: 'array', diff --git a/src/Admin/src/Service/AdminService.php b/src/Admin/src/Service/AdminService.php index 5d07def..52c1ba0 100644 --- a/src/Admin/src/Service/AdminService.php +++ b/src/Admin/src/Service/AdminService.php @@ -6,6 +6,7 @@ use Api\Admin\Collection\AdminCollection; use Api\Admin\Entity\Admin; +use Api\Admin\Enum\AdminStatusEnum; use Api\Admin\Repository\AdminRepository; use Api\App\Exception\BadRequestException; use Api\App\Exception\ConflictException; @@ -43,7 +44,7 @@ public function createAdmin(array $data = []): Admin ->usePassword($data['password']) ->setFirstName($data['firstName']) ->setLastName($data['lastName']) - ->setStatus($data['status'] ?? Admin::STATUS_ACTIVE); + ->setStatus($data['status'] ?? AdminStatusEnum::Active); foreach ($data['roles'] as $roleData) { $admin->addRole( diff --git a/src/App/src/DBAL/Types/AbstractEnumType.php b/src/App/src/DBAL/Types/AbstractEnumType.php new file mode 100644 index 0000000..dffc929 --- /dev/null +++ b/src/App/src/DBAL/Types/AbstractEnumType.php @@ -0,0 +1,67 @@ + "'{$case->value}'", $this->getEnumValues()); + + return sprintf('ENUM(%s)', implode(', ', $values)); + } + + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed + { + if ($value === null) { + return null; + } + + return $this->getEnumClass()::from($value); + } + + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed + { + if ($value === null) { + return null; + } + + if (! $value instanceof BackedEnum) { + throw new InvalidArgumentException(sprintf( + 'Expected instance of %s, got %s', + $this->getEnumClass(), + is_object($value) ? $value::class : gettype($value) + )); + } + + return $value->value; + } + + /** + * @return class-string + */ + abstract protected function getEnumClass(): string; + + private function getEnumValues(): array + { + return $this->getEnumClass()::cases(); + } +} diff --git a/src/App/src/Entity/RoleInterface.php b/src/App/src/Entity/RoleInterface.php index 83b9456..0594759 100644 --- a/src/App/src/Entity/RoleInterface.php +++ b/src/App/src/Entity/RoleInterface.php @@ -4,8 +4,12 @@ namespace Api\App\Entity; +use Ramsey\Uuid\UuidInterface; + interface RoleInterface { + public function getUuid(): UuidInterface; + public function getName(): ?string; public function setName(string $name): RoleInterface; diff --git a/src/App/src/Middleware/AuthorizationMiddleware.php b/src/App/src/Middleware/AuthorizationMiddleware.php index 600d446..566a3bf 100644 --- a/src/App/src/Middleware/AuthorizationMiddleware.php +++ b/src/App/src/Middleware/AuthorizationMiddleware.php @@ -66,7 +66,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $defaultUser->getIdentity() )); } - if ($user->getStatus() !== User::STATUS_ACTIVE) { + if (! $user->isActive()) { return $this->unauthorizedResponse(Message::USER_NOT_ACTIVATED); } $request = $request->withAttribute(User::class, $user); diff --git a/src/User/src/DBAL/Types/UserResetPasswordStatusEnumType.php b/src/User/src/DBAL/Types/UserResetPasswordStatusEnumType.php new file mode 100644 index 0000000..d83525e --- /dev/null +++ b/src/User/src/DBAL/Types/UserResetPasswordStatusEnumType.php @@ -0,0 +1,23 @@ + UserStatusEnum::Pending])] + protected UserStatusEnum $status = UserStatusEnum::Pending; #[ORM\Column(name: "isDeleted", type: "boolean")] protected bool $isDeleted = false; @@ -97,15 +91,12 @@ public function setPassword(string $password): self return $this; } - public function getStatus(): string + public function getStatus(): UserStatusEnum { return $this->status; } - /** - * @psalm-param 'active'|'pending' $status - */ - public function setStatus(string $status): self + public function setStatus(UserStatusEnum $status): self { $this->status = $status; @@ -254,12 +245,12 @@ public function setResetPasswords(array $resetPasswords): self public function activate(): self { - return $this->setStatus(self::STATUS_ACTIVE); + return $this->setStatus(UserStatusEnum::Active); } public function deactivate(): self { - return $this->setStatus(self::STATUS_PENDING); + return $this->setStatus(UserStatusEnum::Pending); } public static function generateHash(): string @@ -274,12 +265,12 @@ public function getName(): string public function isActive(): bool { - return $this->status === self::STATUS_ACTIVE; + return $this->status === UserStatusEnum::Active; } public function isPending(): bool { - return $this->status === self::STATUS_PENDING; + return $this->status === UserStatusEnum::Pending; } public function markAsDeleted(): self diff --git a/src/User/src/Entity/UserResetPassword.php b/src/User/src/Entity/UserResetPassword.php index 46bac3f..59e4f83 100644 --- a/src/User/src/Entity/UserResetPassword.php +++ b/src/User/src/Entity/UserResetPassword.php @@ -6,6 +6,7 @@ use Api\App\Entity\AbstractEntity; use Api\App\Entity\TimestampsTrait; +use Api\User\Enum\UserResetPasswordStatusEnum; use Api\User\Repository\UserResetPasswordRepository; use DateInterval; use DateTime; @@ -20,13 +21,6 @@ class UserResetPassword extends AbstractEntity { use TimestampsTrait; - public const STATUS_COMPLETED = 'completed'; - public const STATUS_REQUESTED = 'requested'; - public const STATUSES = [ - self::STATUS_COMPLETED, - self::STATUS_REQUESTED, - ]; - #[ORM\ManyToOne(targetEntity: User::class, cascade: ['persist', 'remove'], inversedBy: "resetPasswords")] #[ORM\JoinColumn(name: "userUuid", referencedColumnName: "uuid")] protected User $user; @@ -37,8 +31,11 @@ class UserResetPassword extends AbstractEntity #[ORM\Column(name: "hash", type: "string", length: 64, unique: true)] protected string $hash; - #[ORM\Column(name: "status", type: "string", length: 20)] - protected string $status = self::STATUS_REQUESTED; + #[ORM\Column( + type: 'user_reset_password_status_enum', + options: ['default' => UserResetPasswordStatusEnum::Requested], + )] + protected UserResetPasswordStatusEnum $status = UserResetPasswordStatusEnum::Requested; public function __construct() { @@ -86,12 +83,12 @@ public function setHash(string $hash): self return $this; } - public function getStatus(): string + public function getStatus(): UserResetPasswordStatusEnum { return $this->status; } - public function setStatus(string $status): self + public function setStatus(UserResetPasswordStatusEnum $status): self { $this->status = $status; @@ -100,7 +97,7 @@ public function setStatus(string $status): self public function isCompleted(): bool { - return $this->getStatus() === self::STATUS_COMPLETED; + return $this->getStatus() === UserResetPasswordStatusEnum::Completed; } public function isValid(): bool @@ -114,7 +111,7 @@ public function isValid(): bool public function markAsCompleted(): self { - $this->status = self::STATUS_COMPLETED; + $this->status = UserResetPasswordStatusEnum::Completed; return $this; } diff --git a/src/User/src/Enum/UserResetPasswordStatusEnum.php b/src/User/src/Enum/UserResetPasswordStatusEnum.php new file mode 100644 index 0000000..995e3a2 --- /dev/null +++ b/src/User/src/Enum/UserResetPasswordStatusEnum.php @@ -0,0 +1,11 @@ +getFilterChain() ->attachByName(StringTrim::class) - ->attachByName(StripTags::class); + ->attachByName(StripTags::class) + ->attach(fn($value) => $value === null ? UserStatusEnum::Active : UserStatusEnum::from($value)); $this->getValidatorChain() ->attachByName(InArray::class, [ - 'haystack' => User::STATUSES, + 'haystack' => UserStatusEnum::cases(), 'message' => sprintf(Message::INVALID_VALUE, 'status'), ], true); } diff --git a/src/User/src/OpenAPI.php b/src/User/src/OpenAPI.php index f595147..25390d2 100644 --- a/src/User/src/OpenAPI.php +++ b/src/User/src/OpenAPI.php @@ -9,6 +9,8 @@ use Api\User\Entity\UserDetail; use Api\User\Entity\UserResetPassword; use Api\User\Entity\UserRole; +use Api\User\Enum\UserResetPasswordStatusEnum; +use Api\User\Enum\UserStatusEnum; use Api\User\Handler\AccountActivateHandler; use Api\User\Handler\AccountAvatarHandler; use Api\User\Handler\AccountHandler; @@ -168,7 +170,7 @@ new OA\Property(property: 'identity', type: 'string'), new OA\Property(property: 'password', type: 'string'), new OA\Property(property: 'passwordConfirm', type: 'string'), - new OA\Property(property: 'status', type: 'string', default: User::STATUS_ACTIVE), + new OA\Property(property: 'status', type: 'string', default: UserStatusEnum::Active), new OA\Property( property: 'detail', properties: [ @@ -243,7 +245,7 @@ new OA\Property(property: 'identity', type: 'string'), new OA\Property(property: 'password', type: 'string'), new OA\Property(property: 'passwordConfirm', type: 'string'), - new OA\Property(property: 'status', type: 'string', default: User::STATUS_ACTIVE), + new OA\Property(property: 'status', type: 'string', default: UserStatusEnum::Active), new OA\Property( property: 'detail', required: ['email'], @@ -1064,7 +1066,7 @@ new OA\Property(property: 'uuid', type: 'string', example: '1234abcd-abcd-4321-12ab-123456abcdef'), new OA\Property(property: 'hash', type: 'string'), new OA\Property(property: 'identity', type: 'string'), - new OA\Property(property: 'status', type: 'string', example: User::STATUS_ACTIVE), + new OA\Property(property: 'status', type: 'string', example: UserStatusEnum::Active), new OA\Property(property: 'isDeleted', type: 'boolean', example: false), new OA\Property(property: 'avatar', ref: '#/components/schemas/UserAvatar', nullable: true), new OA\Property(property: 'detail', ref: '#/components/schemas/UserDetail'), @@ -1166,7 +1168,7 @@ new OA\Property(property: 'uuid', type: 'string', example: '1234abcd-abcd-4321-12ab-123456abcdef'), new OA\Property(property: 'expires', type: 'object', example: new DateTimeImmutable()), new OA\Property(property: 'hash', type: 'string'), - new OA\Property(property: 'status', type: 'string', example: UserResetPassword::STATUS_REQUESTED), + new OA\Property(property: 'status', type: 'string', example: UserResetPasswordStatusEnum::Requested), new OA\Property(property: 'created', type: 'object', example: new DateTimeImmutable()), new OA\Property(property: 'updated', type: 'object', example: new DateTimeImmutable()), new OA\Property( diff --git a/src/User/src/Repository/UserRepository.php b/src/User/src/Repository/UserRepository.php index b357761..9bee50a 100644 --- a/src/User/src/Repository/UserRepository.php +++ b/src/User/src/Repository/UserRepository.php @@ -10,6 +10,7 @@ use Api\App\Message; use Api\User\Collection\UserCollection; use Api\User\Entity\User; +use Api\User\Enum\UserStatusEnum; use Doctrine\ORM\EntityRepository; use Dot\DependencyInjection\Attribute\Entity; use League\OAuth2\Server\Entities\ClientEntityInterface; @@ -132,7 +133,7 @@ public function getUserEntityByUserCredentials( return null; } - if ($clientEntity->getName() === 'frontend' && $result['status'] !== User::STATUS_ACTIVE) { + if ($clientEntity->getName() === 'frontend' && $result['status'] !== UserStatusEnum::Active) { throw new OAuthServerException(Message::USER_NOT_ACTIVATED, 6, 'inactive_user', 401); } diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index a08b171..2fbb5d0 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -14,6 +14,7 @@ use Api\User\Entity\User; use Api\User\Entity\UserDetail; use Api\User\Entity\UserResetPassword; +use Api\User\Enum\UserStatusEnum; use Api\User\Repository\UserDetailRepository; use Api\User\Repository\UserRepository; use Api\User\Repository\UserResetPasswordRepository; @@ -84,7 +85,7 @@ public function createUser(array $data = []): User ->setDetail($detail) ->setIdentity($data['identity']) ->usePassword($data['password']) - ->setStatus($data['status'] ?? User::STATUS_PENDING); + ->setStatus($data['status'] ?? UserStatusEnum::Pending); $detail->setUser($user); if (! empty($data['roles'])) { diff --git a/test/Functional/AbstractFunctionalTest.php b/test/Functional/AbstractFunctionalTest.php index bba7ca4..2139983 100644 --- a/test/Functional/AbstractFunctionalTest.php +++ b/test/Functional/AbstractFunctionalTest.php @@ -6,10 +6,12 @@ use Api\Admin\Entity\Admin; use Api\Admin\Entity\AdminRole; +use Api\Admin\Enum\AdminStatusEnum; use Api\App\Entity\RoleInterface; use Api\User\Entity\User; use Api\User\Entity\UserDetail; use Api\User\Entity\UserRole; +use Api\User\Enum\UserStatusEnum; use ApiTest\Functional\Traits\AuthenticationTrait; use ApiTest\Functional\Traits\DatabaseTrait; use Doctrine\ORM\EntityManagerInterface; @@ -373,6 +375,9 @@ protected function replaceService(string $service, object $mockInstance): void */ protected function getValidUserData(array $data = []): array { + $userRole = $this->findUserRole(UserRole::ROLE_USER); + $this->assertInstanceOf(UserRole::class, $userRole); + return [ 'detail' => [ 'firstName' => $data['detail']['firstName'] ?? 'First', @@ -382,9 +387,9 @@ protected function getValidUserData(array $data = []): array 'identity' => $data['identity'] ?? 'user@dotkernel.com', 'password' => $data['password'] ?? self::DEFAULT_PASSWORD, 'passwordConfirm' => $data['password'] ?? self::DEFAULT_PASSWORD, - 'status' => $data['status'] ?? User::STATUS_ACTIVE, + 'status' => $data['status'] ?? UserStatusEnum::Active, 'roles' => [ - ['uuid' => $this->findUserRole(UserRole::ROLE_USER)->getUuid()->toString()], + ['uuid' => $userRole->getUuid()->toString()], ], ]; } @@ -399,7 +404,7 @@ protected function getInvalidUserData(): array ], 'identity' => 'invalid', 'password' => 'invalid', - 'status' => Admin::STATUS_INACTIVE, + 'status' => UserStatusEnum::Pending, ]; } @@ -410,7 +415,7 @@ protected function getValidAdminData(): array 'identity' => 'admin@dotkernel.com', 'lastName' => 'Last', 'password' => self::DEFAULT_PASSWORD, - 'status' => Admin::STATUS_ACTIVE, + 'status' => AdminStatusEnum::Active, ]; } @@ -421,10 +426,14 @@ protected function getInvalidAdminData(): array 'identity' => 'invalid', 'lastName' => 'invalid', 'password' => 'invalid', - 'status' => Admin::STATUS_INACTIVE, + 'status' => AdminStatusEnum::Inactive, ]; } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ protected function getValidFrontendAccessTokenCredentials(array $data = []): array { $userData = $this->getValidUserData(); @@ -531,6 +540,8 @@ protected function createAdmin(): Admin protected function createUser(array $data = []): User { $userRole = $this->findUserRole(UserRole::ROLE_USER); + $this->assertInstanceOf(UserRole::class, $userRole); + $userData = $this->getValidUserData(); $user = new User(); diff --git a/test/Functional/AdminTest.php b/test/Functional/AdminTest.php index 6d01f86..e946e2e 100644 --- a/test/Functional/AdminTest.php +++ b/test/Functional/AdminTest.php @@ -10,6 +10,8 @@ use Api\User\Entity\User; use Api\User\Entity\UserDetail; use Api\User\Entity\UserRole; +use Api\User\Enum\UserStatusEnum; +use BackedEnum; use Dot\Mail\Service\MailService; use PHPUnit\Framework\MockObject\Exception; use Psr\Container\ContainerExceptionInterface; @@ -173,6 +175,7 @@ public function testAdminCanCreateAdminAccount(): void $adminRepository = $this->getEntityManager()->getRepository(Admin::class); $adminRole = $adminRoleRepository->findOneBy(['name' => AdminRole::ROLE_ADMIN]); + $this->assertInstanceOf(AdminRole::class, $adminRole); $requestBody = [ 'identity' => 'newadmin@test.com', @@ -192,6 +195,7 @@ public function testAdminCanCreateAdminAccount(): void $this->assertResponseCreated($response); $newAdmin = $adminRepository->findOneBy(['identity' => $requestBody['identity']]); + $this->assertInstanceOf(Admin::class, $newAdmin); $this->assertSame($requestBody['identity'], $newAdmin->getIdentity()); $this->assertSame($requestBody['firstName'], $newAdmin->getFirstName()); $this->assertSame($requestBody['lastName'], $newAdmin->getLastName()); @@ -330,18 +334,21 @@ public function testAdminCreateUserAccountDuplicateEmail(): void $this->loginAs($admin->getIdentity(), self::DEFAULT_PASSWORD, 'admin', 'admin'); + $userRole = $this->findUserRole(UserRole::ROLE_USER); + $this->assertInstanceOf(UserRole::class, $userRole); + $userData = [ 'identity' => 'test@user.com', 'password' => self::DEFAULT_PASSWORD, 'passwordConfirm' => self::DEFAULT_PASSWORD, - 'status' => 'pending', + 'status' => UserStatusEnum::Pending->value, 'detail' => [ 'firstName' => 'User', 'lastName' => 'Test', 'email' => 'user1@test.com', ], 'roles' => [ - ['uuid' => $this->findUserRole(UserRole::ROLE_USER)->getUuid()->toString()], + ['uuid' => $userRole->getUuid()->toString()], ], ]; @@ -366,6 +373,7 @@ public function testAdminCanCreateUserAccount(): void $userRoleRepository = $this->getEntityManager()->getRepository(UserRole::class); $userRole = $userRoleRepository->findOneBy(['name' => UserRole::ROLE_USER]); + $this->assertInstanceOf(UserRole::class, $userRole); $mailService = $this->createMock(MailService::class); $this->replaceService(MailService::class, $mailService); @@ -374,14 +382,14 @@ public function testAdminCanCreateUserAccount(): void 'identity' => 'test@user.com', 'password' => self::DEFAULT_PASSWORD, 'passwordConfirm' => self::DEFAULT_PASSWORD, - 'status' => 'pending', + 'status' => UserStatusEnum::Pending->value, 'detail' => [ 'firstName' => 'User', 'lastName' => 'Test', 'email' => 'test@user.com', ], 'roles' => [ - ['uuid' => $this->findUserRole(UserRole::ROLE_USER)->getUuid()->toString()], + ['uuid' => $userRole->getUuid()->toString()], ], ]; @@ -400,7 +408,7 @@ public function testAdminCanCreateUserAccount(): void $this->assertNotEmpty($data['uuid']); $this->assertNotEmpty($data['hash']); $this->assertSame($userData['identity'], $data['identity']); - $this->assertSame(User::STATUS_PENDING, $data['status']); + $this->assertSame(UserStatusEnum::Pending->value, $data['status']); $this->assertFalse($data['isDeleted']); $this->assertEmpty($data['avatar']); $this->assertEmpty($data['resetPasswords']); @@ -423,7 +431,7 @@ public function testAdminCanActiveUserAccount(): void { $admin = $this->createAdmin(); $user = $this->createUser([ - 'status' => User::STATUS_PENDING, + 'status' => UserStatusEnum::Pending, ]); $this->loginAs($admin->getIdentity(), self::DEFAULT_PASSWORD, 'admin', 'admin'); @@ -435,7 +443,7 @@ public function testAdminCanActiveUserAccount(): void $userRepository = $this->getEntityManager()->getRepository(User::class); $user = $userRepository->find($user->getUuid()->toString()); - $this->assertTrue($user->isActive()); + $this->assertTrue($user?->isActive()); } /** @@ -455,7 +463,7 @@ public function testAdminCanDeleteUserAccount(): void $userRepository = $this->getEntityManager()->getRepository(User::class); $user = $userRepository->find($user->getUuid()->toString()); - $this->assertTrue($user->isDeleted()); + $this->assertTrue($user?->isDeleted()); } /** @@ -499,7 +507,7 @@ public function testAdminUpdateUserAccountDuplicateEmail(): void $userDetailRepository = $this->getEntityManager()->getRepository(UserDetail::class); $userDetail = $userDetailRepository->find($user2->getDetail()->getUuid()); - $this->assertSame($user2->getDetail()->getEmail(), $userDetail->getEmail()); + $this->assertSame($user2->getDetail()->getEmail(), $userDetail?->getEmail()); } /** @@ -522,7 +530,7 @@ public function testAdminCanUpdateUserAccount(): void 'lastName' => 'Bar', 'email' => 'foobar@dotkernel.com', ], - 'status' => User::STATUS_ACTIVE, + 'status' => UserStatusEnum::Active->value, 'roles' => [ [ 'uuid' => $userRole->getUuid()->toString(), @@ -536,7 +544,8 @@ public function testAdminCanUpdateUserAccount(): void $data = json_decode($response->getBody()->getContents(), true); - $this->assertSame($updateData['status'], $data['status']); + $status = UserStatusEnum::tryFrom($updateData['status']); + $this->assertInstanceOf(BackedEnum::class, $status); $this->assertSame($updateData['detail']['firstName'], $data['detail']['firstName']); $this->assertSame($updateData['detail']['lastName'], $data['detail']['lastName']); $this->assertSame($updateData['roles'][0]['uuid'], $data['roles'][0]['uuid']); diff --git a/test/Functional/UserTest.php b/test/Functional/UserTest.php index e0cce27..75d216a 100644 --- a/test/Functional/UserTest.php +++ b/test/Functional/UserTest.php @@ -8,6 +8,8 @@ use Api\User\Entity\User; use Api\User\Entity\UserAvatar; use Api\User\Entity\UserResetPassword; +use Api\User\Enum\UserResetPasswordStatusEnum; +use Api\User\Enum\UserStatusEnum; use Api\User\Service\UserAvatarService; use DateInterval; use DateTimeImmutable; @@ -39,13 +41,13 @@ class UserTest extends AbstractFunctionalTest public function testRegisterAccountDuplicateIdentity(): void { $this->createUser([ - 'status' => User::STATUS_PENDING, + 'status' => UserStatusEnum::Pending, ]); $userAvatarService = $this->createMock(UserAvatarService::class); $this->replaceService(UserAvatarService::class, $userAvatarService); - $response = $this->post('/user', $this->getValidUserData()); + $response = $this->post('/user', $this->getValidUserData(['status' => UserStatusEnum::Pending->value])); $this->assertResponseConflict($response); $data = json_decode($response->getBody()->getContents(), true); @@ -65,13 +67,13 @@ public function testRegisterAccountDuplicateEmail(): void { $this->createUser([ 'identity' => 'foo@dotkernel.com', - 'status' => User::STATUS_PENDING, + 'status' => UserStatusEnum::Pending, ]); $userAvatarService = $this->createMock(UserAvatarService::class); $this->replaceService(UserAvatarService::class, $userAvatarService); - $response = $this->post('/user', $this->getValidUserData()); + $response = $this->post('/user', $this->getValidUserData(['status' => UserStatusEnum::Pending->value])); $this->assertResponseConflict($response); $data = json_decode($response->getBody()->getContents(), true); @@ -83,7 +85,9 @@ public function testRegisterAccountDuplicateEmail(): void } /** + * @throws ContainerExceptionInterface * @throws Exception + * @throws NotFoundExceptionInterface */ public function testRegisterAccount(): void { @@ -94,7 +98,7 @@ public function testRegisterAccount(): void $this->replaceService(MailService::class, $mailService); $user = $this->getValidUserData([ - 'status' => User::STATUS_PENDING, + 'status' => UserStatusEnum::Pending->value, ]); $response = $this->post('/user', $user); @@ -103,7 +107,7 @@ public function testRegisterAccount(): void $data = json_decode($response->getBody()->getContents(), true); $this->assertSame($user['identity'], $data['identity']); - $this->assertSame(User::STATUS_PENDING, $data['status']); + $this->assertSame(UserStatusEnum::Pending->value, $data['status']); $this->assertFalse($data['isDeleted']); $this->assertArrayHasKey('detail', $data); $this->assertArrayHasKey('email', $data['detail']); @@ -239,7 +243,7 @@ public function testActivateMyAccountAlreadyActivated(): void public function testActivateMyAccount(): void { $user = $this->createUser([ - 'status' => User::STATUS_PENDING, + 'status' => UserStatusEnum::Pending, ]); $this->assertFalse($user->isActive()); @@ -248,7 +252,7 @@ public function testActivateMyAccount(): void $userRepository = $this->getEntityManager()->getRepository(User::class); $user = $userRepository->find($user->getUuid()->toString()); - $this->assertTrue($user->isActive()); + $this->assertTrue($user?->isActive()); } /** @@ -259,7 +263,7 @@ public function testActivateMyAccount(): void public function testActivateAccountByEmail(): void { $user = $this->createUser([ - 'status' => User::STATUS_PENDING, + 'status' => UserStatusEnum::Pending, ]); $mailService = $this->createMock(MailService::class); @@ -293,7 +297,7 @@ public function testDeleteMyAccount(): void $userRepository = $this->getEntityManager()->getRepository(User::class); $deletedUser = $userRepository->find($user->getUuid()->toString()); - $this->assertTrue($deletedUser->isDeleted()); + $this->assertTrue($deletedUser?->isDeleted()); } public function testRequestResetPasswordInvalidHash(): void @@ -313,7 +317,7 @@ public function testRequestResetPasswordExpired(): void $resetPassword = (new UserResetPassword()) ->setUser($user) - ->setStatus(UserResetPassword::STATUS_REQUESTED) + ->setStatus(UserResetPasswordStatusEnum::Requested) ->setHash('test') ->setExpires((new DateTimeImmutable())->sub(new DateInterval('P1D'))); $user->addResetPassword($resetPassword); @@ -352,7 +356,7 @@ public function testRequestResetPasswordAlreadyUsed(): void $resetPassword = (new UserResetPassword()) ->setUser($user) - ->setStatus(UserResetPassword::STATUS_COMPLETED) + ->setStatus(UserResetPasswordStatusEnum::Completed) ->setHash('test') ->setExpires((new DateTimeImmutable())->add(new DateInterval('P1D'))); $user->addResetPassword($resetPassword); @@ -391,7 +395,7 @@ public function testResetPassword(): void $resetPassword = (new UserResetPassword()) ->setUser($user) - ->setStatus(UserResetPassword::STATUS_REQUESTED) + ->setStatus(UserResetPasswordStatusEnum::Requested) ->setHash('test') ->setExpires((new DateTimeImmutable())->add(new DateInterval('P1D'))); $user->addResetPassword($resetPassword); diff --git a/test/Unit/Admin/Service/AdminServiceTest.php b/test/Unit/Admin/Service/AdminServiceTest.php index 5dd4a6f..9775617 100644 --- a/test/Unit/Admin/Service/AdminServiceTest.php +++ b/test/Unit/Admin/Service/AdminServiceTest.php @@ -6,6 +6,7 @@ use Api\Admin\Entity\Admin; use Api\Admin\Entity\AdminRole; +use Api\Admin\Enum\AdminStatusEnum; use Api\Admin\Repository\AdminRepository; use Api\Admin\Service\AdminRoleService; use Api\Admin\Service\AdminService as Subject; @@ -81,7 +82,7 @@ public function testCreateAdminSuperAdminRole(): void $this->assertTrue(Admin::verifyPassword($data['password'], $admin->getPassword())); $this->assertCount(count($data['roles']), $admin->getRoles()); $this->assertSame($role->getName(), ($admin->getRoles()->first())->getName()); - $this->assertSame(Admin::STATUS_ACTIVE, $admin->getStatus()); + $this->assertSame(AdminStatusEnum::Active, $admin->getStatus()); } private function getAdmin(array $data = []): array @@ -103,7 +104,7 @@ private function getAdminEntity(array $data = []): Admin ->usePassword($data['password'] ?? '') ->setFirstName($data['firstName'] ?? '') ->setLastName($data['lastName'] ?? '') - ->setStatus($data['status'] ?? Admin::STATUS_ACTIVE); + ->setStatus($data['status'] ?? AdminStatusEnum::Active); foreach ($data['roles'] ?? [] as $role) { $admin->addRole( diff --git a/test/Unit/App/Middleware/AuthorizationMiddlewareTest.php b/test/Unit/App/Middleware/AuthorizationMiddlewareTest.php index 8b48a67..a0dda11 100644 --- a/test/Unit/App/Middleware/AuthorizationMiddlewareTest.php +++ b/test/Unit/App/Middleware/AuthorizationMiddlewareTest.php @@ -6,6 +6,7 @@ use Api\Admin\Entity\Admin; use Api\Admin\Entity\AdminRole; +use Api\Admin\Enum\AdminStatusEnum; use Api\Admin\Repository\AdminRepository; use Api\App\Message; use Api\App\Middleware\AuthorizationMiddleware as Subject; @@ -72,7 +73,7 @@ public function testAuthorizationInactiveAdmin(): void { $user = (new Admin()) ->setIdentity('admin@dotkernel.com') - ->setStatus(Admin::STATUS_INACTIVE) + ->setStatus(AdminStatusEnum::Inactive) ->addRole((new AdminRole())->setName(AdminRole::ROLE_ADMIN)); $this->adminRepository->method('findOneBy')->willReturn($user); diff --git a/test/Unit/User/Service/UserServiceTest.php b/test/Unit/User/Service/UserServiceTest.php index 3fa30cb..720643f 100644 --- a/test/Unit/User/Service/UserServiceTest.php +++ b/test/Unit/User/Service/UserServiceTest.php @@ -11,6 +11,7 @@ use Api\User\Entity\User; use Api\User\Entity\UserDetail; use Api\User\Entity\UserRole; +use Api\User\Enum\UserStatusEnum; use Api\User\Repository\UserDetailRepository; use Api\User\Repository\UserRepository; use Api\User\Repository\UserResetPasswordRepository; @@ -145,7 +146,7 @@ public function testCreateUser(): void $this->assertSame($data['detail']['firstName'], $user->getDetail()->getFirstName()); $this->assertSame($data['detail']['lastName'], $user->getDetail()->getLastName()); $this->assertSame($data['detail']['email'], $user->getDetail()->getEmail()); - $this->assertSame(User::STATUS_PENDING, $user->getStatus()); + $this->assertSame(UserStatusEnum::Pending, $user->getStatus()); $this->assertFalse($user->isDeleted()); $this->assertFalse($user->isActive()); } @@ -214,7 +215,7 @@ private function getUserEntity(array $data = []): User $user ->setIdentity($data['identity'] ?? '') ->usePassword($data['password'] ?? '') - ->setStatus($data['status'] ?? User::STATUS_PENDING) + ->setStatus($data['status'] ?? UserStatusEnum::Pending) ->setDetail( (new UserDetail()) ->setUser($user)