From efc446d073213ad7c3e433d14b2871c5dc41870f Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Tue, 28 Jul 2026 09:20:12 +0900 Subject: [PATCH 1/4] fix: remove leftover dd() debug statement from UserController::createUser --- .../Features/Controller/UserController.php | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/app/Packages/Features/Controller/UserController.php b/src/app/Packages/Features/Controller/UserController.php index 9a8ea7c..1cefe9d 100644 --- a/src/app/Packages/Features/Controller/UserController.php +++ b/src/app/Packages/Features/Controller/UserController.php @@ -16,6 +16,32 @@ class UserController extends Controller { + public function createUser( + Request $request, + CreateUserUseCase $useCase, + ): JsonResponse { + try { + $command = CreateUserCommand::fromArray($request->all()); + + $dto = $useCase->handle($command); + + return response()->json([ + 'status' => 'success', + 'data' => UserViewModelFactory::build($dto)->toArray(), + ], 201); + } catch (\Throwable $throwable) { + Log::error('Failed to create user', [ + 'message' => $throwable->getMessage(), + 'trace' => $throwable->getTraceAsString(), + ]); + + return response()->json([ + 'status' => 'error', + 'message' => 'Internal Server Error', + ], 500); + } + } + public function getUserById( Request $request, GetUserByIdUseCase $useCase, @@ -111,29 +137,4 @@ public function deleteUser( ], 500); } } - - public function createUser( - Request $request, - CreateUserUseCase $useCase, - ): JsonResponse { - try { - $command = CreateUserCommand::fromArray($request->all()); - $dto = $useCase->handle($command); - - return response()->json([ - 'status' => 'success', - 'data' => UserViewModelFactory::build($dto)->toArray(), - ], 201); - } catch (\Throwable $throwable) { - Log::error('Failed to create user', [ - 'message' => $throwable->getMessage(), - 'trace' => $throwable->getTraceAsString(), - ]); - - return response()->json([ - 'status' => 'error', - 'message' => 'Internal Server Error', - ], 500); - } - } } \ No newline at end of file From f0456724cceb09bba8ca1217bb5c227bdb19bf85 Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Tue, 28 Jul 2026 09:20:16 +0900 Subject: [PATCH 2/4] fix: make subscription_tier optional in CreateUserCommand --- .../CommandUseCases/UseCommand/User/CreateUserCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/Packages/Features/CommandUseCases/UseCommand/User/CreateUserCommand.php b/src/app/Packages/Features/CommandUseCases/UseCommand/User/CreateUserCommand.php index 271cdd2..524ff61 100644 --- a/src/app/Packages/Features/CommandUseCases/UseCommand/User/CreateUserCommand.php +++ b/src/app/Packages/Features/CommandUseCases/UseCommand/User/CreateUserCommand.php @@ -12,7 +12,6 @@ final class CreateUserCommand 'email', 'password', 'age_range', - 'subscription_tier', ]; private function __construct( @@ -21,7 +20,7 @@ private function __construct( public readonly string $email, public readonly string $password, public readonly string $ageRange, - public readonly string $subscriptionTier, + public readonly ?string $subscriptionTier, public readonly ?string $subscriptionExpiresAt, ) { @@ -41,7 +40,7 @@ public static function fromArray(array $data): self email: $data['email'], password: $data['password'], ageRange: $data['age_range'], - subscriptionTier: $data['subscription_tier'], + subscriptionTier: $data['subscription_tier'] ?? null, subscriptionExpiresAt: $data['subscription_expires_at'] ?? null, ); } From 593e930954b55de1b43b88de64ec286a69fd6e87 Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Tue, 28 Jul 2026 09:20:19 +0900 Subject: [PATCH 3/4] fix: default subscription_tier to free in CreateUserUseCase when omitted --- .../CommandUseCases/UseCase/User/CreateUserUseCase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/Packages/Features/CommandUseCases/UseCase/User/CreateUserUseCase.php b/src/app/Packages/Features/CommandUseCases/UseCase/User/CreateUserUseCase.php index 92cade5..a798caa 100644 --- a/src/app/Packages/Features/CommandUseCases/UseCase/User/CreateUserUseCase.php +++ b/src/app/Packages/Features/CommandUseCases/UseCase/User/CreateUserUseCase.php @@ -4,6 +4,7 @@ use App\Packages\Domains\User\Interface\UserRepositroyInterface; use App\Packages\Domains\User\Factory\UserEntityFactory; +use App\Packages\Domains\User\Subscription\SubscriptionTier; use App\Packages\Features\CommandUseCases\UseCommand\User\CreateUserCommand; use App\Packages\Features\QueryUseCases\Dto\User\UserDto; @@ -21,7 +22,7 @@ public function handle(CreateUserCommand $command): UserDto 'last_name' => $command->lastName, 'email' => $command->email, 'age_range' => $command->ageRange, - 'subscription_tier' => $command->subscriptionTier, + 'subscription_tier' => $command->subscriptionTier ?? SubscriptionTier::Free->value, 'subscription_expires_at' => $command->subscriptionExpiresAt, 'password_hash' => bcrypt($command->password), ]); From 93a87c4d2e65719f4b276f01249b9f58115ee073 Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Tue, 28 Jul 2026 09:20:23 +0900 Subject: [PATCH 4/4] test: cover optional subscription_tier for CreateUserCommand and CreateUserUseCase --- .../CommandUseCases/CreateUserCommandTest.php | 11 +++++- .../CommandUseCases/CreateUserUseCaseTest.php | 35 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/app/Packages/Features/Tests/CommandUseCases/CreateUserCommandTest.php b/src/app/Packages/Features/Tests/CommandUseCases/CreateUserCommandTest.php index 8957489..4773b54 100644 --- a/src/app/Packages/Features/Tests/CommandUseCases/CreateUserCommandTest.php +++ b/src/app/Packages/Features/Tests/CommandUseCases/CreateUserCommandTest.php @@ -66,7 +66,16 @@ public static function missingKeyProvider(): array ['email'], ['password'], ['age_range'], - ['subscription_tier'], ]; } + + public function test_fromArray_allows_subscription_tier_to_be_omitted(): void + { + $data = $this->validData(); + unset($data['subscription_tier']); + + $command = CreateUserCommand::fromArray($data); + + $this->assertNull($command->subscriptionTier); + } } \ No newline at end of file diff --git a/src/app/Packages/Features/Tests/CommandUseCases/CreateUserUseCaseTest.php b/src/app/Packages/Features/Tests/CommandUseCases/CreateUserUseCaseTest.php index 81e1632..1e5e7f5 100644 --- a/src/app/Packages/Features/Tests/CommandUseCases/CreateUserUseCaseTest.php +++ b/src/app/Packages/Features/Tests/CommandUseCases/CreateUserUseCaseTest.php @@ -20,18 +20,18 @@ protected function tearDown(): void parent::tearDown(); } - private function buildCommand(): CreateUserCommand + private function buildCommand(array $overrides = []): CreateUserCommand { $faker = FakerFactory::create(); - return CreateUserCommand::fromArray([ + return CreateUserCommand::fromArray(array_merge([ 'first_name' => $faker->firstName(), 'last_name' => $faker->lastName(), 'email' => $faker->unique()->safeEmail(), 'password' => $faker->password(8), 'age_range' => $faker->randomElement(['teens', '20s', '30s', '40s', '50s', '60plus']), 'subscription_tier' => 'free', - ]); + ], $overrides)); } private function buildDto(): UserDto @@ -66,4 +66,33 @@ public function test_handle_passes_entity_to_repository_and_returns_dto(): void $this->assertSame($dto, $result); } + + public function test_handle_defaults_subscription_tier_to_free_when_omitted(): void + { + $faker = FakerFactory::create(); + $command = CreateUserCommand::fromArray([ + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + 'email' => $faker->unique()->safeEmail(), + 'password' => $faker->password(8), + 'age_range' => 'teens', + ]); + $dto = $this->buildDto(); + $passedEntity = null; + + /** @var UserRepositroyInterface|MockInterface $repository */ + $repository = Mockery::mock(UserRepositroyInterface::class); + $repository->shouldReceive('createUser') + ->once() + ->with(Mockery::on(function (UserEntity $entity) use (&$passedEntity) { + $passedEntity = $entity; + + return true; + })) + ->andReturn($dto); + + (new CreateUserUseCase($repository))->handle($command); + + $this->assertSame('free', $passedEntity->getSubscription()->getTier()->value); + } } \ No newline at end of file