Skip to content
Merged
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
43 changes: 39 additions & 4 deletions money/tests/data/MoneyThrowTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

use Brick\Math\BigDecimal;
use Brick\Math\BigInteger;
use Brick\Math\Exception\RoundingNecessaryException;
use Brick\Math\RoundingMode;
use Brick\Money\Context\CustomContext;
use Brick\Money\Currency;
use Brick\Money\CurrencyConverter;
use Brick\Money\Exception\ExchangeRateException;
use Brick\Money\Exception\UnknownCurrencyException;
use Brick\Money\Money;
use Brick\Money\RationalMoney;
use PHPStan\TrinaryLogic;
Expand Down Expand Up @@ -340,12 +343,16 @@ public function convertWithSafeCurrency(CurrencyConverter $converter, Money $mon
}
}

public function convertWithSafeCurrencyAndRoundingMode(CurrencyConverter $converter, Money $money): void
{
public function convertWithSafeCurrencyCatchingResidualExceptions(
CurrencyConverter $converter,
Money $money,
): void {
try {
$result = $converter->convert($money, 'USD', [], roundingMode: RoundingMode::Down);
$result = $converter->convert($money, 'USD');
} catch (ExchangeRateException | RoundingNecessaryException) {
$result = $money;
} finally {
assertVariableCertainty(TrinaryLogic::createMaybe(), $result);
assertVariableCertainty(TrinaryLogic::createYes(), $result);
}
}

Expand All @@ -358,6 +365,34 @@ public function convertWithUnknownCurrency(CurrencyConverter $converter, Money $
}
}

public function convertWithUnknownCurrencyAndSkippedNamedSafeRoundingMode(
CurrencyConverter $converter,
Money $money,
string $code,
): void {
try {
$result = $converter->convert($money, $code, roundingMode: RoundingMode::Down);
} catch (ExchangeRateException | UnknownCurrencyException) {
$result = $money;
} finally {
assertVariableCertainty(TrinaryLogic::createYes(), $result);
}
}

public function convertWithUnknownCurrencyAndPositionalSafeRoundingMode(
CurrencyConverter $converter,
Money $money,
string $code,
): void {
try {
$result = $converter->convert($money, $code, new CustomContext(2), RoundingMode::Down);
} catch (ExchangeRateException | UnknownCurrencyException) {
$result = $money;
} finally {
assertVariableCertainty(TrinaryLogic::createYes(), $result);
}
}

public function convertToRationalWithSafeCurrency(CurrencyConverter $converter, Money $money): void
{
try {
Expand Down
Loading