mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
118 lines
3.2 KiB
PHP
Executable File
118 lines
3.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Karaka
|
|
*
|
|
* PHP Version 8.1
|
|
*
|
|
* @package tests
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\tests\Utils\Converter;
|
|
|
|
use phpOMS\Localization\ISO4217CharEnum;
|
|
use phpOMS\Message\Http\HttpRequest;
|
|
use phpOMS\Message\Http\RequestMethod;
|
|
use phpOMS\Message\Http\Rest;
|
|
use phpOMS\Uri\HttpUri;
|
|
use phpOMS\Utils\Converter\Currency;
|
|
|
|
/**
|
|
* @testdox phpOMS\tests\Utils\Converter\CurrencyTest: Currency converter
|
|
*
|
|
* @internal
|
|
*/
|
|
final class CurrencyTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
private static $reachable;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function setUp() : void
|
|
{
|
|
if (!isset(self::$reachable)) {
|
|
try {
|
|
$request = new HttpRequest(new HttpUri('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
|
|
$request->setMethod(RequestMethod::GET);
|
|
|
|
Rest::request($request)->getBody();
|
|
self::$reachable = true;
|
|
} catch (\Throwable $t) {
|
|
self::$reachable = false;
|
|
}
|
|
}
|
|
|
|
if (!self::$reachable) {
|
|
$this->markTestSkipped(
|
|
'External currency conversion not available.'
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @testdox A currency can be converted from euro to another currency
|
|
* @covers phpOMS\Utils\Converter\Currency
|
|
* @group framework
|
|
*/
|
|
public function testCurrencyFromEur() : void
|
|
{
|
|
self::assertGreaterThan(0, Currency::fromEurTo(1, ISO4217CharEnum::_USD));
|
|
}
|
|
|
|
/**
|
|
* @testdox A currency can be converted to euro from another currency
|
|
* @covers phpOMS\Utils\Converter\Currency
|
|
* @group framework
|
|
*/
|
|
public function testCurrencyToEur() : void
|
|
{
|
|
self::assertGreaterThan(0, Currency::fromToEur(1, ISO4217CharEnum::_USD));
|
|
}
|
|
|
|
/**
|
|
* @testdox A currency can be converted from one currency to another currency
|
|
* @covers phpOMS\Utils\Converter\Currency
|
|
* @group framework
|
|
*/
|
|
public function testCurrency() : void
|
|
{
|
|
Currency::resetCurrencies();
|
|
self::assertGreaterThan(0, Currency::convertCurrency(1, ISO4217CharEnum::_USD, ISO4217CharEnum::_GBP));
|
|
}
|
|
|
|
/**
|
|
* @testdox A currency conversion from eur to a invalid currency throws a InvalidArgumentException
|
|
* @covers phpOMS\Utils\Converter\Currency
|
|
* @group framework
|
|
*/
|
|
public function testInvalidFromEur() : void
|
|
{
|
|
self::assertLessThan(0, Currency::fromEurTo(1, 'ERROR'));
|
|
}
|
|
|
|
/**
|
|
* @testdox A currency conversion from a invalid currency to eur throws a InvalidArgumentException
|
|
* @covers phpOMS\Utils\Converter\Currency
|
|
* @group framework
|
|
*/
|
|
public function testInvalidToEur() : void
|
|
{
|
|
self::assertLessThan(0, Currency::fromToEur(1, 'ERROR'));
|
|
}
|
|
|
|
/**
|
|
* @testdox A currency conversion from a invalid currency to a invalid currency throws a InvalidArgumentException
|
|
* @covers phpOMS\Utils\Converter\Currency
|
|
* @group framework
|
|
*/
|
|
public function testInvalidConvert() : void
|
|
{
|
|
self::assertLessThan(0, Currency::convertCurrency(1, 'ERROR', 'TEST'));
|
|
}
|
|
}
|