Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cevro committed Oct 27, 2024
1 parent e4b370e commit caaa8a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
15 changes: 5 additions & 10 deletions tests/Tests/Price/TestCurrency.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ require_once __DIR__ . '/../FakeBootstrap.php';

class TestCurrency extends BaseTest
{
public function testCreateNonExist(): void
{
Assert::exception(fn() => new Currency('XBT'), \Exception::class);
}

public function testCases(): void
{
foreach (Currency::cases() as $case) {
Expand All @@ -27,21 +22,21 @@ class TestCurrency extends BaseTest

public function testFromExists(): void
{
$currency = Currency::from(Currency::CZK);
$currency = Currency::CZK;
Assert::type(Currency::class, $currency);
$currencyLower = Currency::from('czk');
$currencyLower = Currency::from('CZK');
Assert::type(Currency::class, $currencyLower);
}

public function testTryFromExists(): void
{
$currency = Currency::tryFrom(Currency::CZK);
$currency = Currency::CZK;
Assert::type(Currency::class, $currency);
}

public function testFromNonExists(): void
{
Assert::exception(fn() => Currency::from('XBT'), \Exception::class);
Assert::exception(fn() => Currency::from('XBT'), \ValueError::class);
}

public function testTryFromNonExists(): void
Expand All @@ -52,7 +47,7 @@ class TestCurrency extends BaseTest

public function testRender(): void
{
$currency = new Currency(Currency::CZK);
$currency = Currency::CZK;
Assert::same('2.00 Kč', $currency->format(2.0));
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Tests/Price/TestMultiPrice.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,47 @@ class TestMultiPrice extends BaseTest

public function testCreateFilled(): void
{
$multiPrice = new MultiCurrencyPrice([new Price(Currency::from(Currency::CZK))]);
$multiPrice = new MultiCurrencyPrice([new Price(Currency::CZK)]);
$price = $multiPrice->czk;
Assert::type(Price::class, $price);
}

public function testGetAccess(): void
{
$multiPrice = new MultiCurrencyPrice([new Price(Currency::from(Currency::CZK), 4),]);
$multiPrice = new MultiCurrencyPrice([new Price(Currency::CZK, 4),]);
Assert::type(Price::class, $multiPrice->czk);
Assert::exception(fn() => $multiPrice->eur, \OutOfRangeException::class);
Assert::type(Price::class, $multiPrice->CZK);
}

public function testSetAccess(): void
{
$multiPrice = new MultiCurrencyPrice([new Price(Currency::from(Currency::CZK), 4),]);
$multiPrice->czk = new Price(Currency::from(Currency::CZK), 2);
$multiPrice = new MultiCurrencyPrice([new Price(Currency::CZK, 4),]);
$multiPrice->czk = new Price(Currency::CZK, 2);
Assert::type(Price::class, $multiPrice->czk);
Assert::same(2.0, $multiPrice->czk->getAmount());

Assert::exception(
fn() => $multiPrice->czk = new Price(Currency::from(Currency::EUR)),
fn() => $multiPrice->czk = new Price(Currency::EUR),
\LogicException::class
);
Assert::exception(
fn() => $multiPrice->CZK = new Price(Currency::from(Currency::EUR)),
fn() => $multiPrice->CZK = new Price(Currency::EUR),
\LogicException::class
);
Assert::exception(
fn() => $multiPrice->eur = new Price(Currency::from(Currency::EUR)),
fn() => $multiPrice->eur = new Price(Currency::EUR),
\OutOfRangeException::class
);
}

public function testCreateSum(): void
{
$multiPrice1 = new MultiCurrencyPrice([new Price(Currency::from(Currency::CZK), 2)]);
$multiPrice1 = new MultiCurrencyPrice([new Price(Currency::CZK, 2)]);
$multiPrice2 = new MultiCurrencyPrice(
[
new Price(Currency::from(Currency::CZK), 1),
new Price(Currency::from(Currency::EUR), 4),
new Price(Currency::CZK, 1),
new Price(Currency::EUR, 4),
]
);

Expand Down
10 changes: 5 additions & 5 deletions tests/Tests/Price/TestPrice.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ class TestPrice extends BaseTest
{
public function testAddSame(): void
{
$price1 = new Price(new Currency(Currency::CZK), 2);
$price2 = new Price(new Currency(Currency::CZK), 4);
$price1 = new Price(Currency::CZK, 2);
$price2 = new Price(Currency::CZK, 4);
$price1->add($price2);
Assert::same(6.0, $price1->getAmount());
Assert::same(4.0, $price2->getAmount());
}

public function testNotSame(): void
{
$price1 = new Price(new Currency(Currency::CZK), 2);
$price2 = new Price(new Currency(Currency::EUR), 4);
$price1 = new Price(Currency::CZK, 2);
$price2 = new Price(Currency::EUR, 4);
Assert::exception(fn() => $price1->add($price2), \LogicException::class);
}

public function testAdd(): void
{
$price1 = new Price(new Currency(Currency::CZK), 2);
$price1 = new Price(Currency::CZK, 2);
$price1->addAmount(3.5);
Assert::same(5.5, $price1->getAmount());
}
Expand Down

0 comments on commit caaa8a2

Please sign in to comment.