Completed
Pull Request — master (#45)
by Julien
03:06
created

ModelHydrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 74
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeTestMethod() 0 18 1
A testConvertId() 0 11 1
B testConvertIdWithoutMappingPrefix() 0 26 1
1
<?php
2
3
namespace Mapado\RestClientSdk\Tests\Units\Model;
4
5
use atoum;
6
use DateTime;
7
use Mapado\RestClientSdk\Mapping;
8
use Mapado\RestClientSdk\Mapping\Attribute;
9
use Mapado\RestClientSdk\Mapping\ClassMetadata;
10
use Mapado\RestClientSdk\Mapping\Relation;
11
12
/**
13
 * Class ModelHydrator
14
 * @author Julien Deniau <[email protected]>
15
 */
16
class ModelHydrator extends atoum
17
{
18
    private $sdk;
19
20
    public function beforeTestMethod($method)
21
    {
22
        $fooMetadata = new ClassMetadata(
23
            'foo',
24
            'Acme\Foo',
25
            ''
26
        );
27
28
        $mapping = new Mapping('/v1');
29
        $mapping->setMapping([
30
            $fooMetadata,
31
        ]);
32
33
        $this->mockGenerator->orphanize('__construct');
34
        $this->mockGenerator->shuntParentClassCalls();
35
        $this->sdk = new \mock\Mapado\RestClientSdk\SdkClient;
36
        $this->calling($this->sdk)->getMapping = $mapping;
37
    }
38
39
    /**
40
     * testConvertId
41
     *
42
     * @access public
43
     * @return void
44
     */
45
    public function testConvertId()
46
    {
47
        $this
48
            ->given($this->newTestedInstance($this->sdk))
49
            ->then
50
                ->string($this->testedInstance->convertId(2, 'Acme\Foo'))
51
                    ->isEqualTo('/v1/foo/2')
52
                ->string($this->testedInstance->convertId('/v1/foo/2', 'Acme\Foo'))
53
                    ->isEqualTo('/v1/foo/2')
54
        ;
55
    }
56
57
    /**
58
     * testConvertIdWithoutMappingPrefix
59
     *
60
     * @access public
61
     * @return void
62
     */
63
    public function testConvertIdWithoutMappingPrefix()
64
    {
65
        $fooMetadata = new ClassMetadata(
66
            'foo',
67
            'Acme\Foo',
68
            ''
69
        );
70
71
        $mapping = new Mapping();
72
        $mapping->setMapping([
73
            $fooMetadata,
74
        ]);
75
76
        $this->mockGenerator->orphanize('__construct');
77
        $this->mockGenerator->shuntParentClassCalls();
78
        $sdk = new \mock\Mapado\RestClientSdk\SdkClient;
79
        $this->calling($sdk)->getMapping = $mapping;
80
        $this
81
            ->given($this->newTestedInstance($sdk))
82
            ->then
83
                ->string($this->testedInstance->convertId(2, 'Acme\Foo'))
84
                    ->isEqualTo('/foo/2')
85
                ->string($this->testedInstance->convertId('/foo/2', 'Acme\Foo'))
86
                    ->isEqualTo('/foo/2')
87
        ;
88
    }
89
}
90