Add SMS bulk delay configuration and validate coupon phone function
This commit is contained in:
72
tests/Unit/SmsMessageAnalyzerTest.php
Normal file
72
tests/Unit/SmsMessageAnalyzerTest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\SmsMessageAnalyzer;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SmsMessageAnalyzerTest extends TestCase
|
||||
{
|
||||
private SmsMessageAnalyzer $analyzer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->analyzer = new SmsMessageAnalyzer;
|
||||
}
|
||||
|
||||
public function test_empty_message_has_zero_parts(): void
|
||||
{
|
||||
$this->assertSame(0, $this->analyzer->estimatedParts(''));
|
||||
}
|
||||
|
||||
public function test_gsm_single_part_message(): void
|
||||
{
|
||||
$message = str_repeat('A', 160);
|
||||
|
||||
$this->assertTrue($this->analyzer->isGsm7($message));
|
||||
$this->assertSame(1, $this->analyzer->estimatedParts($message));
|
||||
}
|
||||
|
||||
public function test_gsm_multi_part_message(): void
|
||||
{
|
||||
$message = str_repeat('A', 161);
|
||||
|
||||
$this->assertSame(2, $this->analyzer->estimatedParts($message));
|
||||
}
|
||||
|
||||
public function test_unicode_single_part_message(): void
|
||||
{
|
||||
$message = 'Привет';
|
||||
|
||||
$this->assertFalse($this->analyzer->isGsm7($message));
|
||||
$this->assertSame(1, $this->analyzer->estimatedParts($message));
|
||||
}
|
||||
|
||||
public function test_unicode_multi_part_message(): void
|
||||
{
|
||||
$message = str_repeat('Я', 71);
|
||||
|
||||
$this->assertSame(2, $this->analyzer->estimatedParts($message));
|
||||
}
|
||||
|
||||
#[DataProvider('summaryProvider')]
|
||||
public function test_summary(string $message, string $expectedSubstring): void
|
||||
{
|
||||
$this->assertStringContainsString($expectedSubstring, $this->analyzer->summary($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string}>
|
||||
*/
|
||||
public static function summaryProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty' => ['', '0 characters'],
|
||||
'gsm' => ['Hello', '5 characters · 1 SMS'],
|
||||
'unicode' => ['你好', '2 characters · 1 SMS'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user