From 36d44c7a2c4a4bd97231042c9e9dcce139407844 Mon Sep 17 00:00:00 2001 From: George Mponos Date: Sat, 18 Aug 2018 22:22:30 +0300 Subject: [PATCH] Add a test case with a very very tiny float --- tests/Parser/DecimalMoneyParserTest.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/Parser/DecimalMoneyParserTest.php b/tests/Parser/DecimalMoneyParserTest.php index 364d6ce9..3630a158 100644 --- a/tests/Parser/DecimalMoneyParserTest.php +++ b/tests/Parser/DecimalMoneyParserTest.php @@ -5,6 +5,7 @@ use Money\Currencies; use Money\Currency; use Money\Exception\ParserException; +use Money\Money; use Money\Parser\DecimalMoneyParser; use PHPUnit\Framework\TestCase; use Prophecy\Argument; @@ -29,6 +30,24 @@ public function it_parses_money($decimal, $currency, $subunit, $result) $this->assertEquals($result, $parser->parse($decimal, new Currency($currency))->getAmount()); } + /** + * @test + */ + public function it_parses_exponential_number() + { + $currencies = $this->prophesize(Currencies::class); + + $currencies->subunitFor(Argument::allOf( + Argument::type(Currency::class), + Argument::which('getCode', 'EUR') + ))->willReturn('2'); + + $parser = new DecimalMoneyParser($currencies->reveal()); + + $value = 2.8865798640254e-15; + $this->assertInstanceOf(Money::class, $parser->parse((string)$value, new Currency('EUR'))); + } + /** * @dataProvider invalidMoneyExamples * @test @@ -51,7 +70,8 @@ public function it_throws_an_exception_upon_invalid_inputs($input) /** * @group legacy - * @expectedDeprecation Passing a currency as string is deprecated since 3.1 and will be removed in 4.0. Please pass a Money\Currency instance instead. + * @expectedDeprecation Passing a currency as string is deprecated since 3.1 and will be removed in 4.0. Please + * pass a Money\Currency instance instead. * @test */ public function it_accepts_only_a_currency_object()