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

ClassMetadata   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testThrowExceptionIfMoreThanOneIdentifierAttribute() 0 12 1
A testSetAttributeListWithoutId() 0 11 1
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