fix: update KavehNegarProvider to use GET requests with query parameters to resolve 431 and idle timeout errors

This commit is contained in:
hamed
2026-07-08 09:51:30 +03:30
parent 5e5455cf8c
commit 8f4f7fc951
4 changed files with 239 additions and 18 deletions
+49
View File
@@ -0,0 +1,49 @@
<?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']);
}
}