|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
8
|
|
|
use Doctrine\ORM\Mapping\FetchMode; |
|
9
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceCategory; |
|
10
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Tests sorting mechanism of Selectable::matching() |
|
14
|
|
|
*/ |
|
15
|
|
|
class OneToManyMatchingCriteriaTest extends OrmFunctionalTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
private $parent; |
|
18
|
|
|
private $firstChild; |
|
19
|
|
|
private $secondChild; |
|
20
|
|
|
private $thirdChild; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() : void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->useModelSet('ecommerce'); |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
$this->parent = new ECommerceCategory(); |
|
27
|
|
|
$this->parent->setName('Programming languages books'); |
|
28
|
|
|
$this->firstChild = new ECommerceCategory(); |
|
29
|
|
|
$this->firstChild->setName('Java books'); |
|
30
|
|
|
$this->secondChild = new ECommerceCategory(); |
|
31
|
|
|
$this->secondChild->setName('Php books'); |
|
32
|
|
|
$this->thirdChild = new ECommerceCategory(); |
|
33
|
|
|
$this->thirdChild->setName('BBQ books'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testMatchingWithNoOrderingUsesDatabaseDefault() : void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->createFixture(); |
|
39
|
|
|
|
|
40
|
|
|
$metadata = $this->em->getClassMetadata(ECommerceCategory::class); |
|
41
|
|
|
$metadata->getProperty('children')->setFetchMode(FetchMode::LAZY); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$query = $this->em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCategory c order by c.id asc'); |
|
44
|
|
|
$result = $query->getResult(); |
|
45
|
|
|
$parent = $result[0]; |
|
46
|
|
|
$children = $parent->getChildren()->matching(Criteria::create()); |
|
47
|
|
|
$this->assertEquals('Java books', $children[0]->getName()); |
|
48
|
|
|
$this->assertEquals('Php books', $children[1]->getName()); |
|
49
|
|
|
$this->assertEquals('BBQ books', $children[2]->getName()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testMatchingRespectsCollectionOrdering() : void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->createFixture(); |
|
55
|
|
|
|
|
56
|
|
|
$metadata = $this->em->getClassMetadata(ECommerceCategory::class); |
|
57
|
|
|
$metadata->getProperty('children')->setFetchMode(FetchMode::LAZY); |
|
58
|
|
|
$metadata->getProperty('children')->setOrderBy(['name' => 'DESC']); |
|
59
|
|
|
|
|
60
|
|
|
$query = $this->em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCategory c order by c.id asc'); |
|
61
|
|
|
$result = $query->getResult(); |
|
62
|
|
|
$parent = $result[0]; |
|
63
|
|
|
$children = $parent->getChildren()->matching(Criteria::create()); |
|
64
|
|
|
$this->assertEquals('Php books', $children[0]->getName()); |
|
65
|
|
|
$this->assertEquals('Java books', $children[1]->getName()); |
|
66
|
|
|
$this->assertEquals('BBQ books', $children[2]->getName()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testMatchingOverrulesCollectionOrdering() : void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->createFixture(); |
|
72
|
|
|
|
|
73
|
|
|
$metadata = $this->em->getClassMetadata(ECommerceCategory::class); |
|
74
|
|
|
$metadata->getProperty('children')->setFetchMode(FetchMode::LAZY); |
|
75
|
|
|
$metadata->getProperty('children')->setOrderBy(['name' => 'DESC']); |
|
76
|
|
|
|
|
77
|
|
|
$query = $this->em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCategory c order by c.id asc'); |
|
78
|
|
|
$result = $query->getResult(); |
|
79
|
|
|
$parent = $result[0]; |
|
80
|
|
|
$children = $parent->getChildren()->matching(Criteria::create()->orderBy(['name' => 'ASC'])); |
|
81
|
|
|
$this->assertEquals('BBQ books', $children[0]->getName()); |
|
82
|
|
|
$this->assertEquals('Java books', $children[1]->getName()); |
|
83
|
|
|
$this->assertEquals('Php books', $children[2]->getName()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private function createFixture() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->parent->addChild($this->firstChild); |
|
89
|
|
|
$this->parent->addChild($this->secondChild); |
|
90
|
|
|
$this->parent->addChild($this->thirdChild); |
|
91
|
|
|
$this->em->persist($this->parent); |
|
92
|
|
|
|
|
93
|
|
|
$this->em->flush(); |
|
94
|
|
|
$this->em->clear(); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.