Failed Conditions
Pull Request — master (#6392)
by Alessandro
18:37
created

Ticket4646InstanceOfMultiLevelTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
7 View Code Duplication
class Ticket4646InstanceOfMultiLevelTest extends OrmFunctionalTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    protected function setUp()
10
    {
11
        parent::setUp();
12
13
        $this->_schemaTool->createSchema([
14
            $this->_em->getClassMetadata(PersonTicket4646MultiLevel::class),
15
            $this->_em->getClassMetadata(EmployeeTicket4646MultiLevel::class),
16
            $this->_em->getClassMetadata(EngineerTicket4646MultiLevel::class),
17
        ]);
18
    }
19
20
    public function testInstanceOf()
21
    {
22
        $this->_em->persist(new PersonTicket4646MultiLevel());
23
        $this->_em->persist(new EmployeeTicket4646MultiLevel());
24
        $this->_em->persist(new EngineerTicket4646MultiLevel());
25
        $this->_em->flush();
26
27
        $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel p
28
                WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel';
29
        $query = $this->_em->createQuery($dql);
30
        $result = $query->getResult();
31
32
        $this->assertCount(3, $result);
33
        $this->assertContainsOnlyInstancesOf(PersonTicket4646MultiLevel::class, $result);
34
    }
35
}
36
37
/**
38
 * @Entity()
39
 * @Table(name="instance_of_multi_level_test_person")
40
 * @InheritanceType(value="JOINED")
41
 * @DiscriminatorColumn(name="kind", type="string")
42
 * @DiscriminatorMap(value={
43
 *     "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel",
44
 *     "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646MultiLevel",
45
 *     "engineer": "Doctrine\Tests\ORM\Functional\Ticket\EngineerTicket4646MultiLevel",
46
 * })
47
 */
48
class PersonTicket4646MultiLevel
49
{
50
    /**
51
     * @Id()
52
     * @GeneratedValue()
53
     * @Column(type="integer")
54
     */
55
    private $id;
56
57
    public function getId()
58
    {
59
        return $this->id;
60
    }
61
}
62
63
/**
64
 * @Entity()
65
 * @Table(name="instance_of_multi_level_employee")
66
 */
67
class EmployeeTicket4646MultiLevel extends PersonTicket4646MultiLevel
68
{
69
}
70
71
/**
72
 * @Entity()
73
 * @Table(name="instance_of_multi_level_engineer")
74
 */
75
class EngineerTicket4646MultiLevel extends EmployeeTicket4646MultiLevel
76
{
77
}
78