From c06b2898f074e75ca9688614a61e25aa39f4dde4 Mon Sep 17 00:00:00 2001 From: Hanish Singla Date: Wed, 22 Jun 2022 15:58:02 +0530 Subject: [PATCH 1/3] fix #141 --- src/Resources/config/services.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index dcf98be5..58029390 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -47,6 +47,7 @@ + From 0ab668fe361508a3b3d498bca9905d2a45544197 Mon Sep 17 00:00:00 2001 From: Hanish Singla Date: Wed, 20 Dec 2023 11:42:45 +0530 Subject: [PATCH 2/3] Symfony 7 update #146 --- Tests/Entity/RatioHistoryTest.php | 4 +-- Tests/MoneyConverterTest.php | 19 -------------- .../ExchangerAdapterRatioProviderTest.php | 5 +++- composer.json | 26 ++++++++++++------- src/Entity/DoctrineStorageRatio.php | 2 +- src/Entity/RatioHistory.php | 2 +- .../CurrencyToArrayTransformer.php | 4 ++- src/Pair/RatioProvider/ECBRatioProvider.php | 4 +++ 8 files changed, 31 insertions(+), 35 deletions(-) delete mode 100644 Tests/MoneyConverterTest.php diff --git a/Tests/Entity/RatioHistoryTest.php b/Tests/Entity/RatioHistoryTest.php index 8e105871..121bab3d 100644 --- a/Tests/Entity/RatioHistoryTest.php +++ b/Tests/Entity/RatioHistoryTest.php @@ -20,8 +20,8 @@ public function testProperties(): void $ratioHistory = new RatioHistory(); self::assertNull($ratioHistory->getId()); - $ratioHistory->setId('id'); - self::assertSame('id', $ratioHistory->getId()); + $ratioHistory->setId(1); + self::assertSame(1, $ratioHistory->getId()); $ratioHistory->setCurrencyCode('USD'); self::assertSame('USD', $ratioHistory->getCurrencyCode()); diff --git a/Tests/MoneyConverterTest.php b/Tests/MoneyConverterTest.php deleted file mode 100644 index 1ee47a68..00000000 --- a/Tests/MoneyConverterTest.php +++ /dev/null @@ -1,19 +0,0 @@ -expectException(MoneyException::class); - $this->expectExceptionMessage('Currency needs to be a string'); - MoneyConverter::currency(null); - } -} diff --git a/Tests/Pair/RatioProvider/ExchangerAdapterRatioProviderTest.php b/Tests/Pair/RatioProvider/ExchangerAdapterRatioProviderTest.php index 6cb13f8e..0d83749d 100644 --- a/Tests/Pair/RatioProvider/ExchangerAdapterRatioProviderTest.php +++ b/Tests/Pair/RatioProvider/ExchangerAdapterRatioProviderTest.php @@ -6,6 +6,7 @@ use Exchanger\Exchanger; use Exchanger\Service\PhpArray; +use InvalidArgumentException; use Tbbc\MoneyBundle\MoneyException; use Tbbc\MoneyBundle\Pair\RatioProvider\ExchangerAdapterRatioProvider; use Tbbc\MoneyBundle\Pair\RatioProviderInterface; @@ -31,7 +32,9 @@ protected function getRatioProvider(): RatioProviderInterface public function testInvalidCurrencyCode(): void { $this->expectException(MoneyException::class); - $this->expectExceptionMessage('The currency code "" does not exist'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The currency pair must be in the form "EUR/USD".'); + //$this->expectExceptionMessage('The currency code "" does not exist'); $ratiosSetup['EUR/123'] = $this->randomRatio(1, 3, 1); $service = new PhpArray($ratiosSetup); diff --git a/composer.json b/composer.json index 6d0c0482..1b7544c2 100644 --- a/composer.json +++ b/composer.json @@ -23,13 +23,13 @@ "ext-intl": "*", "ext-simplexml": "*", "moneyphp/money": "^3.0|^4.0", - "symfony/form": "^5.4|^6.0", - "symfony/twig-bundle": "^5.4|^6.0", - "symfony/console": "^5.4|^6.0", - "symfony/dom-crawler": "^5.4|^6.0", - "symfony/event-dispatcher": "^5.4|^6.0", - "symfony/templating": "^5.4|^6.0", - "symfony/http-client": "^5.4|^6.0" + "symfony/form": "^5.4|^6.0|^7.0", + "symfony/twig-bundle": "^5.4|^6.0|^7.0", + "symfony/console": "^5.4|^6.0|^7.0", + "symfony/dom-crawler": "^5.4|^6.0|^7.0", + "symfony/event-dispatcher": "^5.4|^6.0|^7.0", + "symfony/templating": "^5.4|^6.0|^7.0", + "symfony/http-client": "^5.4|^6.0|^7.0" }, "autoload": { "psr-4": { @@ -38,16 +38,17 @@ }, "require-dev": { "ext-sqlite3": "*", - "symfony/browser-kit": "^5.4|^6.0", + "symfony/browser-kit": "^5.4|^6.0|^7.0", "doctrine/doctrine-bundle": "^1.12|^2.0", "doctrine/orm": "^2.7|^3.0", "florianv/exchanger": "^2.0", "php-http/message": "^1.0", "php-http/guzzle6-adapter": "^2.0", "vimeo/psalm": "^4.13", - "symfony/phpunit-bridge": "^5.4 | ^6.0", + "symfony/phpunit-bridge": "^5.4|^6.0|^7.0", "phpunit/phpunit": "^9.5", - "symfony/yaml": "^5.4|^6.0" + "symfony/yaml": "^5.4|^6.0|^7.0", + "http-interop/http-factory-guzzle": "^1.2" }, "autoload-dev": { "psr-4": { @@ -65,5 +66,10 @@ "doctrine/doctrine-bundle": "~1.1", "doctrine/orm": "~2.7", "florianv/exchanger": "Exchanger is a PHP framework to work with currency exchange rates from various services." + }, + "config": { + "allow-plugins": { + "php-http/discovery": true + } } } diff --git a/src/Entity/DoctrineStorageRatio.php b/src/Entity/DoctrineStorageRatio.php index 86c37bfa..9f45fb3a 100644 --- a/src/Entity/DoctrineStorageRatio.php +++ b/src/Entity/DoctrineStorageRatio.php @@ -14,7 +14,7 @@ public function __construct( ) { } - public function getId(): int + public function getId(): ?int { return $this->id; } diff --git a/src/Entity/RatioHistory.php b/src/Entity/RatioHistory.php index d966815c..b6fc8714 100644 --- a/src/Entity/RatioHistory.php +++ b/src/Entity/RatioHistory.php @@ -27,7 +27,7 @@ public function setId(int $id): self return $this; } - public function getId(): int + public function getId(): ?int { return $this->id; } diff --git a/src/Form/DataTransformer/CurrencyToArrayTransformer.php b/src/Form/DataTransformer/CurrencyToArrayTransformer.php index 3f279337..6b3af87a 100644 --- a/src/Form/DataTransformer/CurrencyToArrayTransformer.php +++ b/src/Form/DataTransformer/CurrencyToArrayTransformer.php @@ -9,6 +9,7 @@ use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\Exception\UnexpectedTypeException; +use TypeError; /** * Transforms between a Currency and a string. @@ -48,9 +49,10 @@ public function reverseTransform($value): ?Currency if (!isset($value['tbbc_name'])) { return null; } + try { return new Currency($value['tbbc_name']); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException|TypeError $e) { throw new TransformationFailedException($e->getMessage()); } } diff --git a/src/Pair/RatioProvider/ECBRatioProvider.php b/src/Pair/RatioProvider/ECBRatioProvider.php index c7411d9c..e72977d5 100644 --- a/src/Pair/RatioProvider/ECBRatioProvider.php +++ b/src/Pair/RatioProvider/ECBRatioProvider.php @@ -50,6 +50,10 @@ public function fetchRatio(string $referenceCurrencyCode, string $currencyCode): throw new MoneyException(sprintf('The reference currency code for ECB provider must be EUR, got: "%s"', $referenceCurrencyCode)); } + if ('' === $currencyCode) { + throw new MoneyException(sprintf('The currency code "%s" does not exists', $currencyCode)); + } + try { $currency = new Currency($currencyCode); } catch (UnknownCurrencyException|InvalidArgumentException) { From f269a8bcc9d7fa83b7633381622bf5f2bc7c5257 Mon Sep 17 00:00:00 2001 From: Hanish Singla Date: Wed, 20 Dec 2023 17:19:59 +0530 Subject: [PATCH 3/3] Update src/Pair/RatioProvider/ECBRatioProvider.php Co-authored-by: Johan Wilfer --- src/Pair/RatioProvider/ECBRatioProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pair/RatioProvider/ECBRatioProvider.php b/src/Pair/RatioProvider/ECBRatioProvider.php index e72977d5..c901cba2 100644 --- a/src/Pair/RatioProvider/ECBRatioProvider.php +++ b/src/Pair/RatioProvider/ECBRatioProvider.php @@ -51,7 +51,7 @@ public function fetchRatio(string $referenceCurrencyCode, string $currencyCode): } if ('' === $currencyCode) { - throw new MoneyException(sprintf('The currency code "%s" does not exists', $currencyCode)); + throw new MoneyException(sprintf('The currency code "%s" does not exist', $currencyCode)); } try {