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