ClassMetadata   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testThrowExceptionIfMoreThanOneIdentifierAttribute() 0 12 1
A testSetAttributeListWithoutId() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk\Tests\Units\Mapping;
6
7
use atoum;
8
use Mapado\RestClientSdk\Exception\MissingIdentifierException;
9
use Mapado\RestClientSdk\Exception\MoreThanOneIdentifierException;
10
use Mapado\RestClientSdk\Mapping\Attribute;
11
12
class ClassMetadata extends atoum
13
{
14
    public function testSetAttributeListWithoutId()
15
    {
16
        $this
17
            ->given($testedInstance = $this->newTestedInstance('key', 'Model', 'ModelRepository'))
18
            ->and($testedInstance->setAttributeList([
19
                new Attribute('not an id'),
20
            ]))
21
            ->exception(function () use ($testedInstance) {
22
                $testedInstance->getIdentifierAttribute();
23
            })
24
                ->isInstanceOf(MissingIdentifierException::class)
25
        ;
26
    }
27
28
    public function testThrowExceptionIfMoreThanOneIdentifierAttribute()
29
    {
30
        $this
31
            ->given($testedInstance = $this->newTestedInstance('key', 'Model', 'ModelRepository'))
32
            ->exception(function () use ($testedInstance) {
33
                $testedInstance->setAttributeList([
34
                    new Attribute('a first id', null, null, true),
35
                    new Attribute('a second id', null, null, true),
36
                ]);
37
            })
38
                ->isInstanceOf(MoreThanOneIdentifierException::class)
39
                    ->hasMessage('Class metadata for model "Model" already has an identifier named "a first id". Only one identifier is allowed.')
40
        ;
41
    }
42
}
43