50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Sms;
|
|
|
|
use App\Sms\Provider\KavehNegarProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\NullLogger;
|
|
use Symfony\Component\HttpClient\MockHttpClient;
|
|
use Symfony\Component\HttpClient\Response\MockResponse;
|
|
|
|
/**
|
|
* الزام: همهی درخواستهای کاوهنگار باید GET با query باشند (مطابق مستند رسمی)،
|
|
* هرگز POST/body — GET بدنه ندارد پس Expect: 100-continue و idle timeout رخ نمیدهد.
|
|
*/
|
|
class KavehNegarProviderTest extends TestCase
|
|
{
|
|
/** @var array<string,mixed> */
|
|
private array $captured = [];
|
|
|
|
private function provider(): KavehNegarProvider
|
|
{
|
|
$client = new MockHttpClient(function (string $method, string $url, array $options): MockResponse {
|
|
$this->captured = ['method' => $method, 'url' => $url];
|
|
return new MockResponse(json_encode(['return' => ['status' => 200]]));
|
|
});
|
|
|
|
return new KavehNegarProvider($client, new NullLogger(), 'TESTKEY', '10004346');
|
|
}
|
|
|
|
public function testSendTemplateUsesGetWithQuery(): void
|
|
{
|
|
$ok = $this->provider()->sendTemplate('09120671756', 'clinicpro-otp', ['token' => '1234']);
|
|
|
|
$this->assertTrue($ok);
|
|
$this->assertSame('GET', $this->captured['method']);
|
|
$this->assertStringContainsString('/TESTKEY/verify/lookup.json', $this->captured['url']);
|
|
$this->assertStringContainsString('receptor=09120671756', $this->captured['url']);
|
|
$this->assertStringContainsString('template=clinicpro-otp', $this->captured['url']);
|
|
$this->assertStringContainsString('token=1234', $this->captured['url']);
|
|
}
|
|
|
|
public function testSendUsesGetNotPost(): void
|
|
{
|
|
$this->provider()->send('09120671756', 'hello');
|
|
|
|
$this->assertSame('GET', $this->captured['method']);
|
|
$this->assertStringContainsString('/TESTKEY/sms/send.json', $this->captured['url']);
|
|
}
|
|
}
|