IdGeneratorRegistryTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Orm\Ids\Generators;
6
7
use Opulence\Orm\Ids\Generators\IIdGenerator;
8
use Opulence\Orm\Ids\Generators\UuidV4Generator;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
12
class IdGeneratorRegistryTest extends TestCase
13
{
14
    /** @var IdGeneratorRegistry - System Under Test */
15
    protected IdGeneratorRegistry $sut;
16
17
    public function setUp(): void
18
    {
19
        parent::setUp();
20
21
        $this->sut = new IdGeneratorRegistry();
22
    }
23
24
    public function testGetIdGeneratorCreatesGeneratorByDefault(): void
25
    {
26
        $className = 'foo';
27
28
        $actualResult = $this->sut->getIdGenerator($className);
29
30
        $this->assertInstanceOf(UuidV4Generator::class, $actualResult);
31
    }
32
33
    public function testGetIdGeneratorReturnsPreviouslyCreatedGenerator(): void
34
    {
35
        $className = 'foo';
36
37
        $actualResult   = $this->sut->getIdGenerator($className);
38
        $repeatedResult = $this->sut->getIdGenerator($className);
39
40
        $this->assertSame($repeatedResult, $actualResult);
41
    }
42
43
    public function testGetIdGeneratorReturnsRegisteredGenerator(): void
44
    {
45
        /** @var IIdGenerator|MockObject $idGenerator */
46
        $idGenerator = $this->createMock(IIdGenerator::class);
47
48
        $className = 'foo';
49
50
        $this->sut->registerIdGenerator($className, $idGenerator);
51
52
        $actualResult = $this->sut->getIdGenerator($className);
53
54
        $this->assertSame($idGenerator, $actualResult);
55
    }
56
}
57