39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Services\External\Yandex360BalanceProvider;
|
||
|
|
use App\Services\External\Yandex360BalanceStore;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
uses(TestCase::class);
|
||
|
|
|
||
|
|
/** Стаб хранилища ручного баланса. */
|
||
|
|
function balanceStoreReturning(?float $balance): Yandex360BalanceStore
|
||
|
|
{
|
||
|
|
return new class($balance) extends Yandex360BalanceStore
|
||
|
|
{
|
||
|
|
public function __construct(private ?float $b) {}
|
||
|
|
|
||
|
|
public function get(): ?float
|
||
|
|
{
|
||
|
|
return $this->b;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
it('ok при заданном балансе', function () {
|
||
|
|
$p = new Yandex360BalanceProvider(balanceStoreReturning(1464.31));
|
||
|
|
$r = $p->fetch();
|
||
|
|
expect($r->serviceKey)->toBe('email');
|
||
|
|
expect($r->ok)->toBeTrue();
|
||
|
|
expect($r->balance)->toBe(1464.31);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('fail, когда баланс не задан', function () {
|
||
|
|
$p = new Yandex360BalanceProvider(balanceStoreReturning(null));
|
||
|
|
$r = $p->fetch();
|
||
|
|
expect($r->ok)->toBeFalse();
|
||
|
|
expect($r->error)->toContain('не задан');
|
||
|
|
});
|