feat(payments): filter candidates by DNI distance

This commit is contained in:
2026-08-27 16:04:12 -03:00
parent 5601285369
commit 9bca41bfa5
7 changed files with 251 additions and 21 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace Tests\Unit\Purchase;
use App\Domains\Purchase\Services\DniDistanceService;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DniDistanceServiceTest extends TestCase
{
/** @return iterable<string, array{string, string, int}> */
public static function distances(): iterable
{
yield 'exact' => ['40123456', '40123456', 0];
yield 'leading transposition' => ['40123456', '04123456', 1];
yield 'trailing transposition' => ['40123456', '40123465', 1];
yield 'single substitution' => ['40123456', '40123856', 1];
yield 'substitution and transposition' => ['12345678', '12345087', 2];
yield 'seven digits normalized with leading zero' => ['04123456', '4123456', 0];
yield 'more than two edits' => ['40123456', '87654321', 7];
}
#[DataProvider('distances')]
public function test_it_calculates_damerau_levenshtein_distance(
string $left,
string $right,
int $expected,
): void {
$this->assertSame($expected, (new DniDistanceService)->distance($left, $right));
}
}