[BC] New Version

This version simplifies the api a lot, eliminating unnecesary complexity and reducing the library to a few classes only.
This commit is contained in:
2020-11-20 11:51:33 +00:00
parent 0ad94c4944
commit b4f4fe25b9
32 changed files with 847 additions and 1061 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace MNC\ChileanRut\Doctrine;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use MNC\ChileanRut\Rut;
use PHPUnit\Framework\TestCase;
class NumericRutTypeTest extends TestCase
{
public function testItConvertsNullFromDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new NumericRutType();
$result = $type->convertToPHPValue(null, $platform);
self::assertNull($result);
}
public function testItConvertsStringFromDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new NumericRutType();
$result = $type->convertToPHPValue(16894365, $platform);
self::assertInstanceOf(Rut::class, $result);
}
public function testItConvertsNullToDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new NumericRutType();
$result = $type->convertToDatabaseValue(null, $platform);
self::assertNull($result);
}
public function testItConvertsRutToDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new NumericRutType();
$result = $type->convertToDatabaseValue(Rut::parse('168943652'), $platform);
self::assertSame('16894365', $result);
}
public function testItCannotConvertToDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new NumericRutType();
$this->expectException(ConversionException::class);
$type->convertToDatabaseValue(new \DateTime(), $platform);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace MNC\ChileanRut\Doctrine;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use MNC\ChileanRut\Rut;
use PHPUnit\Framework\TestCase;
class RutTypeTest extends TestCase
{
public function testItConvertsNullFromDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new RutType();
$result = $type->convertToPHPValue(null, $platform);
self::assertNull($result);
}
public function testItConvertsStringFromDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new RutType();
$result = $type->convertToPHPValue('16.894.365-2', $platform);
self::assertInstanceOf(Rut::class, $result);
}
public function testItCannotConvertFromDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new RutType();
$this->expectException(ConversionException::class);
$type->convertToPHPValue(true, $platform);
}
public function testItConvertsNullToDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new RutType();
$result = $type->convertToDatabaseValue(null, $platform);
self::assertNull($result);
}
public function testItConvertsRutToDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new RutType();
$result = $type->convertToDatabaseValue(Rut::parse('168943652'), $platform);
self::assertSame('16.894.365-2', $result);
}
public function testItCannotConvertToDatabaseValue(): void
{
$platform = $this->createMock(AbstractPlatform::class);
$type = new RutType();
$this->expectException(ConversionException::class);
$type->convertToDatabaseValue(new \DateTime(), $platform);
}
}