1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Logging\DebugStack; |
8
|
|
|
use Doctrine\ORM\Annotation as ORM; |
9
|
|
|
use Doctrine\DBAL\Types\Type; |
|
|
|
|
10
|
|
|
use Doctrine\Tests\DbalTypes\Rot13Type; |
11
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @group 6443 |
15
|
|
|
*/ |
16
|
|
|
class GH6443Test extends OrmFunctionalTestCase |
17
|
|
|
{ |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
|
|
|
|
20
|
|
|
* @var Rot13Type |
21
|
|
|
*/ |
22
|
|
|
private $rot13Type; |
23
|
|
|
|
24
|
|
|
/** |
|
|
|
|
25
|
|
|
* @var DebugStack |
26
|
|
|
*/ |
27
|
|
|
private $sqlLogger; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* when having an entity, that has a non scalar identifier, the type will not be guessed / converted correctly |
31
|
|
|
*/ |
32
|
|
|
public function testIssue() |
33
|
|
|
{ |
|
|
|
|
34
|
|
|
|
35
|
|
|
$entity = new GH6443Post(); |
|
|
|
|
36
|
|
|
$entity->id = 'Foo'; |
37
|
|
|
|
38
|
|
|
$dql = 'SELECT p FROM ' . GH6443Post::class . ' p WHERE p = ?1'; |
|
|
|
|
39
|
|
|
$query = $this->em->createQuery($dql); |
40
|
|
|
|
41
|
|
|
// we do not know that the internal type is a rot13, so we can not add the type parameter here |
42
|
|
|
$query->setParameter(1, $entity); |
43
|
|
|
|
44
|
|
|
// we do not need the result, but we need to execute it to log the SQL-Statement |
45
|
|
|
$query->getResult(); |
46
|
|
|
|
47
|
|
|
$lastSql = $this->sqlLogger->queries[count($this->sqlLogger->queries)]; |
|
|
|
|
48
|
|
|
|
49
|
|
|
// the entity's identifier is of type "rot13" so the query parameter needs to be this type too |
50
|
|
|
$this->assertSame( |
51
|
|
|
$this->rot13Type->getName(), |
52
|
|
|
$lastSql['types'][0], |
53
|
|
|
"asserting that the entity's identifier type is correctly inferred" |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* when having an entity, that has a non scalar identifier, the type will not be guessed / converted correctly |
59
|
|
|
*/ |
60
|
|
|
public function testIssueWithProxyClass() |
61
|
|
|
{ |
|
|
|
|
62
|
|
|
|
63
|
|
|
$metadata = $this->em->getClassMetadata(GH6443Post::class); |
|
|
|
|
64
|
|
|
$entityProxy = $this->em->getProxyFactory()->getProxy($metadata, ['id' => 'Foo']); |
65
|
|
|
|
66
|
|
|
$dql = 'SELECT p FROM ' . GH6443Post::class . ' p WHERE p = ?1'; |
|
|
|
|
67
|
|
|
$query = $this->em->createQuery($dql); |
68
|
|
|
|
69
|
|
|
// we do not know that the internal type is a rot13, so we can not add the type parameter here |
70
|
|
|
$query->setParameter(1, $entityProxy); |
71
|
|
|
|
72
|
|
|
// we do not need the result, but we need to execute it to log the SQL-Statement |
73
|
|
|
$query->getResult(); |
74
|
|
|
|
75
|
|
|
$lastSql = $this->sqlLogger->queries[count($this->sqlLogger->queries)]; |
|
|
|
|
76
|
|
|
|
77
|
|
|
// the entity's identifier is of type "rot13" so the query parameter needs to be this type too |
78
|
|
|
$this->assertSame( |
79
|
|
|
$this->rot13Type->getName(), |
80
|
|
|
$lastSql['types'][0], |
81
|
|
|
"asserting that the entity's identifier type is correctly inferred" |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritDoc} |
88
|
|
|
*/ |
89
|
|
|
protected function setUp(): void |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
parent::setUp(); |
92
|
|
|
|
93
|
|
|
$this->sqlLogger = new DebugStack(); |
94
|
|
|
$this->em->getConnection()->getConfiguration()->setSQLLogger($this->sqlLogger); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
97
|
|
|
$this->schemaTool->createSchema([ |
98
|
|
|
$this->em->getClassMetadata(GH6443Post::class), |
99
|
|
|
]); |
100
|
|
|
|
101
|
|
|
$this->rot13Type = Type::getType('rot13'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function tearDown(): void |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
parent::tearDown(); |
107
|
|
|
|
108
|
|
|
$this->schemaTool->dropSchema([ |
109
|
|
|
$this->em->getClassMetadata(GH6443Post::class), |
110
|
|
|
]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @ORM\Entity |
117
|
|
|
*/ |
118
|
|
|
class GH6443Post |
119
|
|
|
{ |
120
|
|
|
/** |
121
|
|
|
* @ORM\Id |
122
|
|
|
* @ORM\Column(type="rot13") |
123
|
|
|
*/ |
124
|
|
|
public $id; |
125
|
|
|
} |
126
|
|
|
|