feat: update allowed frontend hosts and add clinic-pro.ir domain
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Shared;
|
||||
|
||||
use App\Shared\Controller\HealthController;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* probe سلامت redis نباید هنگام افتادن redis لاگ warning در app_log بریزد:
|
||||
* HealthController باید logger این pool را با NullLogger خنثی کند و صرفاً وضعیت را برگرداند.
|
||||
*/
|
||||
class HealthControllerTest extends TestCase
|
||||
{
|
||||
private function em(): EntityManagerInterface
|
||||
{
|
||||
$conn = $this->createMock(Connection::class);
|
||||
$conn->method('executeQuery'); // SELECT 1 → موفق
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
$em->method('getConnection')->willReturn($conn);
|
||||
|
||||
return $em;
|
||||
}
|
||||
|
||||
public function testSilencesLoggerOnPool(): void
|
||||
{
|
||||
$pool = new class implements CacheItemPoolInterface, LoggerAwareInterface {
|
||||
public ?LoggerInterface $logger = null;
|
||||
public function setLogger(LoggerInterface $logger): void { $this->logger = $logger; }
|
||||
public function getItem($key): CacheItemInterface { throw new \RuntimeException('redis down'); }
|
||||
public function getItems(array $keys = []): iterable { return []; }
|
||||
public function hasItem($key): bool { return false; }
|
||||
public function clear(): bool { return true; }
|
||||
public function deleteItem($key): bool { return true; }
|
||||
public function deleteItems(array $keys): bool { return true; }
|
||||
public function save(CacheItemInterface $item): bool { return true; }
|
||||
public function saveDeferred(CacheItemInterface $item): bool { return true; }
|
||||
public function commit(): bool { return true; }
|
||||
};
|
||||
|
||||
$controller = new HealthController($this->em(), $pool);
|
||||
|
||||
// logger فوراً در constructor خنثی میشود
|
||||
$this->assertInstanceOf(NullLogger::class, $pool->logger);
|
||||
|
||||
// redis افتاده → degraded + 503، بدون throw
|
||||
$response = $controller();
|
||||
$this->assertSame(503, $response->getStatusCode());
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$this->assertSame('degraded', $body['status']);
|
||||
$this->assertSame('error', $body['checks']['redis']);
|
||||
$this->assertSame('ok', $body['checks']['database']);
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,25 @@ class KavehNegarProviderTest extends TestCase
|
||||
$this->assertSame('GET', $this->captured['method']);
|
||||
$this->assertStringContainsString('/TESTKEY/sms/send.json', $this->captured['url']);
|
||||
}
|
||||
|
||||
/** توکن بلند (نام فارسی) باید cap شود تا URL بزرگ نشود و کاوهنگار 431 ندهد. */
|
||||
public function testLongTokenIsCapped(): void
|
||||
{
|
||||
$long = str_repeat('ک', 200); // 200 کاراکتر فارسی
|
||||
$ok = $this->provider()->sendTemplate('09120671756', 'clinicpro-welcome', ['token' => $long]);
|
||||
|
||||
$this->assertTrue($ok);
|
||||
parse_str(parse_url($this->captured['url'], PHP_URL_QUERY), $q);
|
||||
$this->assertLessThanOrEqual(60, mb_strlen($q['token'], 'UTF-8'));
|
||||
}
|
||||
|
||||
/** خطای 4xx کاوهنگار (مثل 431) باید false برگرداند و throw نکند. */
|
||||
public function testHttpErrorReturnsFalseWithoutThrowing(): void
|
||||
{
|
||||
$client = new MockHttpClient(fn (): MockResponse => new MockResponse('too large', ['http_code' => 431]));
|
||||
$provider = new KavehNegarProvider($client, new NullLogger(), 'TESTKEY', '10004346');
|
||||
|
||||
$this->assertFalse($provider->sendTemplate('09120671756', 'clinicpro-welcome', ['token' => 'x']));
|
||||
$this->assertFalse($provider->send('09120671756', 'hello'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user