IdGeneratorRegistryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testGetIdGeneratorReturnsRegisteredGenerator() 0 12 1
A testGetIdGeneratorReturnsPreviouslyCreatedGenerator() 0 8 1
A testGetIdGeneratorCreatesGeneratorByDefault() 0 7 1
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