Completed
Pull Request — master (#5823)
by Mikhail
13:41
created

DDC2759Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10
Metric Value
wmc 3
lcom 1
cbo 10
dl 0
loc 57
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCorrectNumberOfAssociationsIsReturned() 0 14 1
B setUp() 0 36 2
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
/**
6
 * @group DDC-2759
7
 */
8
class DDC2759Test extends \Doctrine\Tests\OrmFunctionalTestCase
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13
    protected function setUp()
14
    {
15
        parent::setUp();
16
17
        try {
18
            $this->_schemaTool->createSchema(array(
19
                $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759Qualification'),
20
                $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759Category'),
21
                $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759QualificationMetadata'),
22
                $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759MetadataCategory'),
23
            ));
24
        } catch(\Exception $e) {
25
            return;
26
        }
27
28
        $qualification = new DDC2759Qualification();
29
        $qualificationMetadata = new DDC2759QualificationMetadata($qualification);
30
31
        $category1 = new DDC2759Category();
32
        $category2 = new DDC2759Category();
33
34
        $metadataCategory1 = new DDC2759MetadataCategory($qualificationMetadata, $category1);
35
        $metadataCategory2 = new DDC2759MetadataCategory($qualificationMetadata, $category2);
36
37
        $this->_em->persist($qualification);
38
        $this->_em->persist($qualificationMetadata);
39
40
        $this->_em->persist($category1);
41
        $this->_em->persist($category2);
42
43
        $this->_em->persist($metadataCategory1);
44
        $this->_em->persist($metadataCategory2);
45
46
        $this->_em->flush();
47
        $this->_em->clear();
48
    }
49
50
    public function testCorrectNumberOfAssociationsIsReturned()
51
    {
52
        $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC2759Qualification');
53
54
        $builder = $repository->createQueryBuilder('q')
55
            ->select('q, qm, qmc')
56
            ->innerJoin('q.metadata', 'qm')
57
            ->innerJoin('qm.metadataCategories', 'qmc');
58
59
        $result = $builder->getQuery()
60
            ->getArrayResult();
61
62
        $this->assertCount(2, $result[0]['metadata']['metadataCategories']);
63
    }
64
}
65
66
/** @Entity  @Table(name="ddc_2759_qualification") */
67
class DDC2759Qualification
68
{
69
    /** @Id @Column(type="integer") @GeneratedValue */
70
    public $id;
71
72
    /** @OneToOne(targetEntity="DDC2759QualificationMetadata", mappedBy="content") */
73
    public $metadata;
74
}
75
76
/** @Entity  @Table(name="ddc_2759_category") */
77
class DDC2759Category
78
{
79
    /** @Id @Column(type="integer") @GeneratedValue */
80
    public $id;
81
82
    /** @OneToMany(targetEntity="DDC2759MetadataCategory", mappedBy="category") */
83
    public $metadataCategories;
84
}
85
86
/** @Entity  @Table(name="ddc_2759_qualification_metadata") */
87
class DDC2759QualificationMetadata
88
{
89
    /** @Id @Column(type="integer") @GeneratedValue */
90
    public $id;
91
92
    /** @OneToOne(targetEntity="DDC2759Qualification", inversedBy="metadata") */
93
    public $content;
94
95
    /** @OneToMany(targetEntity="DDC2759MetadataCategory", mappedBy="metadata") */
96
    protected $metadataCategories;
97
98
    public function __construct(DDC2759Qualification $content)
99
    {
100
        $this->content = $content;
101
    }
102
}
103
104
/** @Entity  @Table(name="ddc_2759_metadata_category") */
105
class DDC2759MetadataCategory
106
{
107
    /** @Id @Column(type="integer") @GeneratedValue */
108
    public $id;
109
110
    /** @ManyToOne(targetEntity="DDC2759QualificationMetadata", inversedBy="metadataCategories") */
111
    public $metadata;
112
113
    /** @ManyToOne(targetEntity="DDC2759Category", inversedBy="metadataCategories") */
114
    public $category;
115
116
    public function __construct(DDC2759QualificationMetadata $metadata, DDC2759Category $category)
117
    {
118
        $this->metadata = $metadata;
119
        $this->category = $category;
120
    }
121
}
122