feat(смс): точка расширения резерва канала (флаг, по умолчанию выкл)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\Sms\SmsOutgoing;
|
||||
use App\Services\Sms\SmsProvider;
|
||||
use App\Services\Sms\SmsRouter;
|
||||
use App\Services\Sms\SmsSendResult;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
function failover_provider(string $key, array $operators): SmsProvider
|
||||
{
|
||||
return new class($key, $operators) implements SmsProvider
|
||||
{
|
||||
public function __construct(private string $k, private array $ops) {}
|
||||
|
||||
public function key(): string
|
||||
{
|
||||
return $this->k;
|
||||
}
|
||||
|
||||
public function servesOperators(): array
|
||||
{
|
||||
return $this->ops;
|
||||
}
|
||||
|
||||
public function priceKopecks(string $operator): int
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
public function send(SmsOutgoing $m): SmsSendResult
|
||||
{
|
||||
return new SmsSendResult('x', 1, 100, CarbonImmutable::now());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
it('по умолчанию резерва нет — второй канал не отдаётся', function () {
|
||||
config()->set('services.sms.failover_to_universal', false);
|
||||
$router = new SmsRouter([
|
||||
failover_provider('mts', ['mts']),
|
||||
failover_provider('smsc', ['*']),
|
||||
]);
|
||||
|
||||
expect($router->fallbackFor('mts'))->toBeNull();
|
||||
});
|
||||
|
||||
it('при включённом флаге резерв — универсал', function () {
|
||||
config()->set('services.sms.failover_to_universal', true);
|
||||
$router = new SmsRouter([
|
||||
failover_provider('mts', ['mts']),
|
||||
failover_provider('smsc', ['*']),
|
||||
]);
|
||||
|
||||
expect($router->fallbackFor('mts')?->key())->toBe('smsc');
|
||||
});
|
||||
Reference in New Issue
Block a user