Completed
Pull Request — 2.6 (#7692)
by Matthieu
13:42 queued 21s
created

testWrongForeignKeysInDatabaseAreHandledByDoctrine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
7
class GH7692Test extends OrmFunctionalTestCase
8
{
9
    /**
10
     * {@inheritDoc}
11
     */
12
    protected function setUp(): void
13
    {
14
        parent::setUp();
15
16
        $this->setUpEntitySchema([
17
            GH7692Project::class,
18
            GH7692Contact::class,
19
        ]);
20
    }
21
22
    public function testWrongForeignKeysInDatabaseAreHandledByDoctrine(): void
23
    {
24
        // Create a row that references missing rows
25
        $this->_em->getConnection()->insert('project', [
26
            // This composite foreign key doesn't exist
27
            'contact_category' => 999,
28
            'contact_number' => 999,
29
        ]);
30
31
        $projects = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\GH7692Project p')->getResult();
32
        $this->assertCount(1, $projects);
33
    }
34
}
35
36
/**
37
 * @Entity
38
 * @Table(name="project")
39
 */
40
class GH7692Project
41
{
42
    /**
43
     * @Id
44
     * @Column(type="integer")
45
     * @GeneratedValue
46
     */
47
    public $id;
48
49
    /**
50
     * @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7692Contact", fetch="EAGER")
51
     * @JoinColumns({
52
     *     @JoinColumn(name="contact_category", referencedColumnName="category"),
53
     *     @JoinColumn(name="contact_number", referencedColumnName="number")
54
     * })
55
     */
56
    public $contact;
57
}
58
59
/**
60
 * @Entity
61
 */
62
class GH7692Contact
63
{
64
    /**
65
     * @Id
66
     * @Column(type="integer")
67
     */
68
    public $category;
69
70
    /**
71
     * @Id
72
     * @Column(type="integer")
73
     */
74
    public $number;
75
}
76