1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Logging\DebugStack; |
6
|
|
|
use Doctrine\DBAL\Types\Type; |
7
|
|
|
use Doctrine\Tests\DbalTypes\Rot13Type; |
8
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @group 6443 |
12
|
|
|
*/ |
13
|
|
|
class GH6443Test extends OrmFunctionalTestCase |
14
|
|
|
{ |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
|
|
|
|
17
|
|
|
* @var Rot13Type |
18
|
|
|
*/ |
19
|
|
|
private $rot13Type; |
20
|
|
|
|
21
|
|
|
/** |
|
|
|
|
22
|
|
|
* @var DebugStack |
23
|
|
|
*/ |
24
|
|
|
private $sqlLogger; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* when having an entity, that has a non scalar identifier, the type will not be guessed / converted correctly |
28
|
|
|
*/ |
29
|
|
|
public function testIssue() |
30
|
|
|
{ |
|
|
|
|
31
|
|
|
|
32
|
|
|
$entity = new GH6443Post(); |
|
|
|
|
33
|
|
|
$entity->id = 'Foo'; |
34
|
|
|
|
35
|
|
|
$dql = 'SELECT p FROM ' . GH6443Post::class . ' p WHERE p = ?1'; |
|
|
|
|
36
|
|
|
$query = $this->_em->createQuery($dql); |
|
|
|
|
37
|
|
|
|
38
|
|
|
// we do not know that the internal type is a rot13, so we can not add the type parameter here |
39
|
|
|
$query->setParameter(1, $entity); |
40
|
|
|
|
41
|
|
|
// we do not need the result, but we need to execute it to log the SQL-Statement |
42
|
|
|
$query->getResult(); |
43
|
|
|
|
44
|
|
|
$lastSql = $this->sqlLogger->queries[count($this->sqlLogger->queries)]; |
|
|
|
|
45
|
|
|
|
46
|
|
|
// the entity's identifier is of type "rot13" so the query parameter needs to be this type too |
47
|
|
|
$this->assertSame( |
48
|
|
|
$this->rot13Type->getName(), |
49
|
|
|
$lastSql['types'][0], |
50
|
|
|
"asserting that the entity's identifier type is correctly inferred" |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
|
|
protected function setUp(): void |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
parent::setUp(); |
60
|
|
|
|
61
|
|
|
$this->sqlLogger = new DebugStack(); |
62
|
|
|
$this->_em->getConnection()->getConfiguration()->setSQLLogger($this->sqlLogger); |
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
65
|
|
|
$this->_schemaTool->createSchema([ |
|
|
|
|
66
|
|
|
$this->_em->getClassMetadata(GH6443Post::class), |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
$this->rot13Type = Type::getType('rot13'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
|
|
|
|
73
|
|
|
|
74
|
|
|
/** @Entity */ |
75
|
|
|
class GH6443Post |
76
|
|
|
{ |
77
|
|
|
/** @Id @Column(type="rot13") */ |
78
|
|
|
public $id; |
79
|
|
|
} |
80
|
|
|
|