Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function equals(Currency $other): bool
return $this->code === $other->code;
}

/**
* Returns a new Money with zero amount in this currency.
*/
public function zero(): Money
{
return new Money(0, $this);
}

public function __toString(): string
{
return $this->code;
Expand Down
9 changes: 9 additions & 0 deletions tests/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Money;

use Money\Currency;
use Money\Money;
use PHPUnit\Framework\TestCase;

use function json_encode;
Expand Down Expand Up @@ -44,4 +45,12 @@ public function itProvidesEqualityComparison(): void
$currency = new Currency('usd');
self::assertTrue($currency->equals(new Currency('USD')));
}

/**
* @test
*/
public function itCreatesZeroMoney(): void
{
self::assertTrue((new Currency('USD'))->zero()->equals(new Money(0, new Currency('USD'))));
}
}
Loading