Pruebas de integracion con seeds
This commit is contained in:
38
app/tests/extension/Faker/Provider/Rut.php
Normal file
38
app/tests/extension/Faker/Provider/Rut.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Faker\Provider;
|
||||
|
||||
use Faker\Provider\Base;
|
||||
|
||||
class Rut extends Base
|
||||
{
|
||||
public function rut(bool $withDigito = true, bool $withDotsAndSlash = true): string
|
||||
{
|
||||
$base = self::numberBetween(1000000, 99999999);
|
||||
$rut = $base;
|
||||
if ($withDotsAndSlash) {
|
||||
$rut = number_format($rut, 0, ',', '.');
|
||||
}
|
||||
if ($withDigito) {
|
||||
$digito = $this->getDigito($base);
|
||||
if ($withDotsAndSlash) {
|
||||
return "{$digito}-{$rut}";
|
||||
}
|
||||
return "{$digito}{$rut}";
|
||||
}
|
||||
return $rut;
|
||||
}
|
||||
public function digitoVerificador(string $rut): bool|string
|
||||
{
|
||||
if ( !preg_match("/^[0-9.]+/",$rut)) return false;
|
||||
$rut = str_replace('.','',$rut);
|
||||
return $this->getDigito($rut);
|
||||
}
|
||||
|
||||
protected function getDigito(string $rut): string
|
||||
{
|
||||
$M=0;$S=1;
|
||||
for(;$rut;$rut=floor($rut/10))
|
||||
$S=($S+$rut%10*(9-$M++%6))%11;
|
||||
return $S?$S-1:'K';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user