|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace EcodevTests\Felix\DBAL\Types; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
8
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform; |
|
9
|
|
|
use Ecodev\Felix\DBAL\Types\CHFType; |
|
10
|
|
|
use InvalidArgumentException; |
|
11
|
|
|
use Money\Money; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
final class CHFTypeTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
private CHFType $type; |
|
17
|
|
|
|
|
18
|
|
|
private AbstractPlatform $platform; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->type = new CHFType(); |
|
23
|
|
|
|
|
24
|
|
|
$this->platform = new MySQLPlatform(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testMoney(): void |
|
28
|
|
|
{ |
|
29
|
|
|
self::assertSame('INT', $this->type->getSqlDeclaration(['foo' => 'bar'], $this->platform)); |
|
30
|
|
|
|
|
31
|
|
|
// Should always return string |
|
32
|
|
|
$actualPhp = $this->type->convertToPHPValue(100, $this->platform); |
|
33
|
|
|
self::assertInstanceOf(Money::class, $actualPhp); |
|
34
|
|
|
self::assertTrue(Money::CHF(100)->equals($actualPhp)); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
// Should support null values |
|
37
|
|
|
self::assertNull($this->type->convertToPHPValue(null, $this->platform)); |
|
38
|
|
|
self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testConvertToPHPValueThrowsWithInvalidValue(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
44
|
|
|
$this->type->convertToPHPValue('foo', $this->platform); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testConvertToDatabaseValueThrowsWithInvalidValue(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
50
|
|
|
$this->type->convertToDatabaseValue('foo', $this->platform); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|