|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
8
|
|
|
|
|
9
|
|
|
final class GH7804 extends OrmFunctionalTestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public static function setUpBeforeClass() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::setUpBeforeClass(); // TODO: Change the autogenerated stub |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
|
|
21
|
|
|
$this->setUpEntitySchema([ |
|
22
|
|
|
GH7804Entity::class |
|
23
|
|
|
]); |
|
24
|
|
|
|
|
25
|
|
|
$entity = new GH7804Entity(); |
|
26
|
|
|
$entity->title = 'foo'; |
|
27
|
|
|
|
|
28
|
|
|
$this->_em->persist($entity); |
|
29
|
|
|
$this->_em->flush(); |
|
30
|
|
|
$this->_em->clear(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testPositiveQuery(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$qb = $this->_em->createQueryBuilder(); |
|
36
|
|
|
|
|
37
|
|
|
$result = $qb->from(GH7804Entity::class, 'a') |
|
38
|
|
|
->select('a.title as t') |
|
39
|
|
|
->addGroupBy('t') |
|
40
|
|
|
->getQuery() |
|
41
|
|
|
->getResult(); |
|
42
|
|
|
|
|
43
|
|
|
self::assertEquals('foo', $result[0]['t']); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testQueryWithNew(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$qb = $this->_em->createQueryBuilder(); |
|
49
|
|
|
|
|
50
|
|
|
$result = $qb->from(GH7804Entity::class, 'a') |
|
51
|
|
|
->select( |
|
52
|
|
|
sprintf('new %s(a.title)', GH7804Dto::class) |
|
53
|
|
|
) |
|
54
|
|
|
->getQuery() |
|
55
|
|
|
->getResult(); |
|
56
|
|
|
|
|
57
|
|
|
self::assertInstanceOf(GH7804Dto::class, $result[0]); |
|
58
|
|
|
self::assertEquals('foo', $result[0]->getTitle()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testQueryWithNewAlias(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$qb = $this->_em->createQueryBuilder(); |
|
64
|
|
|
|
|
65
|
|
|
$result = $qb->from(GH7804Entity::class, 'a') |
|
66
|
|
|
->select( |
|
67
|
|
|
sprintf('new %s(a.title as t)', GH7804Dto::class) |
|
68
|
|
|
) |
|
69
|
|
|
->addGroupBy('t') |
|
70
|
|
|
->getQuery() |
|
71
|
|
|
->getResult(); |
|
72
|
|
|
|
|
73
|
|
|
self::assertInstanceOf(GH7804Dto::class, $result[0]); |
|
74
|
|
|
self::assertEquals('foo', $result[0]->getTitle()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testQueryWithNewAndHidden(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$qb = $this->_em->createQueryBuilder(); |
|
80
|
|
|
|
|
81
|
|
|
$result = $qb->from(GH7804Entity::class, 'a') |
|
82
|
|
|
->select( |
|
83
|
|
|
sprintf('new %s(a.title)', GH7804Dto::class), |
|
84
|
|
|
'a.title as HIDDEN h1' |
|
85
|
|
|
) |
|
86
|
|
|
->addGroupBy('h1') |
|
87
|
|
|
->getQuery() |
|
88
|
|
|
->getResult(); |
|
89
|
|
|
|
|
90
|
|
|
var_dump($result); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
self::assertInstanceOf(GH7804Dto::class, $result[0]); |
|
93
|
|
|
self::assertEquals('foo', $result[0]->getTitle()); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Entity |
|
99
|
|
|
*/ |
|
100
|
|
|
class GH7804Entity |
|
101
|
|
|
{ |
|
102
|
|
|
/** |
|
103
|
|
|
* @Id |
|
104
|
|
|
* @Column(type="integer") |
|
105
|
|
|
* @GeneratedValue |
|
106
|
|
|
*/ |
|
107
|
|
|
public $id; |
|
108
|
|
|
|
|
109
|
|
|
/** @Column */ |
|
110
|
|
|
public $title; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
final class GH7804Dto |
|
114
|
|
|
{ |
|
115
|
|
|
private $title; |
|
116
|
|
|
|
|
117
|
|
|
public function __construct($title) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->title = $title; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getTitle() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->title; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|