Failed Conditions
Pull Request — 2.6 (#7807)
by Christian
07:11
created

GH7804::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($result) looks like debug code. Are you sure you do not want to remove it?
Loading history...
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