1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\DBAL\Types; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\DBALException; |
8
|
|
|
use Doctrine\DBAL\Types\BinaryType; |
9
|
|
|
use Doctrine\DBAL\Types\BlobType; |
10
|
|
|
use Doctrine\DBAL\Types\StringType; |
11
|
|
|
use Doctrine\DBAL\Types\TextType; |
12
|
|
|
use Doctrine\DBAL\Types\TypeRegistry; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class TypeRegistryTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
private const TEST_TYPE_NAME = 'test'; |
18
|
|
|
private const TEST_TYPE_CLASS = BlobType::class; |
19
|
|
|
private const OTHER_TYPE_NAME = 'other'; |
20
|
|
|
private const OTHER_TYPE_CLASS = BinaryType::class; |
21
|
|
|
|
22
|
|
|
/** @var TypeRegistry */ |
23
|
|
|
private $registry; |
24
|
|
|
|
25
|
|
|
protected function setUp() : void |
26
|
|
|
{ |
27
|
|
|
$this->registry = new TypeRegistry(); |
28
|
|
|
$this->registry->addType(self::OTHER_TYPE_NAME, self::OTHER_TYPE_CLASS); |
29
|
|
|
$this->registry->addType(self::TEST_TYPE_NAME, self::TEST_TYPE_CLASS); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetType() : void |
33
|
|
|
{ |
34
|
|
|
self::assertInstanceOf(self::TEST_TYPE_CLASS, $this->registry->getType(self::TEST_TYPE_NAME)); |
35
|
|
|
|
36
|
|
|
$this->expectException(DBALException::class); |
37
|
|
|
$this->registry->getType('unknown'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetTypeReturnsSameInstances() : void |
41
|
|
|
{ |
42
|
|
|
self::assertSame( |
43
|
|
|
$this->registry->getType(self::TEST_TYPE_NAME), |
44
|
|
|
$this->registry->getType(self::TEST_TYPE_NAME) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGetName() : void |
49
|
|
|
{ |
50
|
|
|
self::assertSame( |
51
|
|
|
self::TEST_TYPE_NAME, |
52
|
|
|
$this->registry->getName($this->registry->getType(self::TEST_TYPE_NAME)) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->expectException(DBALException::class); |
56
|
|
|
$this->registry->getName(new TextType()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHasType() : void |
60
|
|
|
{ |
61
|
|
|
self::assertTrue($this->registry->hasType(self::TEST_TYPE_NAME)); |
62
|
|
|
self::assertFalse($this->registry->hasType('unknown')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testAddType() : void |
66
|
|
|
{ |
67
|
|
|
$this->registry->addType('some', TextType::class); |
68
|
|
|
|
69
|
|
|
self::assertTrue($this->registry->hasType('some')); |
70
|
|
|
self::assertInstanceOf(TextType::class, $this->registry->getType('some')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testOverrideType() : void |
74
|
|
|
{ |
75
|
|
|
$this->registry->addType('some', TextType::class); |
76
|
|
|
$this->registry->overrideType('some', StringType::class); |
77
|
|
|
|
78
|
|
|
self::assertTrue($this->registry->hasType('some')); |
79
|
|
|
self::assertInstanceOf(StringType::class, $this->registry->getType('some')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetTypesMap() : void |
83
|
|
|
{ |
84
|
|
|
self::assertSame( |
85
|
|
|
[ |
86
|
|
|
self::OTHER_TYPE_NAME => self::OTHER_TYPE_CLASS, |
87
|
|
|
self::TEST_TYPE_NAME => self::TEST_TYPE_CLASS, |
88
|
|
|
], |
89
|
|
|
$this->registry->getTypesMap() |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|