ClassMetadata::testSetAttributeListWithoutId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
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