1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Types\Type; |
6
|
|
|
use Doctrine\Tests\DbalTypes\Rot13Type; |
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group 6443 |
11
|
|
|
*/ |
12
|
|
|
class GH6443Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var Rot13Type |
17
|
|
|
*/ |
18
|
|
|
private $rot13Type; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* when having an entity, that has a non scalar identifier, the type will not be guessed / converted correctly |
22
|
|
|
*/ |
23
|
|
|
public function testIssue() |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
$entity = new GH6443Post(); |
27
|
|
|
$entity->id = 'Foo'; |
28
|
|
|
|
29
|
|
|
$dql = 'SELECT p FROM ' . GH6443Post::class . ' p WHERE p = ?1'; |
30
|
|
|
$query = $this->_em->createQuery($dql); |
31
|
|
|
|
32
|
|
|
// we do not know that the internal type is a rot13, so we can not add the type parameter here |
33
|
|
|
$query->setParameter(1, $entity); |
34
|
|
|
|
35
|
|
|
// we do not need the result, but we need to execute it to log the SQL-Statement |
36
|
|
|
$result = $query->getResult(); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$sqlLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); |
39
|
|
|
$lastSql = $sqlLogger->queries[count($sqlLogger->queries)]; |
|
|
|
|
40
|
|
|
|
41
|
|
|
// the entities identifier is of type "rot13" so the query parameter needs to be the converted value |
42
|
|
|
$this->assertSame( |
43
|
|
|
$this->rot13Type->convertToDatabaseValue($entity->id, $this->_em->getConnection()->getDatabasePlatform()), |
44
|
|
|
$lastSql['params'][0] |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
|
|
protected function setUp(): void |
52
|
|
|
{ |
53
|
|
|
parent::setUp(); |
54
|
|
|
|
55
|
|
|
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack); |
56
|
|
|
|
57
|
|
|
$this->_schemaTool->createSchema([ |
58
|
|
|
$this->_em->getClassMetadata(GH6443Post::class), |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
$this->rot13Type = Type::getType('rot13'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @Entity */ |
67
|
|
|
class GH6443Post |
68
|
|
|
{ |
69
|
|
|
/** @Id @Column(type="rot13") */ |
70
|
|
|
public $id; |
71
|
|
|
} |
72
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.