Completed
Push — master ( dda42f...dfc31b )
by Luís
17s
created

GH6740Test::testCollectionFilteringGtOperator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 6
loc 6
rs 9.4285
c 1
b 0
f 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
final class GH6740Test extends OrmFunctionalTestCase
11
{
12
    /**
13
     * @var int
14
     */
15
    private $productId;
16
17
    /**
18
     * @var int
19
     */
20
    private $firstCategoryId;
21
22
    /**
23
     * @var int
24
     */
25
    private $secondCategoryId;
26
27
    public function setUp() : void
28
    {
29
        $this->useModelSet('ecommerce');
30
31
        parent::setUp();
32
33
        $product = new ECommerceProduct();
34
        $product->setName('First Product');
35
36
        $firstCategory  = new ECommerceCategory();
37
        $secondCategory = new ECommerceCategory();
38
39
        $firstCategory->setName('Business');
40
        $secondCategory->setName('Home');
41
42
        $product->addCategory($firstCategory);
43
        $product->addCategory($secondCategory);
44
45
        $this->_em->persist($product);
46
        $this->_em->flush();
47
        $this->_em->clear();
48
49
        $this->productId        = $product->getId();
50
        $this->firstCategoryId  = $firstCategory->getId();
51
        $this->secondCategoryId = $secondCategory->getId();
52
    }
53
54
    /**
55
     * @group 6740
56
     */
57 View Code Duplication
    public function testCollectionFilteringLteOperator() : void
58
    {
59
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
60
        $criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategoryId));
61
62
        self::assertCount(2, $product->getCategories()->matching($criteria));
63
    }
64
65
    /**
66
     * @group 6740
67
     */
68 View Code Duplication
    public function testCollectionFilteringLtOperator() : void
69
    {
70
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
71
        $criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategoryId));
72
73
        self::assertCount(1, $product->getCategories()->matching($criteria));
74
    }
75
76
    /**
77
     * @group 6740
78
     */
79 View Code Duplication
    public function testCollectionFilteringGteOperator() : void
80
    {
81
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
82
        $criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategoryId));
83
84
        self::assertCount(2, $product->getCategories()->matching($criteria));
85
    }
86
87
    /**
88
     * @group 6740
89
     */
90 View Code Duplication
    public function testCollectionFilteringGtOperator() : void
91
    {
92
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
93
        $criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategoryId));
94
95
        self::assertCount(1, $product->getCategories()->matching($criteria));
96
    }
97
98
    /**
99
     * @group 6740
100
     */
101 View Code Duplication
    public function testCollectionFilteringEqualsOperator() : void
102
    {
103
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
104
        $criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategoryId));
105
106
        self::assertCount(1, $product->getCategories()->matching($criteria));
107
    }
108
}
109