Passed
Pull Request — master (#243)
by Jesús
09:27
created

LocatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 3 1
A test_get_null_from_non_existing_class() 0 5 1
A test_get_concrete_class() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Framework\Container;
6
7
use Gacela\Framework\Container\Locator;
8
use GacelaTest\Fixtures\StringValue;
9
use PHPUnit\Framework\TestCase;
10
11
final class LocatorTest extends TestCase
12
{
13
    private Locator $locator;
14
15
    public function setUp(): void
16
    {
17
        Locator::resetInstance();
18
        $this->locator = Locator::getInstance();
19
    }
20
21
    public function tearDown(): void
22
    {
23
        Locator::resetInstance();
24
    }
25
26
    public function test_get_concrete_class(): void
27
    {
28
        /** @var StringValue $stringValue */
29
        $stringValue = $this->locator->get(StringValue::class);
30
        self::assertInstanceOf(StringValue::class, $stringValue);
31
        self::assertSame('', $stringValue->value());
32
        $stringValue->setValue('updated value');
33
34
        /** @var StringValue $stringValue2 */
35
        $stringValue2 = $this->locator->get(StringValue::class);
36
        self::assertSame('updated value', $stringValue2->value());
37
    }
38
39
    public function test_get_null_from_non_existing_class(): void
40
    {
41
        /** @var null $nullValue */
42
        $nullValue = $this->locator->get('NonExistingClass');
43
        self::assertNull($nullValue);
44
    }
45
}
46