Failed Conditions
Pull Request — master (#7155)
by Gabriel
12:44
created

DDC2780Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testIssue() 0 21 1
A setUp() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Annotation as ORM;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
11
/**
12
 * @group DDC-2780
13
 */
14
class DDC2780Test extends OrmFunctionalTestCase
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    protected function setUp() : void
20
    {
21
        parent::setUp();
22
23
        $this->schemaTool->createSchema(
24
            [
25
                $this->em->getClassMetadata(DDC2780User::class),
26
                $this->em->getClassMetadata(DDC2780Project::class),
27
            ]
28
        );
29
    }
30
31
    /**
32
     * Verifies that IS [NOT] NULL can be used on join aliases
33
     */
34
    public function testIssue() : void
35
    {
36
        $user    = new DDC2780User();
37
        $project = new DDC2780Project();
38
39
        $user->project = $project;
40
41
        $this->em->persist($project);
42
        $this->em->persist($user);
43
        $this->em->flush();
44
        $this->em->clear();
45
46
        $result = $this->em->createQueryBuilder()
47
            ->select('user')
48
            ->from(DDC2780User::class, 'user')
49
            ->leftJoin('user.project', 'project')
50
            ->where('project IS NOT NULL')
51
            ->getQuery()
52
            ->getOneOrNullResult();
53
54
        self::assertInstanceOf(DDC2780User::class, $result);
55
    }
56
}
57
58
/**
59
 * @ORM\Entity
60
 */
61
class DDC2780User
62
{
63
    /**
64
     * @ORM\Id @ORM\GeneratedValue
65
     * @ORM\Column(type="integer")
66
     */
67
    public $id;
68
69
    /**
70
     * @ORM\ManyToOne(targetEntity=DDC2780Project::class)
71
     *
72
     * @var DDC2780Project
73
     */
74
    public $project;
75
}
76
77
/** @ORM\Entity */
78
class DDC2780Project
79
{
80
    /**
81
     * @ORM\Id @ORM\GeneratedValue
82
     * @ORM\Column(type="integer")
83
     */
84
    public $id;
85
86
    /**
87
     * @ORM\OneToMany(targetEntity=DDC2780User::class, mappedBy="project")
88
     *
89
     * @var DDC2780User[]
90
     */
91
    public $users;
92
93
    /** Constructor */
94
    public function __construct()
95
    {
96
        $this->users = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Doctrine\Tests\ORM\Functional\Ticket\DDC2780User[] of property $users.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
    }
98
}
99