From adb795e984995e2591832730e4ad99131e963ca4 Mon Sep 17 00:00:00 2001 From: liquetsoft <49859130+liquetsoft@users.noreply.github.com> Date: Wed, 7 Dec 2022 23:05:47 +0100 Subject: [PATCH] Item interfaces (#28) * Add Rate and ItemWithDate interfaces * Add dv method * Run new fixer --- README.md | 8 ++ docker/php/Dockerfile | 2 +- src/CbrfDaily.php | 145 ++++++++++++--------- src/CbrfSoapService.php | 13 +- src/DataHelper.php | 19 ++- src/Entity/CurrencyRate.php | 9 +- src/Entity/DepoRate.php | 7 +- src/Entity/Dv.php | 73 +++++++++++ src/Entity/InternationalReserve.php | 15 +-- src/Entity/InternationalReserveWeek.php | 15 +-- src/Entity/ItemWithDate.php | 13 ++ src/Entity/KeyRate.php | 7 +- src/Entity/Mkr.php | 7 +- src/Entity/OstatDepoRate.php | 7 +- src/Entity/OstatRate.php | 11 +- src/Entity/PreciousMetalRate.php | 15 +-- src/Entity/Rate.php | 13 ++ src/Entity/ReutersCurrencyRate.php | 10 +- src/Entity/RuoniaBid.php | 19 ++- src/Entity/RuoniaIndex.php | 7 +- src/Entity/Saldo.php | 15 +-- src/Entity/SwapRate.php | 9 +- tests/BaseTestCase.php | 22 ++-- tests/CbrfDailyTest.php | 163 +++++++++++++++--------- tests/CbrfSoapServiceTest.php | 16 +-- tests/DataHelperTest.php | 131 +++++++++---------- 26 files changed, 461 insertions(+), 310 deletions(-) create mode 100644 src/Entity/Dv.php create mode 100644 src/Entity/ItemWithDate.php create mode 100644 src/Entity/Rate.php diff --git a/README.md b/README.md index bdd5b84..8af0e95 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,14 @@ $mkr = $cbrf->mkr( ); ``` +```php +//получаем требования Банка России к кредитным организациям +$dv = $cbrf->dv( + new \DateTimeImmutable('-1 month'), + new \DateTimeImmutable() +); +``` + В случае, если необходимо передать сконфигурированный заранее транспорт, например для использования proxy: ```php diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 7cbef9c..5ab3f71 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -24,7 +24,7 @@ RUN docker-php-ext-install zip soap \ && echo 'xdebug.mode=coverage' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.3.7 \ +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.4.4 \ && mkdir -p /.composer && chmod -Rf 777 /.composer diff --git a/src/CbrfDaily.php b/src/CbrfDaily.php index 3471cc0..7cd758c 100644 --- a/src/CbrfDaily.php +++ b/src/CbrfDaily.php @@ -4,10 +4,10 @@ namespace Liquetsoft\CbrfService; -use DateTimeInterface; use Liquetsoft\CbrfService\Entity\CurrencyEnum; use Liquetsoft\CbrfService\Entity\CurrencyRate; use Liquetsoft\CbrfService\Entity\DepoRate; +use Liquetsoft\CbrfService\Entity\Dv; use Liquetsoft\CbrfService\Entity\InternationalReserve; use Liquetsoft\CbrfService\Entity\InternationalReserveWeek; use Liquetsoft\CbrfService\Entity\KeyRate; @@ -20,7 +20,6 @@ use Liquetsoft\CbrfService\Entity\RuoniaIndex; use Liquetsoft\CbrfService\Entity\Saldo; use Liquetsoft\CbrfService\Entity\SwapRate; -use SoapClient; /** * Class for a daily cb RF service. @@ -30,7 +29,7 @@ class CbrfDaily private CbrfSoapService $soapClient; /** - * @param SoapClient|string $client + * @param \SoapClient|string $client */ public function __construct($client = CbrfSoapService::DEFAULT_WSDL) { @@ -40,13 +39,13 @@ public function __construct($client = CbrfSoapService::DEFAULT_WSDL) /** * Returns list of rates for all currencies for set date. * - * @param DateTimeInterface $onDate + * @param \DateTimeInterface $onDate * * @return CurrencyRate[] * * @throws CbrfException */ - public function getCursOnDate(DateTimeInterface $date): array + public function getCursOnDate(\DateTimeInterface $date): array { $soapResult = $this->soapClient->query( 'GetCursOnDate', @@ -65,14 +64,14 @@ public function getCursOnDate(DateTimeInterface $date): array /** * Returns rate for currency with set char code. * - * @param DateTimeInterface $onDate - * @param string $charCode + * @param \DateTimeInterface $onDate + * @param string $charCode * * @return CurrencyRate|null * * @throws CbrfException */ - public function getCursOnDateByCharCode(DateTimeInterface $date, string $charCode): ?CurrencyRate + public function getCursOnDateByCharCode(\DateTimeInterface $date, string $charCode): ?CurrencyRate { $list = $this->getCursOnDate($date); @@ -90,14 +89,14 @@ public function getCursOnDateByCharCode(DateTimeInterface $date, string $charCod /** * Returns rate for currency with set numeric code. * - * @param DateTimeInterface $onDate - * @param int $numericCode + * @param \DateTimeInterface $onDate + * @param int $numericCode * * @return CurrencyRate|null * * @throws CbrfException */ - public function getCursOnDateByNumericCode(DateTimeInterface $date, int $numericCode): ?CurrencyRate + public function getCursOnDateByNumericCode(\DateTimeInterface $date, int $numericCode): ?CurrencyRate { $list = $this->getCursOnDate($date); @@ -191,11 +190,11 @@ public function enumValuteByNumericCode(int $numericCode, bool $seld = false): ? * * @param string $format * - * @return DateTimeInterface + * @return \DateTimeInterface * * @throws CbrfException */ - public function getLatestDateTime(): DateTimeInterface + public function getLatestDateTime(): \DateTimeInterface { $soapResult = $this->soapClient->query('GetLatestDateTime'); @@ -207,11 +206,11 @@ public function getLatestDateTime(): DateTimeInterface * * @param string $format * - * @return DateTimeInterface + * @return \DateTimeInterface * * @throws CbrfException */ - public function getLatestDateTimeSeld(): DateTimeInterface + public function getLatestDateTimeSeld(): \DateTimeInterface { $soapResult = $this->soapClient->query('GetLatestDateTimeSeld'); @@ -223,11 +222,11 @@ public function getLatestDateTimeSeld(): DateTimeInterface * * @param string $format * - * @return DateTimeInterface + * @return \DateTimeInterface * * @throws CbrfException */ - public function getLatestDate(): DateTimeInterface + public function getLatestDate(): \DateTimeInterface { $soapResult = $this->soapClient->query('GetLatestDate'); @@ -239,11 +238,11 @@ public function getLatestDate(): DateTimeInterface * * @param string $format * - * @return DateTimeInterface + * @return \DateTimeInterface * * @throws CbrfException */ - public function getLatestDateSeld(): DateTimeInterface + public function getLatestDateSeld(): \DateTimeInterface { $soapResult = $this->soapClient->query('GetLatestDateSeld'); @@ -253,13 +252,13 @@ public function getLatestDateSeld(): DateTimeInterface /** * Returns rate dynamic for set currency within set dates. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to - * @param CurrencyEnum $currency + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to + * @param CurrencyEnum $currency * * @return CurrencyRate[] */ - public function getCursDynamic(DateTimeInterface $from, DateTimeInterface $to, CurrencyEnum $currency): array + public function getCursDynamic(\DateTimeInterface $from, \DateTimeInterface $to, CurrencyEnum $currency): array { $soapResult = $this->soapClient->query( 'GetCursDynamic', @@ -286,12 +285,12 @@ public function getCursDynamic(DateTimeInterface $from, DateTimeInterface $to, C /** * Returns key rate dynamic within set dates. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return KeyRate[] */ - public function keyRate(DateTimeInterface $from, DateTimeInterface $to): array + public function keyRate(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'KeyRate', @@ -310,12 +309,12 @@ public function keyRate(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns list of presious metals prices within set dates. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return PreciousMetalRate[] */ - public function dragMetDynamic(DateTimeInterface $from, DateTimeInterface $to): array + public function dragMetDynamic(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'DragMetDynamic', @@ -334,12 +333,12 @@ public function dragMetDynamic(DateTimeInterface $from, DateTimeInterface $to): /** * Returns list of swap rates within set dates. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return SwapRate[] */ - public function swapDynamic(DateTimeInterface $from, DateTimeInterface $to): array + public function swapDynamic(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'SwapDynamic', @@ -358,12 +357,12 @@ public function swapDynamic(DateTimeInterface $from, DateTimeInterface $to): arr /** * Returns list depo dynamic items within set dates. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return DepoRate[] */ - public function depoDynamic(DateTimeInterface $from, DateTimeInterface $to): array + public function depoDynamic(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'DepoDynamic', @@ -382,12 +381,12 @@ public function depoDynamic(DateTimeInterface $from, DateTimeInterface $to): arr /** * Returns the dynamic of balances of funds items within set dates. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return OstatRate[] */ - public function ostatDynamic(DateTimeInterface $from, DateTimeInterface $to): array + public function ostatDynamic(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'OstatDynamic', @@ -406,12 +405,12 @@ public function ostatDynamic(DateTimeInterface $from, DateTimeInterface $to): ar /** * Returns the banks deposites at bank of Russia. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return OstatDepoRate[] */ - public function ostatDepo(DateTimeInterface $from, DateTimeInterface $to): array + public function ostatDepo(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'OstatDepo', @@ -430,12 +429,12 @@ public function ostatDepo(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns international valute reseves of Russia for month. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return InternationalReserve[] */ - public function mrrf(DateTimeInterface $from, DateTimeInterface $to): array + public function mrrf(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'mrrf', @@ -454,12 +453,12 @@ public function mrrf(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns international valute reseves of Russia for week. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return InternationalReserveWeek[] */ - public function mrrf7d(DateTimeInterface $from, DateTimeInterface $to): array + public function mrrf7d(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'mrrf7D', @@ -478,12 +477,12 @@ public function mrrf7d(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns operations saldo. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return Saldo[] */ - public function saldo(DateTimeInterface $from, DateTimeInterface $to): array + public function saldo(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'Saldo', @@ -502,12 +501,12 @@ public function saldo(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns Ruonia index. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return RuoniaIndex[] */ - public function ruoniaSV(DateTimeInterface $from, DateTimeInterface $to): array + public function ruoniaSV(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'RuoniaSV', @@ -526,12 +525,12 @@ public function ruoniaSV(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns Ruonia bid. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return RuoniaBid[] */ - public function ruonia(DateTimeInterface $from, DateTimeInterface $to): array + public function ruonia(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'Ruonia', @@ -550,12 +549,12 @@ public function ruonia(DateTimeInterface $from, DateTimeInterface $to): array /** * Returns inter banks credit market bids. * - * @param DateTimeInterface $from - * @param DateTimeInterface $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * * @return Mkr[] */ - public function mkr(DateTimeInterface $from, DateTimeInterface $to): array + public function mkr(\DateTimeInterface $from, \DateTimeInterface $to): array { $soapResult = $this->soapClient->query( 'MKR', @@ -571,16 +570,40 @@ public function mkr(DateTimeInterface $from, DateTimeInterface $to): array return array_map($callback, $list); } + /** + * Returns requirements for credit organisations. + * + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to + * + * @return Dv[] + */ + public function dv(\DateTimeInterface $from, \DateTimeInterface $to): array + { + $soapResult = $this->soapClient->query( + 'DV', + [ + 'fromDate' => $from->format(CbrfSoapService::DATE_TIME_FORMAT), + 'ToDate' => $to->format(CbrfSoapService::DATE_TIME_FORMAT), + ] + ); + + $list = DataHelper::array('DV_base.DV', $soapResult); + $callback = fn (array $item): Dv => new Dv($item); + + return array_map($callback, $list); + } + /** * Returns list of Reuters rates for all currencies for set date. * - * @param DateTimeInterface $onDate + * @param \DateTimeInterface $onDate * * @return ReutersCurrencyRate[] * * @throws CbrfException */ - public function getReutersCursOnDate(DateTimeInterface $date): array + public function getReutersCursOnDate(\DateTimeInterface $date): array { $enumSoapResults = $this->soapClient->query( 'EnumReutersValutes', diff --git a/src/CbrfSoapService.php b/src/CbrfSoapService.php index 0779a5d..35bf567 100644 --- a/src/CbrfSoapService.php +++ b/src/CbrfSoapService.php @@ -5,7 +5,6 @@ namespace Liquetsoft\CbrfService; use SoapClient; -use Throwable; /** * Class for cbrf SOAP service. @@ -17,14 +16,14 @@ class CbrfSoapService private ?string $wsdl = null; - private ?SoapClient $client = null; + private ?\SoapClient $client = null; /** - * @param SoapClient|string $client + * @param \SoapClient|string $client */ public function __construct($client) { - if ($client instanceof SoapClient) { + if ($client instanceof \SoapClient) { $this->client = $client; } else { $this->wsdl = $client; @@ -45,7 +44,7 @@ public function query(string $method, array $params = []): array { try { return $this->queryInternal($method, $params); - } catch (Throwable $e) { + } catch (\Throwable $e) { $message = sprintf("Fail on '%s': '%s'.", $method, $e->getMessage()); throw new CbrfException($message, 0, $e); } @@ -109,7 +108,7 @@ private function xml2array($xmlObject): array /** * Returns a SoapClient instance for soap requests. * - * @return SoapClient + * @return \SoapClient */ private function getSoapClient() { @@ -117,7 +116,7 @@ private function getSoapClient() return $this->client; } - $this->client = new SoapClient( + $this->client = new \SoapClient( $this->wsdl, [ 'exception' => true, diff --git a/src/DataHelper.php b/src/DataHelper.php index cab51de..d6b9974 100644 --- a/src/DataHelper.php +++ b/src/DataHelper.php @@ -6,7 +6,6 @@ use DateTimeImmutable; use DateTimeInterface; -use Throwable; /** * Helper that contains several operations for data access and converts. @@ -16,22 +15,22 @@ class DataHelper /** * Creates DateTimeImmutable from string or DateTimeInterface. * - * @param DateTimeInterface|string $date + * @param \DateTimeInterface|string $date * - * @return DateTimeImmutable + * @return \DateTimeImmutable */ - public static function createImmutableDateTime($date): DateTimeImmutable + public static function createImmutableDateTime($date): \DateTimeImmutable { try { - if ($date instanceof DateTimeInterface) { - $immutableDate = new DateTimeImmutable( + if ($date instanceof \DateTimeInterface) { + $immutableDate = new \DateTimeImmutable( $date->format(\DATE_ATOM), $date->getTimezone() ); } else { - $immutableDate = new DateTimeImmutable($date); + $immutableDate = new \DateTimeImmutable($date); } - } catch (Throwable $e) { + } catch (\Throwable $e) { throw new CbrfException($e->getMessage(), 0, $e); } @@ -66,9 +65,9 @@ public static function array(string $path, $data): array * @param string $path * @param mixed $data * - * @return DateTimeInterface + * @return \DateTimeInterface */ - public static function dateTime(string $path, $data): DateTimeInterface + public static function dateTime(string $path, $data): \DateTimeInterface { $item = self::get($path, $data); diff --git a/src/Entity/CurrencyRate.php b/src/Entity/CurrencyRate.php index 1a47336..22d222f 100644 --- a/src/Entity/CurrencyRate.php +++ b/src/Entity/CurrencyRate.php @@ -4,13 +4,12 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from GetCursOnDate method. */ -class CurrencyRate implements Currency +class CurrencyRate implements Currency, Rate { private string $charCode; @@ -22,9 +21,9 @@ class CurrencyRate implements Currency private int $nom; - private DateTimeInterface $date; + private \DateTimeInterface $date; - public function __construct(array $item, DateTimeInterface $date) + public function __construct(array $item, \DateTimeInterface $date) { $this->charCode = DataHelper::charCode('VchCode', $item, ''); $this->name = DataHelper::string('Vname', $item, ''); @@ -59,7 +58,7 @@ public function getNom(): int return $this->nom; } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/DepoRate.php b/src/Entity/DepoRate.php index d43e9ca..6e86d1a 100644 --- a/src/Entity/DepoRate.php +++ b/src/Entity/DepoRate.php @@ -4,17 +4,16 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from DepoDynamic method. */ -class DepoRate +class DepoRate implements Rate { private float $rate; - private DateTimeInterface $date; + private \DateTimeInterface $date; public function __construct(array $item) { @@ -27,7 +26,7 @@ public function getRate(): float return $this->rate; } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/Dv.php b/src/Entity/Dv.php new file mode 100644 index 0000000..e33dafc --- /dev/null +++ b/src/Entity/Dv.php @@ -0,0 +1,73 @@ +vOvern = DataHelper::float('VOvern', $item, .0); + $this->vLomb = DataHelper::float('VLomb', $item, .0); + $this->vIDay = DataHelper::float('VIDay', $item, .0); + $this->vOther = DataHelper::float('VOther', $item, .0); + $this->vGold = DataHelper::float('Vol_Gold', $item, .0); + $this->vIDate = DataHelper::dateTime('VIDate', $item); + $this->date = DataHelper::dateTime('Date', $item); + } + + public function getVOvern(): float + { + return $this->vOvern; + } + + public function getVLomb(): float + { + return $this->vLomb; + } + + public function getVIDay(): float + { + return $this->vIDay; + } + + public function getVOther(): float + { + return $this->vOther; + } + + public function getVGold(): float + { + return $this->vGold; + } + + public function getVIDate(): \DateTimeInterface + { + return $this->vIDate; + } + + public function getDate(): \DateTimeInterface + { + return $this->date; + } +} diff --git a/src/Entity/InternationalReserve.php b/src/Entity/InternationalReserve.php index 0f3d854..e2d4b02 100644 --- a/src/Entity/InternationalReserve.php +++ b/src/Entity/InternationalReserve.php @@ -4,30 +4,29 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from mrrf method. */ -class InternationalReserve +class InternationalReserve implements Rate { - private DateTimeInterface $date; + private \DateTimeInterface $date; - private float $value; + private float $rate; public function __construct(array $item) { $this->date = DataHelper::dateTime('D0', $item); - $this->value = DataHelper::float('p1', $item, .0); + $this->rate = DataHelper::float('p1', $item, .0); } - public function getValue(): float + public function getRate(): float { - return $this->value; + return $this->rate; } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/InternationalReserveWeek.php b/src/Entity/InternationalReserveWeek.php index 98ebcd8..d3ea177 100644 --- a/src/Entity/InternationalReserveWeek.php +++ b/src/Entity/InternationalReserveWeek.php @@ -4,30 +4,29 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from mrrf7d method. */ -class InternationalReserveWeek +class InternationalReserveWeek implements Rate { - private DateTimeInterface $date; + private \DateTimeInterface $date; - private float $value; + private float $rate; public function __construct(array $item) { $this->date = DataHelper::dateTime('D0', $item); - $this->value = DataHelper::float('val', $item, .0); + $this->rate = DataHelper::float('val', $item, .0); } - public function getValue(): float + public function getRate(): float { - return $this->value; + return $this->rate; } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/ItemWithDate.php b/src/Entity/ItemWithDate.php new file mode 100644 index 0000000..d31c626 --- /dev/null +++ b/src/Entity/ItemWithDate.php @@ -0,0 +1,13 @@ +rate; } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/Mkr.php b/src/Entity/Mkr.php index 55d66da..120669a 100644 --- a/src/Entity/Mkr.php +++ b/src/Entity/Mkr.php @@ -4,15 +4,14 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from mkr method. */ -class Mkr +class Mkr implements ItemWithDate { - private DateTimeInterface $date; + private \DateTimeInterface $date; private int $p1; @@ -40,7 +39,7 @@ public function __construct(array $item) $this->d360 = DataHelper::floatOrNull('d360', $item); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/OstatDepoRate.php b/src/Entity/OstatDepoRate.php index 756a986..3358121 100644 --- a/src/Entity/OstatDepoRate.php +++ b/src/Entity/OstatDepoRate.php @@ -4,19 +4,18 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from OstatDepo method. */ -class OstatDepoRate +class OstatDepoRate implements ItemWithDate { private float $days1to7 = .0; private float $total = .0; - private DateTimeInterface $date; + private \DateTimeInterface $date; public function __construct(array $item) { @@ -25,7 +24,7 @@ public function __construct(array $item) $this->total = DataHelper::float('total', $item, .0); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/OstatRate.php b/src/Entity/OstatRate.php index 2eeb6a7..519c0fb 100644 --- a/src/Entity/OstatRate.php +++ b/src/Entity/OstatRate.php @@ -4,23 +4,18 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** -<<<<<<< HEAD * DTO that represents response item from OstatDynamic method. -======= - * DTO that represents response item from GetCursOnDate method. ->>>>>>> origin/master */ -class OstatRate +class OstatRate implements ItemWithDate { private float $moscow = .0; private float $russia = .0; - private DateTimeInterface $date; + private \DateTimeInterface $date; public function __construct(array $item) { @@ -29,7 +24,7 @@ public function __construct(array $item) $this->russia = DataHelper::float('InRuss', $item, .0); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/PreciousMetalRate.php b/src/Entity/PreciousMetalRate.php index e349bda..5ca20a0 100644 --- a/src/Entity/PreciousMetalRate.php +++ b/src/Entity/PreciousMetalRate.php @@ -4,33 +4,32 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from DragMetDynamic method. */ -class PreciousMetalRate +class PreciousMetalRate implements Rate { public const CODE_GOLD = 1; public const CODE_SILVER = 2; public const CODE_PLATINUM = 3; public const CODE_PALLADIUM = 4; - private DateTimeInterface $date; + private \DateTimeInterface $date; private int $code; - private float $price; + private float $rate; public function __construct(array $item) { $this->date = DataHelper::dateTime('DateMet', $item); $this->code = DataHelper::int('CodMet', $item, 0); - $this->price = DataHelper::float('price', $item, .0); + $this->rate = DataHelper::float('price', $item, .0); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } @@ -40,8 +39,8 @@ public function getCode(): int return $this->code; } - public function getPrice(): float + public function getRate(): float { - return $this->price; + return $this->rate; } } diff --git a/src/Entity/Rate.php b/src/Entity/Rate.php new file mode 100644 index 0000000..008b26c --- /dev/null +++ b/src/Entity/Rate.php @@ -0,0 +1,13 @@ +chCode = strtoupper(trim($item['char_code'] ?? '')); $this->nameRu = trim($item['Title_ru'] ?? ''); @@ -66,7 +64,7 @@ public function getDir(): int return $this->dir; } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/RuoniaBid.php b/src/Entity/RuoniaBid.php index 9df3d08..3b78c4b 100644 --- a/src/Entity/RuoniaBid.php +++ b/src/Entity/RuoniaBid.php @@ -4,38 +4,37 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from ruonia method. */ -class RuoniaBid +class RuoniaBid implements Rate { - private DateTimeInterface $date; + private \DateTimeInterface $date; - private float $bid; + private float $rate; private float $dealsVolume; - private DateTimeInterface $dateUpdate; + private \DateTimeInterface $dateUpdate; public function __construct(array $item) { $this->date = DataHelper::dateTime('D0', $item); - $this->bid = DataHelper::float('ruo', $item, .0); + $this->rate = DataHelper::float('ruo', $item, .0); $this->dealsVolume = DataHelper::float('vol', $item, .0); $this->dateUpdate = DataHelper::dateTime('DateUpdate', $item); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } - public function getBid(): float + public function getRate(): float { - return $this->bid; + return $this->rate; } public function getDealsVolume(): float @@ -43,7 +42,7 @@ public function getDealsVolume(): float return $this->dealsVolume; } - public function getDateUpdate(): DateTimeInterface + public function getDateUpdate(): \DateTimeInterface { return $this->dateUpdate; } diff --git a/src/Entity/RuoniaIndex.php b/src/Entity/RuoniaIndex.php index f05f9c3..b852f02 100644 --- a/src/Entity/RuoniaIndex.php +++ b/src/Entity/RuoniaIndex.php @@ -4,15 +4,14 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from ruoniaSV method. */ -class RuoniaIndex +class RuoniaIndex implements ItemWithDate { - private DateTimeInterface $date; + private \DateTimeInterface $date; private float $index; @@ -31,7 +30,7 @@ public function __construct(array $item) $this->average6Month = DataHelper::float('RUONIA_AVG_6M', $item, .0); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } diff --git a/src/Entity/Saldo.php b/src/Entity/Saldo.php index 5cfe5b6..641b24d 100644 --- a/src/Entity/Saldo.php +++ b/src/Entity/Saldo.php @@ -4,31 +4,30 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** * DTO that represents response item from saldo method. */ -class Saldo +class Saldo implements Rate { - private DateTimeInterface $date; + private \DateTimeInterface $date; - private float $value; + private float $rate; public function __construct(array $item) { $this->date = DataHelper::dateTime('Dt', $item); - $this->value = DataHelper::float('DEADLINEBS', $item, .0); + $this->rate = DataHelper::float('DEADLINEBS', $item, .0); } - public function getDate(): DateTimeInterface + public function getDate(): \DateTimeInterface { return $this->date; } - public function getValue(): float + public function getRate(): float { - return $this->value; + return $this->rate; } } diff --git a/src/Entity/SwapRate.php b/src/Entity/SwapRate.php index 22f39fc..77020bf 100644 --- a/src/Entity/SwapRate.php +++ b/src/Entity/SwapRate.php @@ -4,7 +4,6 @@ namespace Liquetsoft\CbrfService\Entity; -use DateTimeInterface; use Liquetsoft\CbrfService\DataHelper; /** @@ -12,9 +11,9 @@ */ class SwapRate { - private DateTimeInterface $dateBuy; + private \DateTimeInterface $dateBuy; - private DateTimeInterface $dateSell; + private \DateTimeInterface $dateSell; private float $baseRate; @@ -34,12 +33,12 @@ public function __construct(array $item) $this->currency = DataHelper::int('Currency', $item, 0); } - public function getDateBuy(): DateTimeInterface + public function getDateBuy(): \DateTimeInterface { return $this->dateBuy; } - public function getDateSell(): DateTimeInterface + public function getDateSell(): \DateTimeInterface { return $this->dateSell; } diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 62e941a..d323c86 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -4,12 +4,8 @@ namespace Liquetsoft\CbrfService\Tests; -use DateTimeInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use RuntimeException; -use SoapClient; -use stdClass; /** * @internal @@ -21,7 +17,7 @@ abstract class BaseTestCase extends TestCase public const FIXTURE_TYPE_FLOAT = 'float'; public const FIXTURE_TYPE_DATE = 'date'; - protected function assertSameDate(DateTimeInterface $date1, DateTimeInterface $date2): void + protected function assertSameDate(\DateTimeInterface $date1, \DateTimeInterface $date2): void { $this->assertSame( $date1->getTimestamp(), @@ -35,12 +31,12 @@ protected function assertSameDate(DateTimeInterface $date1, DateTimeInterface $d * @param array|null $params * @param mixed $result * - * @return SoapClient + * @return \SoapClient */ - protected function createSoapCallMock(string $method, ?array $params, $result = null): SoapClient + protected function createSoapCallMock(string $method, ?array $params, $result = null): \SoapClient { - /** @var MockObject&SoapClient */ - $soapClient = $this->getMockBuilder(SoapClient::class) + /** @var MockObject&\SoapClient */ + $soapClient = $this->getMockBuilder(\SoapClient::class) ->disableOriginalConstructor() ->getMock(); @@ -110,7 +106,7 @@ protected function createFixtureData(array $schema, int $count = 4): array break; default: $message = sprintf("Can't recognize field type '%s'.", $type); - throw new RuntimeException($message); + throw new \RuntimeException($message); } $datum[$name] = $value; } @@ -133,7 +129,7 @@ protected function createFixtureResponse(string $xmlPath, array $data): object $arPath = explode('.any.', $xmlPath); if (\count($arPath) !== 2 || empty($arPath[0]) || empty($arPath[1])) { $message = sprintf("Incorrect XML path '%s'.", $xmlPath); - throw new RuntimeException($message); + throw new \RuntimeException($message); } [$beforeAny, $afterAny] = $arPath; @@ -156,9 +152,9 @@ protected function createFixtureResponse(string $xmlPath, array $data): object $any .= ''; $arBeforeAny = explode('.', $beforeAny); - $latest = $soapResponse = new stdClass(); + $latest = $soapResponse = new \stdClass(); foreach ($arBeforeAny as $objectNode) { - $newNode = new stdClass(); + $newNode = new \stdClass(); $latest->{$objectNode} = $newNode; $latest = $newNode; } diff --git a/tests/CbrfDailyTest.php b/tests/CbrfDailyTest.php index 711944c..475ec90 100644 --- a/tests/CbrfDailyTest.php +++ b/tests/CbrfDailyTest.php @@ -4,12 +4,12 @@ namespace Liquetsoft\CbrfService\Tests; -use DateTimeImmutable; use Liquetsoft\CbrfService\CbrfDaily; use Liquetsoft\CbrfService\CbrfSoapService; use Liquetsoft\CbrfService\Entity\CurrencyEnum; use Liquetsoft\CbrfService\Entity\CurrencyRate; use Liquetsoft\CbrfService\Entity\DepoRate; +use Liquetsoft\CbrfService\Entity\Dv; use Liquetsoft\CbrfService\Entity\InternationalReserve; use Liquetsoft\CbrfService\Entity\InternationalReserveWeek; use Liquetsoft\CbrfService\Entity\KeyRate; @@ -22,7 +22,6 @@ use Liquetsoft\CbrfService\Entity\Saldo; use Liquetsoft\CbrfService\Entity\SwapRate; use PHPUnit\Framework\MockObject\MockObject; -use stdClass; /** * @internal @@ -163,6 +162,18 @@ class CbrfDailyTest extends BaseTestCase ], 'path' => 'MKRResult.any.mkr_base.MKR', ], + 'DV' => [ + 'schema' => [ + 'Date' => self::FIXTURE_TYPE_DATE, + 'VIDate' => self::FIXTURE_TYPE_DATE, + 'VOvern' => self::FIXTURE_TYPE_FLOAT, + 'VLomb' => self::FIXTURE_TYPE_FLOAT, + 'VIDay' => self::FIXTURE_TYPE_FLOAT, + 'VOther' => self::FIXTURE_TYPE_FLOAT, + 'Vol_Gold' => self::FIXTURE_TYPE_FLOAT, + ], + 'path' => 'DVResult.any.DV_base.DV', + ], ]; /** @@ -171,7 +182,7 @@ class CbrfDailyTest extends BaseTestCase public function testGetCursOnDate(): void { [$courses, $response] = $this->createFixture(self::FIXTURES['CurrencyRate']); - $onDate = new DateTimeImmutable(); + $onDate = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'GetCursOnDate', @@ -203,7 +214,7 @@ public function testGetCursOnDateByCharCode(): void { [$courses, $response] = $this->createFixture(self::FIXTURES['CurrencyRate']); $charCode = $courses[0]['VchCode'] ?? ''; - $onDate = new DateTimeImmutable(); + $onDate = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'GetCursOnDate', @@ -227,7 +238,7 @@ public function testGetCursOnDateByNumericCode(): void { [$courses, $response] = $this->createFixture(self::FIXTURES['CurrencyRate']); $numericCode = $courses[0]['Vcode'] ?? 0; - $onDate = new DateTimeImmutable(); + $onDate = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'GetCursOnDate', @@ -329,8 +340,8 @@ public function testEnumValuteByNumericCode(): void */ public function testGetLatestDateTime(): void { - $date = new DateTimeImmutable(); - $response = new stdClass(); + $date = new \DateTimeImmutable(); + $response = new \stdClass(); $response->GetLatestDateTimeResult = $date->format(CbrfSoapService::DATE_TIME_FORMAT); $soapClient = $this->createSoapCallMock( @@ -350,8 +361,8 @@ public function testGetLatestDateTime(): void */ public function testGetLatestDateTimeSeld(): void { - $date = new DateTimeImmutable(); - $response = new stdClass(); + $date = new \DateTimeImmutable(); + $response = new \stdClass(); $response->GetLatestDateTimeSeldResult = $date->format(CbrfSoapService::DATE_TIME_FORMAT); $soapClient = $this->createSoapCallMock( @@ -371,8 +382,8 @@ public function testGetLatestDateTimeSeld(): void */ public function testGetLatestDate(): void { - $date = new DateTimeImmutable(); - $response = new stdClass(); + $date = new \DateTimeImmutable(); + $response = new \stdClass(); $response->GetLatestDateResult = $date->format(CbrfSoapService::DATE_TIME_FORMAT); $soapClient = $this->createSoapCallMock( @@ -392,8 +403,8 @@ public function testGetLatestDate(): void */ public function testGetLatestDateSeld(): void { - $date = new DateTimeImmutable(); - $response = new stdClass(); + $date = new \DateTimeImmutable(); + $response = new \stdClass(); $response->GetLatestDateSeldResult = $date->format(CbrfSoapService::DATE_TIME_FORMAT); $soapClient = $this->createSoapCallMock( @@ -414,8 +425,8 @@ public function testGetLatestDateSeld(): void public function testGetCursDynamic(): void { [$currencies, $response] = $this->createFixture(self::FIXTURES['CursDynamic']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $charCode = 'EUR'; $numericCode = 978; $name = 'Euro'; @@ -451,7 +462,7 @@ public function testGetCursDynamic(): void $this->assertSame($numericCode, $list[$key]->getNumericCode()); $this->assertSame($currency['Vcurs'], $list[$key]->getRate()); $this->assertSame($currency['Vnom'], $list[$key]->getNom()); - $this->assertSameDate(new DateTimeImmutable($currency['CursDate']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($currency['CursDate']), $list[$key]->getDate()); } } @@ -461,8 +472,8 @@ public function testGetCursDynamic(): void public function testKeyRate(): void { [$rates, $response] = $this->createFixture(self::FIXTURES['KeyRate']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'KeyRate', @@ -479,7 +490,7 @@ public function testKeyRate(): void $this->assertCount(\count($rates), $list); $this->assertContainsOnlyInstancesOf(KeyRate::class, $list); foreach ($rates as $key => $rate) { - $this->assertSameDate(new DateTimeImmutable($rate['DT']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($rate['DT']), $list[$key]->getDate()); $this->assertSame($rate['Rate'], $list[$key]->getRate()); } } @@ -490,8 +501,8 @@ public function testKeyRate(): void public function testDragMetDynamic(): void { [$metals, $response] = $this->createFixture(self::FIXTURES['DragMetDynamic']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'DragMetDynamic', @@ -508,9 +519,9 @@ public function testDragMetDynamic(): void $this->assertCount(\count($metals), $list); $this->assertContainsOnlyInstancesOf(PreciousMetalRate::class, $list); foreach ($metals as $key => $metal) { - $this->assertSameDate(new DateTimeImmutable($metal['DateMet']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($metal['DateMet']), $list[$key]->getDate()); $this->assertSame($metal['CodMet'], $list[$key]->getCode()); - $this->assertSame($metal['price'], $list[$key]->getPrice()); + $this->assertSame($metal['price'], $list[$key]->getRate()); } } @@ -520,8 +531,8 @@ public function testDragMetDynamic(): void public function testSwapDynamic(): void { [$swaps, $response] = $this->createFixture(self::FIXTURES['SwapDynamic']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'SwapDynamic', @@ -538,8 +549,8 @@ public function testSwapDynamic(): void $this->assertCount(\count($swaps), $list); $this->assertContainsOnlyInstancesOf(SwapRate::class, $list); foreach ($swaps as $key => $swap) { - $this->assertSameDate(new DateTimeImmutable($swap['DateBuy']), $list[$key]->getDateBuy()); - $this->assertSameDate(new DateTimeImmutable($swap['DateSell']), $list[$key]->getDateSell()); + $this->assertSameDate(new \DateTimeImmutable($swap['DateBuy']), $list[$key]->getDateBuy()); + $this->assertSameDate(new \DateTimeImmutable($swap['DateSell']), $list[$key]->getDateSell()); $this->assertSame($swap['BaseRate'], $list[$key]->getBaseRate()); $this->assertSame($swap['TIR'], $list[$key]->getTIR()); $this->assertSame($swap['Stavka'], $list[$key]->getRate()); @@ -553,8 +564,8 @@ public function testSwapDynamic(): void public function testDepoDynamic(): void { [$depos, $response] = $this->createFixture(self::FIXTURES['DepoDynamic']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'DepoDynamic', @@ -571,7 +582,7 @@ public function testDepoDynamic(): void $this->assertCount(\count($depos), $list); $this->assertContainsOnlyInstancesOf(DepoRate::class, $list); foreach ($depos as $key => $depo) { - $this->assertSameDate(new DateTimeImmutable($depo['DateDepo']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($depo['DateDepo']), $list[$key]->getDate()); $this->assertSame($depo['Overnight'], $list[$key]->getRate()); } } @@ -582,8 +593,8 @@ public function testDepoDynamic(): void public function testOstatDynamic(): void { [$depos, $response] = $this->createFixture(self::FIXTURES['OstatDynamic']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'OstatDynamic', @@ -600,7 +611,7 @@ public function testOstatDynamic(): void $this->assertCount(\count($depos), $list); $this->assertContainsOnlyInstancesOf(OstatRate::class, $list); foreach ($depos as $key => $ostat) { - $this->assertSameDate(new DateTimeImmutable($ostat['DateOst']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($ostat['DateOst']), $list[$key]->getDate()); $this->assertSame($ostat['InMoscow'], $list[$key]->getMoscow()); $this->assertSame($ostat['InRuss'], $list[$key]->getRussia()); } @@ -612,8 +623,8 @@ public function testOstatDynamic(): void public function testOstatDepo(): void { [$depos, $response] = $this->createFixture(self::FIXTURES['OstatDepo']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'OstatDepo', @@ -630,7 +641,7 @@ public function testOstatDepo(): void $this->assertCount(\count($depos), $list); $this->assertContainsOnlyInstancesOf(OstatDepoRate::class, $list); foreach ($depos as $key => $ostat) { - $this->assertSameDate(new DateTimeImmutable($ostat['D0']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($ostat['D0']), $list[$key]->getDate()); $this->assertSame($ostat['D1_7'], $list[$key]->getDays1to7()); $this->assertSame($ostat['total'], $list[$key]->getTotal()); } @@ -642,8 +653,8 @@ public function testOstatDepo(): void public function testMrrf(): void { [$mrrfs, $response] = $this->createFixture(self::FIXTURES['Mrrf']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'mrrf', @@ -660,8 +671,8 @@ public function testMrrf(): void $this->assertCount(\count($mrrfs), $list); $this->assertContainsOnlyInstancesOf(InternationalReserve::class, $list); foreach ($mrrfs as $key => $mrrf) { - $this->assertSameDate(new DateTimeImmutable($mrrf['D0']), $list[$key]->getDate()); - $this->assertSame($mrrf['p1'], $list[$key]->getValue()); + $this->assertSameDate(new \DateTimeImmutable($mrrf['D0']), $list[$key]->getDate()); + $this->assertSame($mrrf['p1'], $list[$key]->getRate()); } } @@ -671,8 +682,8 @@ public function testMrrf(): void public function testMrrf7d(): void { [$mrrfs, $response] = $this->createFixture(self::FIXTURES['Mrrf7D']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'mrrf7D', @@ -689,8 +700,8 @@ public function testMrrf7d(): void $this->assertCount(\count($mrrfs), $list); $this->assertContainsOnlyInstancesOf(InternationalReserveWeek::class, $list); foreach ($mrrfs as $key => $mrrf) { - $this->assertSameDate(new DateTimeImmutable($mrrf['D0']), $list[$key]->getDate()); - $this->assertSame($mrrf['val'], $list[$key]->getValue()); + $this->assertSameDate(new \DateTimeImmutable($mrrf['D0']), $list[$key]->getDate()); + $this->assertSame($mrrf['val'], $list[$key]->getRate()); } } @@ -700,8 +711,8 @@ public function testMrrf7d(): void public function testSaldo(): void { [$saldos, $response] = $this->createFixture(self::FIXTURES['Saldo']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'Saldo', @@ -718,8 +729,8 @@ public function testSaldo(): void $this->assertCount(\count($saldos), $list); $this->assertContainsOnlyInstancesOf(Saldo::class, $list); foreach ($saldos as $key => $saldo) { - $this->assertSameDate(new DateTimeImmutable($saldo['Dt']), $list[$key]->getDate()); - $this->assertSame($saldo['DEADLINEBS'], $list[$key]->getValue()); + $this->assertSameDate(new \DateTimeImmutable($saldo['Dt']), $list[$key]->getDate()); + $this->assertSame($saldo['DEADLINEBS'], $list[$key]->getRate()); } } @@ -729,8 +740,8 @@ public function testSaldo(): void public function testRuoniaSV(): void { [$ruoniaIndexes, $response] = $this->createFixture(self::FIXTURES['RuoniaSV']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'RuoniaSV', @@ -747,7 +758,7 @@ public function testRuoniaSV(): void $this->assertCount(\count($ruoniaIndexes), $list); $this->assertContainsOnlyInstancesOf(RuoniaIndex::class, $list); foreach ($ruoniaIndexes as $key => $ruoniaIndex) { - $this->assertSameDate(new DateTimeImmutable($ruoniaIndex['DT']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($ruoniaIndex['DT']), $list[$key]->getDate()); $this->assertSame($ruoniaIndex['RUONIA_Index'], $list[$key]->getIndex()); $this->assertSame($ruoniaIndex['RUONIA_AVG_1M'], $list[$key]->getAverage1Month()); $this->assertSame($ruoniaIndex['RUONIA_AVG_3M'], $list[$key]->getAverage3Month()); @@ -761,8 +772,8 @@ public function testRuoniaSV(): void public function testMKR(): void { [$mkrs, $response] = $this->createFixture(self::FIXTURES['MKR']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'MKR', @@ -779,7 +790,7 @@ public function testMKR(): void $this->assertCount(\count($mkrs), $list); $this->assertContainsOnlyInstancesOf(Mkr::class, $list); foreach ($mkrs as $key => $mkr) { - $this->assertSameDate(new DateTimeImmutable($mkr['CDate']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($mkr['CDate']), $list[$key]->getDate()); $this->assertSame($mkr['p1'], $list[$key]->getP1()); $this->assertSame($mkr['d1'], $list[$key]->getD1()); $this->assertSame($mkr['d7'], $list[$key]->getD7()); @@ -789,14 +800,48 @@ public function testMKR(): void } } + /** + * @test + */ + public function testDV(): void + { + [$dvs, $response] = $this->createFixture(self::FIXTURES['DV']); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); + + $soapClient = $this->createSoapCallMock( + 'DV', + [ + 'fromDate' => $from->format(CbrfSoapService::DATE_TIME_FORMAT), + 'ToDate' => $to->format(CbrfSoapService::DATE_TIME_FORMAT), + ], + $response + ); + + $service = new CbrfDaily($soapClient); + $list = $service->dv($from, $to); + + $this->assertCount(\count($dvs), $list); + $this->assertContainsOnlyInstancesOf(Dv::class, $list); + foreach ($dvs as $key => $dv) { + $this->assertSameDate(new \DateTimeImmutable($dv['Date']), $list[$key]->getDate()); + $this->assertSameDate(new \DateTimeImmutable($dv['VIDate']), $list[$key]->getVIDate()); + $this->assertSame($dv['VOvern'], $list[$key]->getVOvern()); + $this->assertSame($dv['VLomb'], $list[$key]->getVLomb()); + $this->assertSame($dv['VIDay'], $list[$key]->getVIDay()); + $this->assertSame($dv['VOther'], $list[$key]->getVOther()); + $this->assertSame($dv['Vol_Gold'], $list[$key]->getVGold()); + } + } + /** * @test */ public function testRuonia(): void { [$ruoniaBids, $response] = $this->createFixture(self::FIXTURES['Ruonia']); - $from = new DateTimeImmutable('-1 month'); - $to = new DateTimeImmutable(); + $from = new \DateTimeImmutable('-1 month'); + $to = new \DateTimeImmutable(); $soapClient = $this->createSoapCallMock( 'Ruonia', @@ -813,10 +858,10 @@ public function testRuonia(): void $this->assertCount(\count($ruoniaBids), $list); $this->assertContainsOnlyInstancesOf(RuoniaBid::class, $list); foreach ($ruoniaBids as $key => $ruoniaBid) { - $this->assertSameDate(new DateTimeImmutable($ruoniaBid['D0']), $list[$key]->getDate()); - $this->assertSame($ruoniaBid['ruo'], $list[$key]->getBid()); + $this->assertSameDate(new \DateTimeImmutable($ruoniaBid['D0']), $list[$key]->getDate()); + $this->assertSame($ruoniaBid['ruo'], $list[$key]->getRate()); $this->assertSame($ruoniaBid['vol'], $list[$key]->getDealsVolume()); - $this->assertSameDate(new DateTimeImmutable($ruoniaBid['DateUpdate']), $list[$key]->getDateUpdate()); + $this->assertSameDate(new \DateTimeImmutable($ruoniaBid['DateUpdate']), $list[$key]->getDateUpdate()); } } } diff --git a/tests/CbrfSoapServiceTest.php b/tests/CbrfSoapServiceTest.php index e5b6226..9662ac9 100644 --- a/tests/CbrfSoapServiceTest.php +++ b/tests/CbrfSoapServiceTest.php @@ -4,11 +4,8 @@ namespace Liquetsoft\CbrfService\Tests; -use Exception; use Liquetsoft\CbrfService\CbrfException; use Liquetsoft\CbrfService\CbrfSoapService; -use SoapClient; -use stdClass; /** * @internal @@ -17,11 +14,12 @@ class CbrfSoapServiceTest extends BaseTestCase { /** * @test + * * @dataProvider queryProvider */ public function testQueryXmlResult(string $method, array $params, object $responseXml, array $response): void { - $soapClient = $this->getMockBuilder(SoapClient::class) + $soapClient = $this->getMockBuilder(\SoapClient::class) ->disableOriginalConstructor() ->getMock(); $soapClient->method('__soapCall') @@ -39,13 +37,13 @@ public function testQueryXmlResult(string $method, array $params, object $respon public function queryProvider(): array { - $responseXml = new stdClass(); - $responseXml->TestSoapAnyXmlResult = new stdClass(); + $responseXml = new \stdClass(); + $responseXml->TestSoapAnyXmlResult = new \stdClass(); $responseXml->TestSoapAnyXmlResult->any = ''; $responseXml->TestSoapAnyXmlResult->any .= 'value'; $responseXml->TestSoapAnyXmlResult->any .= ''; - $regularResponse = new stdClass(); + $regularResponse = new \stdClass(); $regularResponse->test = 'value'; return [ @@ -79,12 +77,12 @@ public function queryProvider(): array */ public function testQueryException(): void { - $soapClient = $this->getMockBuilder(SoapClient::class) + $soapClient = $this->getMockBuilder(\SoapClient::class) ->disableOriginalConstructor() ->getMock(); $soapClient->method('__soapCall') ->with($this->equalTo('EnumValutes')) - ->will($this->throwException(new Exception())); + ->will($this->throwException(new \Exception())); $service = new CbrfSoapService($soapClient); diff --git a/tests/DataHelperTest.php b/tests/DataHelperTest.php index 0916e73..633cf70 100644 --- a/tests/DataHelperTest.php +++ b/tests/DataHelperTest.php @@ -4,13 +4,8 @@ namespace Liquetsoft\CbrfService\Tests; -use DateTimeImmutable; -use DateTimeInterface; -use DateTimeZone; use Liquetsoft\CbrfService\CbrfException; use Liquetsoft\CbrfService\DataHelper; -use stdClass; -use Throwable; /** * @internal @@ -18,30 +13,31 @@ class DataHelperTest extends BaseTestCase { /** - * @param string|DateTimeInterface $input - * @param DateTimeInterface|Throwable $result + * @param string|\DateTimeInterface $input + * @param \DateTimeInterface|\Throwable $result * * @test + * * @dataProvider createImmutableDateTimeProvider */ public function testCreateImmutableDateTime($input, $result): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } $testDateTime = DataHelper::createImmutableDateTime($input); - if ($result instanceof DateTimeInterface) { - $this->assertInstanceOf(DateTimeImmutable::class, $testDateTime); + if ($result instanceof \DateTimeInterface) { + $this->assertInstanceOf(\DateTimeImmutable::class, $testDateTime); $this->assertSameDate($result, $testDateTime); } } public function createImmutableDateTimeProvider(): array { - $dateTime = new DateTimeImmutable('-1 hour'); - $dateTimeTz = new DateTimeImmutable('+1 hour', new DateTimeZone('Asia/ShangHai')); + $dateTime = new \DateTimeImmutable('-1 hour'); + $dateTimeTz = new \DateTimeImmutable('+1 hour', new \DateTimeZone('Asia/ShangHai')); return [ 'dateTime instance' => [ @@ -64,16 +60,17 @@ public function createImmutableDateTimeProvider(): array } /** - * @param string $path - * @param mixed $input - * @param array|Throwable $result + * @param string $path + * @param mixed $input + * @param array|\Throwable $result * * @test + * * @dataProvider arrayProvider */ public function testArray(string $path, $input, $result): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } @@ -89,11 +86,11 @@ public function arrayProvider(): array $path = 'test1.test2'; $result = ['key' => 'value']; - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $result; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $result, ]; @@ -132,23 +129,24 @@ public function arrayProvider(): array } /** - * @param string $path - * @param mixed $input - * @param DateTimeInterface|Throwable $result + * @param string $path + * @param mixed $input + * @param \DateTimeInterface|\Throwable $result * * @test + * * @dataProvider dateTimeProvider */ public function testDateTime(string $path, $input, $result): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } $testDateTime = DataHelper::dateTime($path, $input); - if ($result instanceof DateTimeInterface) { - $this->assertInstanceOf(DateTimeImmutable::class, $testDateTime); + if ($result instanceof \DateTimeInterface) { + $this->assertInstanceOf(\DateTimeImmutable::class, $testDateTime); $this->assertSameDate($result, $testDateTime); } } @@ -156,14 +154,14 @@ public function testDateTime(string $path, $input, $result): void public function dateTimeProvider(): array { $path = 'test1.test2'; - $result = new DateTimeImmutable(); + $result = new \DateTimeImmutable(); $date = $result->format(\DATE_ATOM); - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $date; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $date, ]; @@ -220,17 +218,18 @@ public function dateTimeProvider(): array } /** - * @param string $path - * @param mixed $input - * @param string|Throwable $result - * @param string|null $default + * @param string $path + * @param mixed $input + * @param string|\Throwable $result + * @param string|null $default * * @test + * * @dataProvider stringProvider */ public function testString(string $path, $input, $result, ?string $default = null): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } @@ -247,11 +246,11 @@ public function stringProvider(): array $string = ' test '; $result = 'test'; - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $string; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $string, ]; @@ -296,17 +295,18 @@ public function stringProvider(): array } /** - * @param string $path - * @param mixed $input - * @param float|Throwable $result - * @param float|null $default + * @param string $path + * @param mixed $input + * @param float|\Throwable $result + * @param float|null $default * * @test + * * @dataProvider floatProvider */ public function testFloat(string $path, $input, $result, ?float $default = null): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } @@ -323,11 +323,11 @@ public function floatProvider(): array $result = 12.3; $float = '12.3'; - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $float; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $float, ]; @@ -377,6 +377,7 @@ public function floatProvider(): array * @param float|null $result * * @test + * * @dataProvider floatOrNullProvider */ public function testFloatOrNull(string $path, $input, $result): void @@ -392,11 +393,11 @@ public function floatOrNullProvider(): array $result = 12.3; $float = '12.3'; - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $float; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $float, ]; @@ -435,17 +436,18 @@ public function floatOrNullProvider(): array } /** - * @param string $path - * @param mixed $input - * @param int|Throwable $result - * @param int|null $default + * @param string $path + * @param mixed $input + * @param int|\Throwable $result + * @param int|null $default * * @test + * * @dataProvider intProvider */ public function testInt(string $path, $input, $result, ?int $default = null): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } @@ -462,11 +464,11 @@ public function intProvider(): array $result = 12; $int = '12'; - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $int; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $int, ]; @@ -511,17 +513,18 @@ public function intProvider(): array } /** - * @param string $path - * @param mixed $input - * @param string|Throwable $result - * @param string|null $default + * @param string $path + * @param mixed $input + * @param string|\Throwable $result + * @param string|null $default * * @test + * * @dataProvider charCodeProvider */ public function testCharCode(string $path, $input, $result, ?string $default = null): void { - if ($result instanceof Throwable) { + if ($result instanceof \Throwable) { $this->expectException(\get_class($result)); } @@ -538,11 +541,11 @@ public function charCodeProvider(): array $string = ' TeSt '; $result = 'TEST'; - $object = new stdClass(); - $object->test1 = new stdClass(); + $object = new \stdClass(); + $object->test1 = new \stdClass(); $object->test1->test2 = $string; - $objectMixed = new stdClass(); + $objectMixed = new \stdClass(); $objectMixed->test1 = [ 'test2' => $string, ];