Completed
Push — master ( c5047e...3a177f )
by Gabriel
03:52
created

ModelLocatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetClassFullName() 0 5 1
A testGetInvalidAlias() 0 5 1
A testGetClassFromConfigNamespace() 0 12 1
A testGetClassFromModelRegistry() 0 13 1
1
<?php
2
3
namespace Nip\Records\Tests\Locator;
4
5
use Nip\Records\Locator\Exceptions\InvalidModelException;
6
use Nip\Records\Locator\ModelLocator;
7
use Nip\Records\Tests\AbstractTest;
8
use Nip\Records\Tests\Fixtures\Records\Books\Books;
9
10
/**
11
 * Class ModelLocatorTest
12
 * @package Nip\Records\Tests
13
 */
14
class ModelLocatorTest extends AbstractTest
15
{
16
17
    public function testGetClassFullName()
18
    {
19
        $manager = ModelLocator::get(Books::class);
20
        self::assertInstanceOf(Books::class, $manager);
21
    }
22
23
    public function testGetInvalidAlias()
24
    {
25
        self::expectException(InvalidModelException::class);
26
        ModelLocator::get('ClassNotExist');
27
    }
28
29
    public function testGetClassFromConfigNamespace()
30
    {
31
        ModelLocator::instance()->getConfiguration()->addNamespace('Nip\Records\Tests\Fixtures\Records');
32
33
        $manager = ModelLocator::get('Books');
34
        self::assertInstanceOf(Books::class, $manager);
35
36
        $manager = ModelLocator::get('Books\Books');
37
        self::assertInstanceOf(Books::class, $manager);
38
        $manager = ModelLocator::get('books');
39
        self::assertInstanceOf(Books::class, $manager);
40
    }
41
42
    public function testGetClassFromModelRegistry()
43
    {
44
        ModelLocator::instance()->getConfiguration()->addNamespace('Nip\Records\Tests\Fixtures\Records');
45
46
        $manager = ModelLocator::get('Books');
47
        self::assertInstanceOf(Books::class, $manager);
48
        $manager->singleton = 'valid';
0 ignored issues
show
Bug introduced by
The property singleton does not seem to exist in Nip\Records\RecordManager.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
        self::assertEquals('valid', $manager->singleton);
50
51
        $manager = ModelLocator::get('Books\Books');
52
        self::assertInstanceOf(Books::class, $manager);
53
        self::assertEquals('valid', $manager->singleton);
54
    }
55
}
56