Skip to content

Commit

Permalink
Merge pull request #148 from hanishsingla/master
Browse files Browse the repository at this point in the history
Symfony 7 update #146
  • Loading branch information
hanishsingla authored Dec 20, 2023
2 parents fa2bce3 + f269a8b commit 6419dd9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Tests/Entity/RatioHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
19 changes: 0 additions & 19 deletions Tests/MoneyConverterTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
26 changes: 16 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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
}
}
}
2 changes: 1 addition & 1 deletion src/Entity/DoctrineStorageRatio.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
) {
}

public function getId(): int
public function getId(): ?int
{
return $this->id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/RatioHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setId(int $id): self
return $this;
}

public function getId(): int
public function getId(): ?int
{
return $this->id;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Form/DataTransformer/CurrencyToArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Pair/RatioProvider/ECBRatioProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 exist', $currencyCode));
}

try {
$currency = new Currency($currencyCode);
} catch (UnknownCurrencyException|InvalidArgumentException) {
Expand Down

0 comments on commit 6419dd9

Please sign in to comment.