Version 2.0.0
This commit is contained in:
56
tests/Validator/ChainRutValidatorTest.php
Normal file
56
tests/Validator/ChainRutValidatorTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the MNC\ChileanRut library.
|
||||
*
|
||||
* (c) Matías Navarro Carter <mnavarrocarter@gmail.com>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace MNC\ChileanRut\Tests\Validator;
|
||||
|
||||
use MNC\ChileanRut\Exception\InvalidRutException;
|
||||
use MNC\ChileanRut\Util\CorrelativeUtils;
|
||||
use MNC\ChileanRut\Validator\ChainRutValidator;
|
||||
use MNC\ChileanRut\Validator\Module11RutValidator;
|
||||
use MNC\ChileanRut\Validator\RutValidator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class ChainRutValidatorTest.
|
||||
*/
|
||||
class ChainRutValidatorTest extends TestCase
|
||||
{
|
||||
public function testThatChainValidatorFails(): void
|
||||
{
|
||||
$rut = CorrelativeUtils::autoGenerateValidRut();
|
||||
|
||||
$normalValidator = new Module11RutValidator();
|
||||
$mockValidator = $this->createMock(RutValidator::class);
|
||||
$mockValidator->expects($this->once())
|
||||
->method('validate')
|
||||
->willThrowException(new InvalidRutException($rut));
|
||||
|
||||
$chainValidator = new ChainRutValidator($normalValidator, $mockValidator);
|
||||
|
||||
$this->expectException(InvalidRutException::class);
|
||||
$chainValidator->validate($rut);
|
||||
}
|
||||
|
||||
public function testThatChainValidatorPasses(): void
|
||||
{
|
||||
$rut = CorrelativeUtils::autoGenerateValidRut();
|
||||
|
||||
$normalValidator = new Module11RutValidator();
|
||||
$mockValidator = $this->createMock(RutValidator::class);
|
||||
$mockValidator->expects($this->once())
|
||||
->method('validate')
|
||||
->willReturn(null);
|
||||
|
||||
$chainValidator = new ChainRutValidator($normalValidator, $mockValidator);
|
||||
|
||||
$chainValidator->validate($rut);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace MNC\ChileanRut\Tests\Validator;
|
||||
|
||||
use MNC\ChileanRut\Exception\InvalidRutException;
|
||||
use MNC\ChileanRut\Rut;
|
||||
use MNC\ChileanRut\Validator\SimpleRutValidator;
|
||||
use MNC\ChileanRut\Validator\Module11RutValidator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SimpleRutValidatorTest extends TestCase
|
||||
@@ -20,7 +20,7 @@ class SimpleRutValidatorTest extends TestCase
|
||||
public function testValidationPassesOnValidRut()
|
||||
{
|
||||
$rut = new Rut('16.894.365-2');
|
||||
$validator = new SimpleRutValidator();
|
||||
$validator = new Module11RutValidator();
|
||||
|
||||
$validator->validate($rut);
|
||||
|
||||
@@ -32,7 +32,7 @@ class SimpleRutValidatorTest extends TestCase
|
||||
$this->expectException(InvalidRutException::class);
|
||||
|
||||
$rut = new Rut('34.4534.353-1');
|
||||
$validator = new SimpleRutValidator();
|
||||
$validator = new Module11RutValidator();
|
||||
|
||||
$validator->validate($rut);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user