300]); } function smsc_message(): SmsOutgoing { return new SmsOutgoing( phone: '79990000001', body: 'Здравствуйте!', senderName: 'liderra.ru', operator: 'МегаФон', segments: 1, ); } it('обслуживает всех как универсал', function () { expect(smsc_provider()->servesOperators())->toBe(['*']) ->and(smsc_provider()->key())->toBe('smsc'); }); it('успешная отправка возвращает id сообщения и цену по сегментам', function () { Http::fake(['smsc.ru/*' => Http::response(['id' => 555, 'cnt' => 1], 200)]); $result = smsc_provider()->send(smsc_message()); expect($result->providerMessageId)->toBe('555') ->and($result->costKopecks)->toBe(300); }); it('отказ smsc.ru бросает terminal-исключение', function () { Http::fake(['smsc.ru/*' => Http::response(['error' => 'invalid number', 'error_code' => 7], 200)]); expect(fn () => smsc_provider()->send(smsc_message())) ->toThrow(SmsSendException::class); }); it('сетевой сбой — не terminal (можно повторить)', function () { Http::fake(['smsc.ru/*' => Http::response('', 500)]); try { smsc_provider()->send(smsc_message()); $this->fail('ожидалось SmsSendException'); } catch (SmsSendException $e) { expect($e->terminal)->toBeFalse(); } });