73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?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 harp'],
|
|
'gsm' => ['Hello', '5 harp · 1 SMS'],
|
|
'unicode' => ['你好', '2 harp · 1 SMS'],
|
|
];
|
|
}
|
|
}
|