|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; |
|
7
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
8
|
|
|
use Doctrine\ORM\Mapping\DefaultQuoteStrategy; |
|
9
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class DDC7079Test |
|
13
|
|
|
* @group DDC-7079 |
|
14
|
|
|
* @package Doctrine\Tests\ORM\Functional |
|
15
|
|
|
* @author mairo744 |
|
16
|
|
|
*/ |
|
17
|
|
|
class DDC7079Test extends OrmFunctionalTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Doctrine\ORM\Mapping\DefaultQuoteStrategy |
|
21
|
|
|
*/ |
|
22
|
|
|
private $strategy; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform |
|
26
|
|
|
*/ |
|
27
|
|
|
private $platform; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritDoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::setUp(); |
|
35
|
|
|
$this->platform = $this->_em->getConnection()->getDatabasePlatform(); |
|
36
|
|
|
$this->strategy = new DefaultQuoteStrategy(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGetTableName () |
|
40
|
|
|
{ |
|
41
|
|
|
$table = [ |
|
42
|
|
|
'name'=>'cms_user', |
|
43
|
|
|
'schema' => 'cms', |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
$cm = $this->createClassMetadata(DDC7079CmsUser::class); |
|
47
|
|
|
$cm->setPrimaryTable($table); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals($this->getTableFullName($table), $this->strategy->getTableName($cm, $this->platform)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testJoinTableName() |
|
53
|
|
|
{ |
|
54
|
|
|
$table = [ |
|
55
|
|
|
'name'=>'cmsaddress_cmsuser', |
|
56
|
|
|
'schema' => 'cms', |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
$cm = $this->createClassMetadata(DDC7079CmsAddress::class); |
|
60
|
|
|
$cm->mapManyToMany( |
|
61
|
|
|
[ |
|
62
|
|
|
'fieldName' => 'user', |
|
63
|
|
|
'targetEntity' => 'DDC7079CmsUser', |
|
64
|
|
|
'inversedBy' => 'users', |
|
65
|
|
|
'joinTable' => $table, |
|
66
|
|
|
] |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals($this->getTableFullName($table), $this->strategy->getJoinTableName($cm->associationMappings['user'], $cm, $this->platform)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function getTableFullName(array $table): string |
|
73
|
|
|
{ |
|
74
|
|
|
$join = '.'; |
|
75
|
|
|
if ( ! $this->platform->supportsSchemas() && $this->platform->canEmulateSchemas()) { |
|
76
|
|
|
$join = '__'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $table['schema'] . $join . $table['name']; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
private function createClassMetadata(string $className): ClassMetadata |
|
83
|
|
|
{ |
|
84
|
|
|
$cm = new ClassMetadata($className); |
|
85
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
86
|
|
|
|
|
87
|
|
|
return $cm; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @Entity |
|
93
|
|
|
* @Table(name="cms_users", schema="cms") |
|
94
|
|
|
*/ |
|
95
|
|
|
class DDC7079CmsUser |
|
96
|
|
|
{ |
|
97
|
|
|
/** |
|
98
|
|
|
* @Id @Column(type="integer") |
|
99
|
|
|
* @GeneratedValue |
|
100
|
|
|
*/ |
|
101
|
|
|
public $id; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @OneToOne(targetEntity="DDC7079CmsAddress", mappedBy="user", cascade={"persist"}, orphanRemoval=true) |
|
105
|
|
|
*/ |
|
106
|
|
|
public $address; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @Entity |
|
111
|
|
|
* @Table(name="cms_addresses", schema="cms") |
|
112
|
|
|
*/ |
|
113
|
|
|
class DDC7079CmsAddress |
|
114
|
|
|
{ |
|
115
|
|
|
/** |
|
116
|
|
|
* @Column(type="integer") |
|
117
|
|
|
* @Id @GeneratedValue |
|
118
|
|
|
*/ |
|
119
|
|
|
public $id; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @OneToOne(targetEntity="DDC7079CmsUser", inversedBy="address") |
|
123
|
|
|
* @JoinColumn(referencedColumnName="id") |
|
124
|
|
|
*/ |
|
125
|
|
|
public $user; |
|
126
|
|
|
} |