Completed
Push — master ( e4704b...bd1efa )
by Luís
11:15
created

DDC2780Test::testIssue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
7
/**
8
 * @group DDC-2780
9
 */
10
class DDC2780Test extends \Doctrine\Tests\OrmFunctionalTestCase
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15
    protected function setup()
16
    {
17
        parent::setup();
18
19
        $this->_schemaTool->createSchema(
20
            [
21
                $this->_em->getClassMetadata(DDC2780User::class),
22
                $this->_em->getClassMetadata(DDC2780Project::class)
23
            ]
24
        );
25
    }
26
27
    /**
28
     * Verifies that IS [NOT] NULL can be used on join aliases
29
     */
30
    public function testIssue()
31
    {
32
        $user    = new DDC2780User;
33
        $project = new DDC2780Project;
34
35
        $user->project = $project;
36
37
        $this->_em->persist($project);
38
        $this->_em->persist($user);
39
        $this->_em->flush();
40
        $this->_em->clear();
41
42
        $result = $this->_em->createQueryBuilder()
43
            ->select('user')
44
            ->from(DDC2780User::class, 'user')
45
            ->leftJoin('user.project', 'project')
46
            ->where('project IS NOT NULL')
47
            ->getQuery()
48
            ->getOneOrNullResult();
49
50
        $this->assertInstanceOf(DDC2780User::class, $result);
51
    }
52
}
53
54
/**
55
 * @Entity
56
 */
57
class DDC2780User
58
{
59
    /** @Id @Column(type="integer") @GeneratedValue */
60
    public $id;
61
62
    /**
63
     * @ManyToOne(targetEntity="DDC2780Project")
64
     *
65
     * @var DDC2780Project
66
     */
67
    public $project;
68
}
69
70
/** @Entity */
71
class DDC2780Project
72
{
73
    /** @Id @Column(type="integer") @GeneratedValue */
74
    public $id;
75
76
    /**
77
     * @OneToMany(targetEntity="DDC2780User", mappedBy="project")
78
     *
79
     * @var DDC2780User[]
80
     */
81
    public $users;
82
83
    /** Constructor */
84
    public function __construct()
85
    {
86
        $this->users = new ArrayCollection();
87
    }
88
}
89
90