Publication initiale de RelaisSMS : documentation et sources nettoyees

This commit is contained in:
2026-10-21 09:29:39 +02:00
commit ac186b03b1
158 changed files with 24818 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
<?php
namespace Tests\Feature;
use App\Models\SmsCampaign;
use App\Services\Sms\OvhSmsProvider;
use App\Services\Sms\SmsProviderException;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;
use Tests\TestCase;
class OvhSmsProviderTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
config([
'relais_sms.ovh.application_key' => 'test',
'relais_sms.ovh.application_secret' => 'test',
'relais_sms.ovh.consumer_key' => 'test',
'relais_sms.ovh.sms_service_name' => 'sms-test',
'relais_sms.ovh.sms_sender' => '',
'relais_sms.ovh.sms_short_code' => true,
'relais_sms.ovh.endpoint' => 'ovh-eu',
]);
}
public function test_short_code_strips_links_from_the_actual_signed_request(): void
{
$history = [];
$stack = HandlerStack::create(new MockHandler([new Response(200, [], '123456'), new Response(200, [], '{"ids":["1"]}')]));
$stack->push(Middleware::history($history));
$provider = new OvhSmsProvider(new Client(['handler' => $stack]));
$result = $provider->send(new SmsCampaign(['message' => 'Reunion https://zoom.us/j/123 à 10h']), [['number' => '+33611111111']]);
$payload = json_decode((string) $history[1]['request']->getBody(), true);
$this->assertSame('Reunion à 10h', $payload['message']);
$this->assertTrue($payload['senderForResponse']);
$this->assertArrayNotHasKey('sender', $payload);
$this->assertSame($payload, $result->requestPayload);
}
public function test_named_sender_preserves_links_and_does_not_request_a_short_code(): void
{
config(['relais_sms.ovh.sms_short_code' => false, 'relais_sms.ovh.sms_sender' => 'AFPMA']);
$provider = new OvhSmsProvider(new Client(['handler' => HandlerStack::create(new MockHandler([new Response(200, [], '123456'), new Response(200, [], '{"ids":["1"]}')]))]));
$result = $provider->send(new SmsCampaign(['message' => 'Reunion https://zoom.us/j/123']), [['number' => '+33611111111']]);
$this->assertSame('Reunion https://zoom.us/j/123', $result->requestPayload['message']);
$this->assertSame('AFPMA', $result->requestPayload['sender']);
$this->assertArrayNotHasKey('senderForResponse', $result->requestPayload);
}
public function test_link_only_message_is_rejected_before_any_network_request(): void
{
$this->expectException(SmsProviderException::class);
$this->expectExceptionMessage('vide apres retrait');
(new OvhSmsProvider(new Client(['handler' => HandlerStack::create(new MockHandler([]))])))->send(new SmsCampaign(['message' => 'https://zoom.us/j/123']), []);
}
public function test_disabling_short_code_requires_an_explicit_sender(): void
{
config(['relais_sms.ovh.sms_short_code' => false]);
$this->expectException(SmsProviderException::class);
$this->expectExceptionMessage('Configurer OVH_SMS_SENDER');
(new OvhSmsProvider(new Client(['handler' => HandlerStack::create(new MockHandler([]))])))->send(new SmsCampaign(['message' => 'Rappel']), []);
}
public function test_conflicting_sender_configuration_is_rejected(): void
{
config(['relais_sms.ovh.sms_sender' => 'AFPMA']);
$this->expectException(SmsProviderException::class);
$this->expectExceptionMessage('incompatible');
(new OvhSmsProvider(new Client(['handler' => HandlerStack::create(new MockHandler([]))])))->send(new SmsCampaign(['message' => 'Rappel']), []);
}
public function test_unknown_endpoint_is_not_silently_routed_to_ovh_europe(): void
{
config(['relais_sms.ovh.endpoint' => 'another-provider']);
$this->expectException(SmsProviderException::class);
$this->expectExceptionMessage('Endpoint OVH non pris en charge');
(new OvhSmsProvider(new Client(['handler' => HandlerStack::create(new MockHandler([]))])))->send(new SmsCampaign(['message' => 'Rappel']), []);
}
}