-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Exchange): support more rates, middle, buy and sell
- Loading branch information
Showing
8 changed files
with
224 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace h4kuna\Exchange; | ||
|
||
use h4kuna\Exchange\Currency\Property; | ||
|
||
/** | ||
* become enum | ||
*/ | ||
final class Rate | ||
{ | ||
/** @see Property::$rate */ | ||
public const Middle = 'rate'; | ||
/** @see Property::$rateSell */ | ||
public const Sell = 'rateSell'; | ||
/** @see Property::$rateBuy */ | ||
public const Buy = 'rateBuy'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace h4kuna\Exchange\Fixtures; | ||
|
||
use DateTimeImmutable; | ||
use h4kuna\Exchange\Currency\Property; | ||
use h4kuna\Exchange\RatingList\CacheEntity; | ||
use h4kuna\Exchange\RatingList\RatingListInterface; | ||
|
||
final class RatingListOffline implements RatingListInterface | ||
{ | ||
/** @var array<string, Property> */ | ||
private array $properties; | ||
|
||
|
||
public function __construct(array $properties = null) | ||
{ | ||
$this->properties = $properties ?? [ | ||
'CZK' => new Property(1,1, 'CZK'), | ||
'EUR' => new Property(1,22, 'EUR', 25, 20), | ||
]; | ||
} | ||
|
||
|
||
public function modify(CacheEntity $cacheEntity): RatingListInterface | ||
{ | ||
return $this; | ||
} | ||
|
||
|
||
public function get(string $code): Property | ||
{ | ||
return $this->properties[$code]; | ||
} | ||
|
||
|
||
public function all(): array | ||
{ | ||
return array_keys($this->properties); | ||
} | ||
|
||
|
||
public function getDate(): DateTimeImmutable | ||
{ | ||
return new DateTimeImmutable(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace h4kuna\Exchange\Tests\Currency; | ||
|
||
use Closure; | ||
use h4kuna\Exchange\Currency\Property; | ||
use Tester\Assert; | ||
use Tester\TestCase; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
final class PropertyTest extends TestCase | ||
{ | ||
/** | ||
* @return array<string|int, array{0: Closure(static):void}> | ||
*/ | ||
public function data(): array | ||
{ | ||
return [ | ||
[ | ||
function (self $self) { | ||
$self->assert( | ||
property: new Property(10, 23.0, 'EUR'), | ||
rate: 2.3, | ||
rateSell: 2.3, | ||
rateBuy: 2.3, | ||
); | ||
}, | ||
], | ||
[ | ||
function (self $self) { | ||
$self->assert( | ||
property: new Property(0, 23.0, 'EUR'), | ||
rate: 0.0, | ||
rateSell: 0.0, | ||
rateBuy: 0.0, | ||
); | ||
}, | ||
], | ||
[ | ||
function (self $self) { | ||
$self->assert( | ||
property: new Property(0, 23.0, 'EUR', 23.1, 22.9), | ||
rate: 0.0, | ||
rateSell: 0.0, | ||
rateBuy: 0.0, | ||
); | ||
}, | ||
], | ||
[ | ||
function (self $self) { | ||
$self->assert( | ||
property: new Property(10, 23.0, 'EUR', 23.1, 22.9), | ||
rate: 2.3, | ||
rateSell: 2.31, | ||
rateBuy: 2.29, | ||
); | ||
}, | ||
], | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* @param Closure(static):void $assert | ||
* @dataProvider data | ||
*/ | ||
public function testBasic(Closure $assert): void | ||
{ | ||
$assert($this); | ||
} | ||
|
||
|
||
public function assert( | ||
Property $property, | ||
float $rate, | ||
float $rateSell, | ||
float $rateBuy, | ||
): void | ||
{ | ||
Assert::same($rate, $property->rate); | ||
Assert::same($rateSell, $property->rateSell); | ||
Assert::same($rateBuy, $property->rateBuy); | ||
} | ||
} | ||
|
||
(new PropertyTest())->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters