Skip to content

fix: default subscription_tier to free in SubscriptionFactory when omitted / SubscriptionFactoryでsubscription_tier省略時にfreeへデフォルト設定 - #558

Merged
zigzagdev merged 2 commits into
feat/userfrom
fix/create-user-subscription-tier
Aug 1, 2026
Merged

fix: default subscription_tier to free in SubscriptionFactory when omitted / SubscriptionFactoryでsubscription_tier省略時にfreeへデフォルト設定#558
zigzagdev merged 2 commits into
feat/userfrom
fix/create-user-subscription-tier

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Motivation / 目的

subscription_tier was already made optional at the CreateUserCommand/CreateUserUseCase level, but the Domain-layer factories (UserEntityFactory, SubscriptionFactory) still assumed the key was always present and non-null. Any future caller that omitted subscription_tier would hit a TypeError from SubscriptionTier::from(null) instead of getting the intended free default.

subscription_tierCreateUserCommand/CreateUserUseCase側では既に任意項目化されていましたが、Domain層のファクトリ(UserEntityFactory, SubscriptionFactory)は依然として値が必ず存在する前提でした。将来subscription_tierを省略する呼び出しが増えた場合、SubscriptionTier::from(null)TypeErrorになってしまう抜けがありました。

What I have done / 実施内容

  • SubscriptionFactory::build(): default the tier to SubscriptionTier::Free->value when $data['tier'] is null
  • UserEntityFactory::build(): pass $data['subscription_tier'] ?? null instead of a direct array access, so a missing key no longer raises an undefined array key warning before reaching SubscriptionFactory
  • Added test coverage for the default behavior

Test Results / テスト結果

  • UserEntityFactoryTest::test_build_returns_user_entity_with_correct_values
  • UserEntityFactoryTest::test_build_sets_password_hash_when_provided
  • UserEntityFactoryTest::test_build_defaults_subscription_tier_to_free_when_omitted
  • UserEntityFactoryTest::test_build_passes_expires_at_to_subscription
  • SubscriptionTest (all cases)
  • UserEntityTest (all cases)
  • CreateUserCommandTest / CreateUserUseCaseTest / UpdateUserCommandTest / UpdateUserUseCaseTest (all cases)

Closes #559

@github-actions github-actions Bot added bug Something isn't working backend labels Aug 1, 2026
@zigzagdev zigzagdev self-assigned this Aug 1, 2026
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.90%. Comparing base (93a87c4) to head (a764093).
⚠️ Report is 1 commits behind head on feat/user.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##             feat/user     #558      +/-   ##
===============================================
+ Coverage        62.85%   62.90%   +0.04%     
- Complexity        1621     1622       +1     
===============================================
  Files              136      136              
  Lines             8399     8410      +11     
===============================================
+ Hits              5279     5290      +11     
  Misses            3120     3120              
Files with missing lines Coverage Δ
...kages/Domains/User/Factory/SubscriptionFactory.php 100.00% <100.00%> (ø)
...ackages/Domains/User/Factory/UserEntityFactory.php 100.00% <100.00%> (ø)
...mains/User/Tests/Factory/UserEntityFactoryTest.php 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zigzagdev zigzagdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@zigzagdev
zigzagdev merged commit 12e4976 into feat/user Aug 1, 2026
28 checks passed
@zigzagdev
zigzagdev deleted the fix/create-user-subscription-tier branch August 1, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

1 participant