Completed
Pull Request — master (#6392)
by Alessandro
13:46
created

Person   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket {
4
5
    use Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee;
6
    use Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person;
7
    use Doctrine\Tests\OrmFunctionalTestCase;
8
9
    class Ticket4646InstanceOfAbstractTest extends OrmFunctionalTestCase
10
    {
11
        protected function setUp()
12
        {
13
            parent::setUp();
14
15
            $this->_schemaTool->createSchema([
16
                $this->_em->getClassMetadata(Person::class),
17
                $this->_em->getClassMetadata(Employee::class),
18
            ]);
19
        }
20
21
        public function testInstanceOf()
22
        {
23
            $this->loadData();
24
25
            $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p
26
                    WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person';
27
            $query = $this->_em->createQuery($dql);
28
            $result = $query->getResult();
29
30
            $this->assertCount(1, $result);
31
32
            foreach ($result as $r) {
33
                $this->assertInstanceOf(Person::class, $r);
34
                $this->assertInstanceOf(Employee::class, $r);
35
                $this->assertSame('bar', $r->getName());
36
            }
37
        }
38
39
        private function loadData()
40
        {
41
            $employee = new Employee();
42
            $employee->setName('bar');
43
            $employee->setDepartement('qux');
44
45
            $this->_em->persist($employee);
46
47
            $this->_em->flush($employee);
48
        }
49
    }
50
}
51
52
namespace Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest {
53
54
    /**
55
     * @Entity()
56
     * @Table(name="instance_of_abstract_test_person")
57
     * @InheritanceType(value="JOINED")
58
     * @DiscriminatorColumn(name="kind", type="string")
59
     * @DiscriminatorMap(value={
60
     *     "employee": Employee::class
61
     * })
62
     */
63
    abstract class Person
64
    {
65
        /**
66
         * @Id()
67
         * @GeneratedValue()
68
         * @Column(type="integer")
69
         */
70
        private $id;
71
72
        /**
73
         * @Column(type="string")
74
         */
75
        private $name;
76
77
        public function getId()
78
        {
79
            return $this->id;
80
        }
81
82
        public function getName()
83
        {
84
            return $this->name;
85
        }
86
87
        public function setName($name)
88
        {
89
            $this->name = $name;
90
        }
91
    }
92
93
    /**
94
     * @Entity()
95
     * @Table(name="instance_of_abstract_test_employee")
96
     */
97
    class Employee extends Person
98
    {
99
        /**
100
         * @Column(type="string")
101
         */
102
        private $departement;
103
104
        public function getDepartement()
105
        {
106
            return $this->departement;
107
        }
108
109
        public function setDepartement($departement)
110
        {
111
            $this->departement = $departement;
112
        }
113
    }
114
}
115