Skip to content

Commit f7358f8

Browse files
fix: allow nullables properties in SubscriptionPurchase (#223)
Co-authored-by: Dhemy <[email protected]>
1 parent fa65d0c commit f7358f8

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

src/Domain/Purchase/Entity/SubscriptionPurchase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function __construct(
2929
public string $regionCode,
3030
public SubscriptionState $subscriptionState,
3131
public AcknowledgementState $acknowledgementState,
32-
public ExternalAccountIdentifiers $externalAccountIdentifiers,
33-
public SubscribeWithGoogleInfo $subscribeWithGoogleInfo,
32+
public ?ExternalAccountIdentifiers $externalAccountIdentifiers = null,
33+
public ?SubscribeWithGoogleInfo $subscribeWithGoogleInfo = null,
3434
public array $lineItems = [],
3535
public ?GooglePlay\Time $startTime = null,
3636
public ?string $linkedPurchaseToken = null,

src/Domain/Purchase/Subscription/OfferDetails.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
final readonly class OfferDetails
1313
{
1414
/**
15-
* @param string[] $offerTags
15+
* @param string[]|null $offerTags
1616
*/
1717
public function __construct(
18-
public array $offerTags,
1918
public string $basePlanId,
19+
public ?array $offerTags = null,
2020
public ?string $offerId = null,
2121
) {
2222
}

tests/Domain/Purchase/Entity/SubscriptionPurchaseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,30 @@ public function instantiation(): void
9090
$actual->subscribeWithGoogleInfo
9191
);
9292
}
93+
94+
/** @test */
95+
public function instantiation_with_required_fields(): void
96+
{
97+
$data = [
98+
'kind' => 'androidpublisher#subscriptionPurchaseV2',
99+
'regionCode' => $this->faker->countryCode(),
100+
'subscriptionState' => $this->randomEnumValue(SubscriptionState::class),
101+
'acknowledgementState' => $this->randomEnumValue(enumClass: AcknowledgementState::class),
102+
];
103+
104+
$actual = $this->normalizer->normalize($data, SubscriptionPurchase::class);
105+
106+
$this->assertSame($data['kind'], $actual->kind);
107+
$this->assertSame($data['regionCode'], $actual->regionCode);
108+
$this->assertSame($data['subscriptionState'], $actual->subscriptionState->value);
109+
$this->assertSame($data['acknowledgementState'], $actual->acknowledgementState->value);
110+
$this->assertNull($actual->externalAccountIdentifiers);
111+
$this->assertNull($actual->subscribeWithGoogleInfo);
112+
$this->assertEmpty($actual->lineItems);
113+
$this->assertNull($actual->startTime);
114+
$this->assertNull($actual->linkedPurchaseToken);
115+
$this->assertNull($actual->pausedStateContext);
116+
$this->assertNull($actual->canceledStateContext);
117+
$this->assertNull($actual->testPurchase);
118+
}
93119
}

tests/Domain/Purchase/Subscription/OfferDetailsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,17 @@ public function instantiation(): void
2828
$this->assertSame($basePlanId, $actual->basePlanId);
2929
$this->assertSame($offerId, $actual->offerId);
3030
}
31+
32+
/** @test */
33+
public function instantiation_with_required_fields(): void
34+
{
35+
$data = ['basePlanId' => $this->faker->word()];
36+
37+
$actual = $this->normalizer->normalize($data, OfferDetails::class);
38+
39+
$this->assertInstanceOf(OfferDetails::class, $actual);
40+
$this->assertSame($data['basePlanId'], $actual->basePlanId);
41+
$this->assertNull($actual->offerTags);
42+
$this->assertNull($actual->offerId);
43+
}
3144
}

0 commit comments

Comments
 (0)