EntityTest::testGetIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Ajir\RabbitMqSqlBundle\Tests\Model;
3
4
use Ajir\RabbitMqSqlBundle\Model\Entity;
5
use PHPUnit_Framework_TestCase;
6
7
/**
8
 * Class EntityTest
9
 *
10
 * @author Florian Ajir <[email protected]>
11
 */
12
class EntityTest extends PHPUnit_Framework_TestCase
13
{
14
15
    /**
16
     * The simple mapping fixture
17
     *
18
     * @var array
19
     */
20
    protected $data;
21
22
    /**
23
     *
24
     */
25
    public function testGetIdentifier()
26
    {
27
        $entity = new Entity($this->data);
28
        $identifier = $entity->getIdentifier();
29
        $this->assertEquals(array('sku' => 'sku_user'), $identifier);
30
    }
31
32
    /**
33
     *
34
     */
35
    public function testGetProperty()
36
    {
37
        $entity = new Entity($this->data);
38
        $sku = $entity->getProperty('sku');
39
        $this->assertEquals('sku_user', $sku);
40
    }
41
42
    /**
43
     *
44
     */
45
    public function testGetTable()
46
    {
47
        $entity = new Entity($this->data);
48
        $table = $entity->getTable();
49
        $this->assertEquals('user', $table);
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testInstanciateWithoutTableData()
56
    {
57
        $data = $this->data;
58
        unset($data['_table']);
59
        $this->setExpectedException('InvalidArgumentException');
60
        new Entity($data);
61
    }
62
63
    /**
64
     * Sets up the fixture
65
     */
66
    protected function setUp()
67
    {
68
        $this->data = array(
69
            '_identifier' => 'sku',
70
            '_table'      => 'user',
71
            'id'          => '1',
72
            'sku'         => 'sku_user',
73
            'name'        => 'toto',
74
            '_related'    =>
75
                array(
76
                    'manyToOne' =>
77
                        array(
78
                            'Address' =>
79
                                array(
80
                                    '_relation' => array(
81
                                        'targetEntity' => 'Address',
82
                                        'joinColumn'   => array(
83
                                            'name'                 => 'address_id',
84
                                            'referencedColumnName' => 'id',
85
                                        ),
86
                                        'table'        => 'address',
87
                                    ),
88
                                    '_data'     =>
89
                                        array(
90
                                            'address' =>
91
                                                array(
92
                                                    '_identifier' => 'id',
93
                                                    'id'          => '1',
94
                                                    'postal_code' => '34000',
95
                                                    'city'        => 'Montpellier',
96
                                                ),
97
                                        ),
98
                                ),
99
                        ),
100
                ),
101
        );
102
    }
103
}
104