Completed
Push — master ( 3eeaf5...0122c0 )
by Julien
05:59 queued 03:17
created

testThrowExceptionIfMoreThanOneIdentifierAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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