Passed
Pull Request — master (#6740)
by Mathieu
15:42
created

DDC288Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 9.0856
c 1
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
7
use Doctrine\Tests\Models\ECommerce\ECommerceCategory;
8
use Doctrine\Common\Collections\Criteria;
9
10
class DDC288Test extends OrmFunctionalTestCase
11
{
12
    private $firstProduct;
13
    private $secondProduct;
0 ignored issues
show
Unused Code introduced by
The property $secondProduct is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
    private $firstCategory;
15
    private $secondCategory;
16
17
    public function setUp()
18
    {
19
        $this->useModelSet('ecommerce');
20
        parent::setUp();
21
22
        $this->firstProduct = new ECommerceProduct();
23
        $this->firstProduct->setName("First Product");
24
25
        $this->firstCategory = new ECommerceCategory();
26
        $this->firstCategory->setName("Business");
27
28
29
        $this->secondCategory = new ECommerceCategory();
30
        $this->secondCategory->setName("Home");
31
32
        $this->firstProduct->addCategory($this->firstCategory);
33
        $this->firstProduct->addCategory($this->secondCategory);
34
35
        $this->_em->persist($this->firstProduct);
36
37
        $this->_em->flush();
38
        $this->_em->clear();
39
    }
40
41 View Code Duplication
    public function testCollectionFilteringLteOperator()
42
    {
43
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
44
45
        $criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategory->getId()));
46
47
        $this->assertCount(2, $firstProduct->getCategories()->matching($criteria));
48
    }
49
50 View Code Duplication
    public function testCollectionFilteringLtOperator()
51
    {
52
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
53
54
        $criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategory->getId()));
55
56
        $this->assertCount(1, $firstProduct->getCategories()->matching($criteria));
57
    }
58
59 View Code Duplication
    public function testCollectionFilteringGteOperator()
60
    {
61
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
62
63
        $criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategory->getId()));
64
65
        $this->assertCount(2, $firstProduct->getCategories()->matching($criteria));
66
    }
67
68 View Code Duplication
    public function testCollectionFilteringGtOperator()
69
    {
70
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
71
72
        $criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategory->getId()));
73
74
        $this->assertCount(1, $firstProduct->getCategories()->matching($criteria));
75
    }
76
77 View Code Duplication
    public function testCollectionFilteringEqualsOperator()
78
    {
79
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
80
81
        $criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategory->getId()));
82
83
        $this->assertCount(1, $firstProduct->getCategories()->matching($criteria));
84
    }
85
}
86