2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Str;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-03-20 20:24:24 +01:00
|
|
|
use Psl;
|
2019-12-26 23:10:57 +01:00
|
|
|
use Psl\Str;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class MetaphoneTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2019-12-26 23:10:57 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testMetaphone(?string $expected, string $str, int $phonemes = 0): void
|
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Str\metaphone($str, $phonemes));
|
2019-12-26 23:10:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['HL', 'hello'],
|
|
|
|
['HLWRLT', 'Hello, World !!', 10],
|
2019-12-26 23:10:57 +01:00
|
|
|
['PPLLNKTBTSTNWLLWSFNTX0R', 'People linked by destiny will always find each other.'],
|
2019-12-26 23:10:57 +01:00
|
|
|
['', 'سيف'],
|
|
|
|
['', '1337'],
|
|
|
|
];
|
|
|
|
}
|
2021-03-20 20:24:24 +01:00
|
|
|
|
|
|
|
public function testThrowsIfPhonemeIsNegative(): void
|
|
|
|
{
|
|
|
|
$this->expectException(Psl\Exception\InvariantViolationException::class);
|
|
|
|
$this->expectExceptionMessage('Expected non-negative phonemes, got -1.');
|
|
|
|
|
|
|
|
Str\metaphone('foo', -1);
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|