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
|
|
|
* {@inheritDoc} |
59
|
|
|
*/ |
60
|
|
|
protected function setUp(): void |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
parent::setUp(); |
63
|
|
|
|
64
|
|
|
$this->sqlLogger = new DebugStack(); |
65
|
|
|
$this->em->getConnection()->getConfiguration()->setSQLLogger($this->sqlLogger); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
68
|
|
|
$this->schemaTool->createSchema([ |
69
|
|
|
$this->em->getClassMetadata(GH6443Post::class), |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
$this->rot13Type = Type::getType('rot13'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @ORM\Entity |
79
|
|
|
*/ |
80
|
|
|
class GH6443Post |
81
|
|
|
{ |
82
|
|
|
/** |
83
|
|
|
* @ORM\Id |
84
|
|
|
* @ORM\Column(type="rot13") |
85
|
|
|
*/ |
86
|
|
|
public $id; |
87
|
|
|
} |
88
|
|
|
|