Failed Conditions
Pull Request — master (#6392)
by Alessandro
21:55 queued 10:50
created

Ticket4646InstanceOfParametricTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 6
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testInstanceOf() 0 16 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
7
class Ticket4646InstanceOfParametricTest extends OrmFunctionalTestCase
8
{
9
    protected function setUp(): void
10
    {
11
        parent::setUp();
12
        $this->_schemaTool->createSchema([
13
            $this->_em->getClassMetadata(PersonTicket4646Parametric::class),
14
            $this->_em->getClassMetadata(EmployeeTicket4646Parametric::class),
15
        ]);
16
    }
17
18
    public function testInstanceOf(): void
19
    {
20
        $this->_em->persist(new PersonTicket4646Parametric());
21
        $this->_em->persist(new EmployeeTicket4646Parametric());
22
        $this->_em->flush();
23
        $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric p
24
                WHERE p INSTANCE OF :parameter';
25
        $query = $this->_em->createQuery($dql);
26
        $query->setParameter(
27
            'parameter',
28
            $this->_em->getClassMetadata(PersonTicket4646Parametric::class)
29
        );
30
        $result = $query->getResult();
31
        self::assertCount(2, $result);
32
        self::assertContainsOnlyInstancesOf(PersonTicket4646Parametric::class, $result);
33
    }
34
}
35
36
/**
37
 * @Entity()
38
 * @Table(name="instance_of_parametric_person")
39
 * @InheritanceType(value="JOINED")
40
 * @DiscriminatorColumn(name="kind", type="string")
41
 * @DiscriminatorMap(value={
42
 *     "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric",
43
 *     "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646Parametric"
44
 * })
45
 */
46
class PersonTicket4646Parametric
47
{
48
    /**
49
     * @Id()
50
     * @GeneratedValue()
51
     * @Column(type="integer")
52
     */
53
    private $id;
54
55
    public function getId(): ?int
56
    {
57
        return $this->id;
58
    }
59
}
60
61
/**
62
 * @Entity()
63
 * @Table(name="instance_of_parametric_employee")
64
 */
65
class EmployeeTicket4646Parametric extends PersonTicket4646Parametric
66
{
67
}
68