Initial release

This commit is contained in:
Matias Navarro Carter
2018-08-08 14:11:11 -04:00
parent 05871cb847
commit 33eeec319b
18 changed files with 552 additions and 79 deletions

View File

@@ -0,0 +1,41 @@
<?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\Bridge\Symfony\Form;
use MNC\ChileanRut\Bridge\Symfony\Form\RutType;
use MNC\ChileanRut\Rut;
use Symfony\Component\Form\Test\TypeTestCase;
class RutTypeTest extends TypeTestCase
{
public function testSubmitValidData()
{
$objectToCompare = new Rut('16.894.365-2');
// $objectToCompare will retrieve data from the form submission; pass it as the second argument
$form = $this->factory->create(RutType::class);
// submit the data to the form directly
$form->submit('16.894.365-2');
$this->assertTrue($form->isSynchronized());
$formData = $form->getData();
// check that $objectToCompare was modified as expected when the form was submitted
$this->assertInstanceOf(Rut::class, $formData);
$this->assertTrue($formData->isEqualTo($objectToCompare));
$view = $form->createView();
$this->assertSame('16.894.365-2', $view->vars['value']);
}
}

View File

@@ -1,15 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: mnavarro
* Date: 07-08-18
* Time: 23:45
/*
* 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\Rut;
use MNC\ChileanRut\Exception\InvalidRutException;
use MNC\ChileanRut\Rut\Rut;
use MNC\ChileanRut\Rut;
use MNC\ChileanRut\Validator\SimpleRutValidator;
use PHPUnit\Framework\TestCase;
@@ -19,8 +21,8 @@ class RutTest extends TestCase
{
$rut = Rut::fromString('16.894.365-2');
$this->assertEquals('16894365', $rut->getCorrelative());
$this->assertEquals('2', $rut->getVerifierDigit());
$this->assertSame('16894365', $rut->getCorrelative());
$this->assertSame('2', $rut->getVerifierDigit());
}
public function testThatRutsInstantiatedDifferentFormatButWithEqualValueAreIndeedEqual()
@@ -33,19 +35,25 @@ class RutTest extends TestCase
public function testThatFormatClearWorks()
{
$rut = new Rut('16.894.365-2');
$this->assertEquals('168943652', $rut->format(Rut::FORMAT_CLEAR));
$this->assertSame('168943652', $rut->format(Rut::FORMAT_CLEAR));
}
public function testThatFormatWithHyphenWorks()
{
$rut = new Rut('16.894.365-2');
$this->assertEquals('16894365-2', $rut->format(Rut::FORMAT_HYPHENED));
$this->assertSame('16894365-2', $rut->format(Rut::FORMAT_HYPHENED));
}
public function testThatFormatReadableWorks()
{
$rut = new Rut('168943652');
$this->assertEquals('16.894.365-2', $rut->format(Rut::FORMAT_READABLE));
$this->assertSame('16.894.365-2', $rut->format(Rut::FORMAT_READABLE));
}
public function testThatFormatHiddenWorks()
{
$rut = new Rut('168943652');
$this->assertSame('16.***.***-2', $rut->format(Rut::FORMAT_HIDDEN));
}
public function testThatIntegratedValidationThrowsExceptionOnInvalidRut()
@@ -63,4 +71,12 @@ class RutTest extends TestCase
$this->assertInstanceOf(Rut::class, $rut);
}
public function testInvalidFormatValueRaisesException()
{
$rut = new Rut('16.894.365-2');
$this->expectException(\InvalidArgumentException::class);
$rut->format(23);
}
}

View File

@@ -1,9 +1,17 @@
<?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\Rut\Rut;
use MNC\ChileanRut\Rut;
use MNC\ChileanRut\Validator\SimpleRutValidator;
use PHPUnit\Framework\TestCase;