ModelResourceTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorVariants() 0 10 1
A testUnknownClassMustThrow() 0 5 1
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