1
|
|
|
<?php |
2
|
|
|
namespace Ajir\RabbitMqSqlBundle\Tests\Model; |
3
|
|
|
|
4
|
|
|
use Ajir\RabbitMqSqlBundle\Model\OneToManyRelation; |
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class OneToManyRelationTest |
9
|
|
|
* |
10
|
|
|
* @author Florian Ajir <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class OneToManyRelationTest extends PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
public function testInstanciate() |
18
|
|
|
{ |
19
|
|
|
$data = array( |
20
|
|
|
'_relation' => array( |
21
|
|
|
'targetEntity' => 'selection_lang', |
22
|
|
|
'joinColumn' => array( |
23
|
|
|
'referencedColumnName' => 'id', |
24
|
|
|
'name' => 'selection_id', |
25
|
|
|
), |
26
|
|
|
'removeReferenced' => 'true', |
27
|
|
|
'references' => array( |
28
|
|
|
'lang_id' => array( |
29
|
|
|
'table' => 'lang', |
30
|
|
|
'referencedColumnName' => 'id', |
31
|
|
|
'where' => array( |
32
|
|
|
'iso_code' => 'fr' |
33
|
|
|
) |
34
|
|
|
) |
35
|
|
|
), |
36
|
|
|
'table' => 'selection_lang' |
37
|
|
|
), |
38
|
|
|
'_data' => array( |
39
|
|
|
array( |
40
|
|
|
'selection_lang' => array( |
41
|
|
|
'_table' => 'selection_lang', |
42
|
|
|
'_identifier' => 'name', |
43
|
|
|
'name' => 'test', |
44
|
|
|
) |
45
|
|
|
) |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
$relation = new OneToManyRelation($data); |
49
|
|
|
$this->assertTrue($relation->isRemoveReferenced()); |
50
|
|
|
$this->assertEquals($data['_data'], $relation->getEntities()); |
51
|
|
|
$this->assertEquals($data['_relation']['references'], $relation->getReferences()); |
52
|
|
|
$this->assertEquals($data['_relation']['targetEntity'], $relation->getEntityName()); |
53
|
|
|
$this->assertEquals($data['_relation']['joinColumn']['name'], $relation->getJoinColumnName()); |
54
|
|
|
$this->assertEquals( |
55
|
|
|
$data['_relation']['joinColumn']['referencedColumnName'], |
56
|
|
|
$relation->getJoinColumnReferencedColumnName() |
57
|
|
|
); |
58
|
|
|
$this->assertEquals($data['_relation']['table'], $relation->getTable()); |
59
|
|
|
} |
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
*/ |
63
|
|
|
public function testNotRemoveReferenced() |
64
|
|
|
{ |
65
|
|
|
$data = array( |
66
|
|
|
'_relation' => array( |
67
|
|
|
'targetEntity' => 'selection_lang', |
68
|
|
|
'joinColumn' => array( |
69
|
|
|
'referencedColumnName' => 'id', |
70
|
|
|
'name' => 'selection_id', |
71
|
|
|
), |
72
|
|
|
'references' => array( |
73
|
|
|
'lang_id' => array( |
74
|
|
|
'table' => 'lang', |
75
|
|
|
'referencedColumnName' => 'id', |
76
|
|
|
'where' => array( |
77
|
|
|
'iso_code' => 'fr' |
78
|
|
|
) |
79
|
|
|
) |
80
|
|
|
), |
81
|
|
|
'table' => 'selection_lang' |
82
|
|
|
), |
83
|
|
|
'_data' => array( |
84
|
|
|
array( |
85
|
|
|
'selection_lang' => array( |
86
|
|
|
'_table' => 'selection_lang', |
87
|
|
|
'_identifier' => 'name', |
88
|
|
|
'name' => 'test', |
89
|
|
|
) |
90
|
|
|
) |
91
|
|
|
) |
92
|
|
|
); |
93
|
|
|
$relation = new OneToManyRelation($data); |
94
|
|
|
$this->assertFalse($relation->isRemoveReferenced()); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|