Failed Conditions
Pull Request — 2.7 (#7148)
by Vadim
10:10
created

DDC6470User   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setName() 0 3 1
A getId() 0 3 1
A getName() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\ORM\Tools\ToolsException;
6
7
/**
8
 */
9
class DDC6470Test extends \Doctrine\Tests\OrmFunctionalTestCase
10
{
11
    public function setUp()
12
    {
13
        $this->enableSecondLevelCache();
14
        parent::setUp();
15
16
        try {
17
            $this->_schemaTool->createSchema(
18
                [
19
                    $this->_em->getClassMetadata(DDC6470User::class),
20
                    $this->_em->getClassMetadata(DDC6470Driver::class),
21
                ]
22
            );
23
        } catch (ToolsException $exc) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
24
        }
25
    }
26
27
    public function testIssue()
28
    {
29
        $driver1 = new DDC6470Driver('Bar');
30
31
        $this->_em->persist($driver1);
32
        $this->_em->flush();
33
        $this->_em->clear();
34
35
36
        $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470User::class, ['id' => $driver1->getUserProfile()->getId()]));
37
        $queryCount = $this->getCurrentQueryCount();
38
        $driver3 = $this->_em->createQueryBuilder()
39
            ->from(DDC6470Driver::class, 'd')
40
            ->select('d')
41
            ->where('d.id = :id')
42
            ->setParameter('id', $driver1->getId())
43
            ->setCacheable(true)
44
            ->getQuery()
45
            ->getOneOrNullResult();
46
        $this->assertEquals($queryCount+1, $this->getCurrentQueryCount());
47
        $this->assertInstanceOf(DDC6470Driver::class, $driver3);
48
        $this->assertInstanceOf(DDC6470User::class, $driver3->getUserProfile());
49
    }
50
}
51
52
/**
53
 * @Entity
54
 * @Table(name="ddc6470_drivers")
55
 * @Cache("NONSTRICT_READ_WRITE")
56
 */
57
class DDC6470Driver
58
{
59
    /**
60
     * @Id
61
     * @GeneratedValue
62
     * @Column(type="integer")
63
     */
64
    protected $id;
65
66
    /**
67
     * @Column(type="string")
68
     * @var string
69
     */
70
    protected $name;
71
72
    /**
73
     * @Cache("NONSTRICT_READ_WRITE")
74
     * @OneToOne(targetEntity="DDC6470User", mappedBy="user", cascade={"persist"})
75
     */
76
    protected $userProfile;
77
78
    public function __construct($name)
79
    {
80
        $this->name = $name;
81
        $this->userProfile = new DDC6470User('Foo', $this);
82
    }
83
84
    /**
85
     * @return integer
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90
    }
91
92
    /**
93
     * @param string $name
94
     */
95
    public function setName($name)
96
    {
97
        $this->name = $name;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getName()
104
    {
105
        return $this->name;
106
    }
107
108
    /**
109
     * @param \Entities\User $userProfile
0 ignored issues
show
Bug introduced by
The type Entities\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
110
     */
111
    public function setUserProfile($userProfile)
112
    {
113
        $this->userProfile = $userProfile;
114
    }
115
116
    /**
117
     * @return \Entities\User
118
     */
119
    public function getUserProfile()
120
    {
121
        return $this->userProfile;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->userProfile returns the type Doctrine\Tests\ORM\Functional\Ticket\DDC6470User which is incompatible with the documented return type Entities\User.
Loading history...
122
    }
123
}
124
125
/**
126
 * @Entity
127
 * @Table(name="ddc6470_users")
128
 * @Cache("NONSTRICT_READ_WRITE")
129
 */
130
class DDC6470User
131
{
132
    /**
133
     * @Id
134
     * @GeneratedValue
135
     * @Column(type="integer")
136
     */
137
    protected $id;
138
139
    /**
140
     * @Column(type="string")
141
     * @var string
142
     */
143
    protected $name;
144
    /**
145
     *
146
     * @OneToOne(targetEntity="DDC6470Driver", inversedBy="userProfile")
147
     * @JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
148
     * @Cache(usage="READ_ONLY")
149
     */
150
    protected $user;
151
152
    public function __construct($name, DDC6470Driver $user)
153
    {
154
        $this->name = $name;
155
        $this->user = $user;
156
    }
157
158
    /**
159
     * @return integer
160
     */
161
    public function getId()
162
    {
163
        return $this->id;
164
    }
165
166
    /**
167
     * @param string $name
168
     */
169
    public function setName($name)
170
    {
171
        $this->name = $name;
172
    }
173
174
    /**
175
     * @return string
176
     */
177
    public function getName()
178
    {
179
        return $this->name;
180
    }
181
}
182