diff --git a/money/tests/data/MoneyThrowTypes.php b/money/tests/data/MoneyThrowTypes.php index b3b7513..b17d47a 100644 --- a/money/tests/data/MoneyThrowTypes.php +++ b/money/tests/data/MoneyThrowTypes.php @@ -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; @@ -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); } } @@ -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 {