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

ModelLocatorTest::testGetInvalidAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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