ModelResourceTest::testConstructorVariants()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Acl;
6
7
use Ecodev\Felix\Acl\ModelResource;
8
use EcodevTests\Felix\Blog\Model\User;
9
use InvalidArgumentException;
10
use PHPUnit\Framework\TestCase;
11
12
final class ModelResourceTest extends TestCase
13
{
14
    public function testConstructorVariants(): void
15
    {
16
        // Constructor with preloaded model
17
        $user = new User();
18
        $resource = new ModelResource(User::class, $user);
19
        self::assertSame($user, $resource->getInstance(), 'should be able to get back model');
20
        self::assertSame('User#null', $resource->getName(), 'should have unique name');
21
22
        $resourceWithoutInstance = new ModelResource(User::class);
23
        self::assertSame('User#null', $resourceWithoutInstance->getName(), 'should have name even without instance');
24
    }
25
26
    public function testUnknownClassMustThrow(): void
27
    {
28
        $this->expectException(InvalidArgumentException::class);
29
30
        new ModelResource('non-existing-class-name');
31
    }
32
}
33