1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
5
|
|
|
|
6
|
|
|
use Doctrine\ORM\Query; |
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group 5544 |
11
|
|
|
*/ |
12
|
|
|
class GH5544Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
protected function setUp(): void |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
$this->_schemaTool->createSchema([$this->_em->getClassMetadata(GH5544UserBrowser::class)]); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testIssue(): void |
22
|
|
|
{ |
23
|
|
|
$this->createData(); |
24
|
|
|
$initialQueryCount = $this->getCurrentQueryCount(); |
25
|
|
|
|
26
|
|
|
$query = $this->createQuery(false); |
27
|
|
|
self::assertSame(1, (int) $query->getSingleScalarResult()); |
28
|
|
|
self::assertEquals($initialQueryCount + 1, $this->getCurrentQueryCount()); |
29
|
|
|
|
30
|
|
|
$query = $this->createQuery(true); |
31
|
|
|
self::assertSame(1, (int) $query->getSingleScalarResult()); |
32
|
|
|
self::assertEquals($initialQueryCount + 2, $this->getCurrentQueryCount()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function createQuery(bool $distinct): Query |
36
|
|
|
{ |
37
|
|
|
return $this->_em |
38
|
|
|
->createQueryBuilder() |
39
|
|
|
->select(sprintf( |
40
|
|
|
'COUNT(%s CONCAT(ub.userId, :concat_separator, ub.browser)) cnt', |
41
|
|
|
$distinct ? 'DISTINCT' : '' |
42
|
|
|
)) |
43
|
|
|
->from(GH5544UserBrowser::class, 'ub') |
44
|
|
|
->setParameter('concat_separator', '|') |
45
|
|
|
->getQuery(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function createData(): void |
49
|
|
|
{ |
50
|
|
|
$this->_em->persist(new GH5544UserBrowser(123, 'Chrome')); |
51
|
|
|
$this->_em->flush(); |
52
|
|
|
$this->_em->clear(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Entity |
58
|
|
|
* @Table(name="GH5544_user_browser") |
59
|
|
|
*/ |
60
|
|
|
class GH5544UserBrowser |
61
|
|
|
{ |
62
|
|
|
/** |
63
|
|
|
* @Id |
64
|
|
|
* @GeneratedValue("NONE") |
65
|
|
|
* @Column(type="integer") |
66
|
|
|
* |
67
|
|
|
* @var int |
68
|
|
|
*/ |
69
|
|
|
public $userId; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Id |
73
|
|
|
* @GeneratedValue("NONE") |
74
|
|
|
* @Column(type="string", length=64) |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
public $browser; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param int $userId |
82
|
|
|
* @param string $browser |
83
|
|
|
*/ |
84
|
|
|
public function __construct(int $userId, string $browser) |
85
|
|
|
{ |
86
|
|
|
$this->userId = $userId; |
87
|
|
|
$this->browser = $browser; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|