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\EnumType; |
10
|
|
|
use InvalidArgumentException; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
final class EnumTypeTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private EnumType $type; |
16
|
|
|
|
17
|
|
|
private AbstractPlatform $platform; |
18
|
|
|
|
19
|
|
|
protected function setUp(): void |
20
|
|
|
{ |
21
|
|
|
$this->type = new ExampleEnum(); |
22
|
|
|
$this->platform = new MySQLPlatform(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testEnum(): void |
26
|
|
|
{ |
27
|
|
|
self::assertSame("ENUM('value1', 'value2')", $this->type->getSqlDeclaration(['foo' => 'bar'], $this->platform)); |
28
|
|
|
|
29
|
|
|
// Should always return string |
30
|
|
|
self::assertSame('value1', $this->type->convertToPHPValue('value1', $this->platform)); |
31
|
|
|
|
32
|
|
|
// Should support null values or empty string |
33
|
|
|
self::assertNull($this->type->convertToPHPValue(null, $this->platform)); |
34
|
|
|
self::assertNull($this->type->convertToPHPValue('', $this->platform)); |
|
|
|
|
35
|
|
|
self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); |
36
|
|
|
self::assertNull($this->type->convertToDatabaseValue('', $this->platform)); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testConvertToPHPValueThrowsWithInvalidValue(): void |
40
|
|
|
{ |
41
|
|
|
$this->expectException(InvalidArgumentException::class); |
42
|
|
|
$this->expectExceptionMessage("Invalid 'foo' value fetched from database for enum ExampleEnum"); |
43
|
|
|
|
44
|
|
|
$this->type->convertToPHPValue('foo', $this->platform); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testConvertToDatabaseValueThrowsWithInvalidValue(): void |
48
|
|
|
{ |
49
|
|
|
$this->expectException(InvalidArgumentException::class); |
50
|
|
|
$this->expectExceptionMessage("Invalid 'foo' value to be stored in database for enum ExampleEnum"); |
51
|
|
|
|
52
|
|
|
$this->type->convertToDatabaseValue('foo', $this->platform); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testConvertToPHPValueThrowsWithZero(): void |
56
|
|
|
{ |
57
|
|
|
$this->expectException(InvalidArgumentException::class); |
58
|
|
|
$this->expectExceptionMessage("Invalid '0' value fetched from database for enum ExampleEnum"); |
59
|
|
|
|
60
|
|
|
$this->type->convertToPHPValue(0, $this->platform); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testConvertToDatabaseValueThrowsWithZero(): void |
64
|
|
|
{ |
65
|
|
|
$this->expectException(InvalidArgumentException::class); |
66
|
|
|
$this->expectExceptionMessage("Invalid '0' value to be stored in database for enum ExampleEnum"); |
67
|
|
|
|
68
|
|
|
$this->type->convertToDatabaseValue(0, $this->platform); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.