Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
voidgraphics committed Oct 11, 2024
1 parent 76d2bd9 commit 0e47fe5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function jsonSerialize(): array
'base' => $this->getRational($this->base)->getAmount(),
'currency' => $this->base->getCurrency()->getCurrencyCode(),
'units' => $this->units,
'vat' => $this->vat->percentage(),
'vat' => $this->vat?->percentage(),
'total' => [
'exclusive' => $this->getRational($excl)->getAmount(),
'inclusive' => $this->getRational($incl)->getAmount(),
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/HasVatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@
expect($instance->inclusive(true)->__toString())->toBe('EUR 5.50');
});

it('does not throw an exception when serializing a price with no vat', function () {
$instance = Price::ofMinor(500, 'EUR')->setUnits(3);

expect($instance->jsonSerialize())
->toBeArray();
});

0 comments on commit 0e47fe5

Please sign in to comment.