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; |
|
|
|
|
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
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.