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 Money\Money; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class CHFTypeTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var CHFType |
17
|
|
|
*/ |
18
|
|
|
private $type; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var AbstractPlatform |
22
|
|
|
*/ |
23
|
|
|
private $platform; |
24
|
|
|
|
25
|
|
|
public function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->type = $this->getMockBuilder(CHFType::class) |
|
|
|
|
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->onlyMethods([]) |
30
|
|
|
->getMock(); |
31
|
|
|
$this->platform = $this->createMock(AbstractPlatform::class); |
|
|
|
|
32
|
|
|
$this->platform = new MySqlPlatform(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testMoney(): void |
36
|
|
|
{ |
37
|
|
|
self::assertSame('INT', $this->type->getSqlDeclaration(['foo'], $this->platform)); |
38
|
|
|
|
39
|
|
|
// Should always return string |
40
|
|
|
$actualPhp = $this->type->convertToPHPValue(100, $this->platform); |
41
|
|
|
self::assertInstanceOf(Money::class, $actualPhp); |
42
|
|
|
self::assertTrue(Money::CHF(100)->equals($actualPhp)); |
43
|
|
|
|
44
|
|
|
// Should support null values |
45
|
|
|
self::assertNull($this->type->convertToPHPValue(null, $this->platform)); |
|
|
|
|
46
|
|
|
self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); |
47
|
|
|
|
48
|
|
|
self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testConvertToPHPValueThrowsWithInvalidValue(): void |
52
|
|
|
{ |
53
|
|
|
$this->expectException(\InvalidArgumentException::class); |
54
|
|
|
$this->type->convertToPHPValue('foo', $this->platform); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testConvertToDatabaseValueThrowsWithInvalidValue(): void |
58
|
|
|
{ |
59
|
|
|
$this->expectException(\InvalidArgumentException::class); |
60
|
|
|
$this->type->convertToDatabaseValue('foo', $this->platform); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..