Skip to content

Commit b617314

Browse files
committed
Fixed price instanciation with minor value of 0
1 parent 55b1dca commit b617314

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Models/Price.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function __construct(
4343

4444
public function fill(array $attributes)
4545
{
46-
if ($minor = $attributes['minor'] ?? null) {
46+
$minor = $attributes['minor'] ?? null;
47+
48+
if (! is_null($minor)) {
4749
$attributes['amount'] = $minor;
4850
} else if (($amount = $attributes['amount'] ?? null) && ($currency = $attributes['currency'] ?? null)) {
4951
$attributes['amount'] = Money::of($amount, $currency)->getMinorAmount()->toInt();

tests/Feature/InstanciationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@
3232
$this->assertSame('EUR', $price->currency);
3333
});
3434

35+
test('a price instance can be created with a minor value of 0', function() {
36+
$price = new Price(
37+
type: 'selling',
38+
minor: 0,
39+
currency: 'EUR',
40+
activated_at: now()->addWeek()
41+
);
42+
43+
$this->assertNotNull($price);
44+
$this->assertInstanceOf(Price::class, $price);
45+
$this->assertSame('selling', $price->type);
46+
$this->assertNotNull($price->amount);
47+
$this->assertSame(0, $price->amount);
48+
$this->assertSame('EUR', $price->currency);
49+
});
50+
3551
test('a price instance can be created from a minor value using a constructor arguments array', function() {
3652
$price = new Price([
3753
'type' => 'selling',

0 commit comments

Comments
 (0)