Failed Conditions
Pull Request — master (#3354)
by Michael
28:01 queued 16:46
created

TypeRegistryTest::testHas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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->register(self::OTHER_TYPE_NAME, self::OTHER_TYPE_CLASS);
29
        $this->registry->register(self::TEST_TYPE_NAME, self::TEST_TYPE_CLASS);
30
    }
31
32
    public function testGet() : void
33
    {
34
        self::assertInstanceOf(self::TEST_TYPE_CLASS, $this->registry->get(self::TEST_TYPE_NAME));
35
36
        $this->expectException(DBALException::class);
37
        $this->registry->get('unknown');
38
    }
39
40
    public function testGetReturnsSameInstances() : void
41
    {
42
        self::assertSame(
43
            $this->registry->get(self::TEST_TYPE_NAME),
44
            $this->registry->get(self::TEST_TYPE_NAME)
45
        );
46
    }
47
48
    public function testLookupName() : void
49
    {
50
        self::assertSame(
51
            self::TEST_TYPE_NAME,
52
            $this->registry->lookupName($this->registry->get(self::TEST_TYPE_NAME))
53
        );
54
55
        $this->expectException(DBALException::class);
56
        $this->registry->lookupName(new TextType());
57
    }
58
59
    public function testHas() : void
60
    {
61
        self::assertTrue($this->registry->has(self::TEST_TYPE_NAME));
62
        self::assertFalse($this->registry->has('unknown'));
63
    }
64
65
    public function testRegister() : void
66
    {
67
        $this->registry->register('some', TextType::class);
68
69
        self::assertTrue($this->registry->has('some'));
70
        self::assertInstanceOf(TextType::class, $this->registry->get('some'));
71
72
        $this->expectException(DBALException::class);
73
        $this->registry->register('some', TextType::class);
74
    }
75
76
    public function testOverride() : void
77
    {
78
        $this->registry->register('some', TextType::class);
79
        $this->registry->override('some', StringType::class);
80
81
        self::assertTrue($this->registry->has('some'));
82
        self::assertInstanceOf(StringType::class, $this->registry->get('some'));
83
84
        $this->expectException(DBALException::class);
85
        $this->registry->override('unknown', StringType::class);
86
    }
87
88
    public function testGetTypeClasses() : void
89
    {
90
        self::assertSame(
91
            [
92
                self::OTHER_TYPE_NAME => self::OTHER_TYPE_CLASS,
93
                self::TEST_TYPE_NAME  => self::TEST_TYPE_CLASS,
94
            ],
95
            $this->registry->getTypeClasses()
96
        );
97
    }
98
}
99