1 | <?php |
||
33 | class ProxyQueryTest extends TestCase |
||
34 | { |
||
35 | /** |
||
36 | * @var EntityManager |
||
37 | */ |
||
38 | private $em; |
||
39 | |||
40 | public static function setUpBeforeClass(): void |
||
46 | |||
47 | protected function setUp(): void |
||
66 | |||
67 | protected function tearDown(): void |
||
71 | |||
72 | public function dataGetFixedQueryBuilder() |
||
81 | |||
82 | /** |
||
83 | * @dataProvider dataGetFixedQueryBuilder |
||
84 | * |
||
85 | * @param $class |
||
86 | * @param $alias |
||
87 | * @param $id |
||
88 | */ |
||
89 | public function testGetFixedQueryBuilder($class, $alias, $id, $expectedId, $value, $identifierType): void |
||
90 | { |
||
91 | $meta = $this->createMock(ClassMetadata::class); |
||
92 | $meta->expects($this->any()) |
||
93 | ->method('getIdentifierFieldNames') |
||
94 | ->willReturn([$id]); |
||
95 | $meta->expects($this->any()) |
||
96 | ->method('getTypeOfField') |
||
97 | ->willReturn($identifierType); |
||
98 | |||
99 | $mf = $this->createMock(ClassMetadataFactory::class); |
||
100 | $mf->expects($this->any()) |
||
101 | ->method('getMetadataFor') |
||
102 | ->with($this->equalTo($class)) |
||
103 | ->willReturn($meta); |
||
104 | |||
105 | $platform = $this->createMock(PostgreSqlPlatform::class); |
||
106 | |||
107 | $conn = $this->createMock(Connection::class); |
||
108 | $conn->expects($this->any()) |
||
109 | ->method('getDatabasePlatform') |
||
110 | ->willReturn($platform); |
||
111 | |||
112 | $em = $this->createMock(EntityManager::class); |
||
113 | $em->expects($this->any()) |
||
114 | ->method('getMetadataFactory') |
||
115 | ->willReturn($mf); |
||
116 | $em->expects($this->any()) |
||
117 | ->method('getConnection') |
||
118 | ->willReturn($conn); |
||
119 | |||
120 | // NEXT MAJOR: Replace this when dropping PHP < 5.6 |
||
121 | // $q = $this->createMock('PDOStatement'); |
||
122 | $q = $this->getMockBuilder('stdClass') |
||
123 | ->setMethods(['execute', 'setHint']) |
||
124 | ->getMock(); |
||
125 | $q->expects($this->once()) |
||
126 | ->method('setHint') |
||
127 | ->willReturn($q); |
||
128 | $q->expects($this->any()) |
||
129 | ->method('execute') |
||
130 | ->willReturn([[$id => $value]]); |
||
131 | |||
132 | $qb = $this->getMockBuilder(QueryBuilder::class) |
||
133 | ->setConstructorArgs([$em]) |
||
134 | ->getMock(); |
||
135 | $qb->expects($this->any()) |
||
136 | ->method('getEntityManager') |
||
137 | ->willReturn($em); |
||
138 | $qb->expects($this->any()) |
||
139 | ->method('getQuery') |
||
140 | ->willReturn($q); |
||
141 | $qb->expects($this->once()) |
||
142 | ->method('setParameter') |
||
143 | ->with($this->equalTo($expectedId), $this->equalTo([$value])); |
||
144 | $qb->expects($this->any()) |
||
145 | ->method('getDQLPart') |
||
146 | ->will($this->returnCallBack(function ($part) use ($class, $alias) { |
||
147 | $parts = [ |
||
148 | 'from' => [new From($class, $alias)], |
||
149 | 'orderBy' => [new OrderBy('whatever', 'DESC')], |
||
150 | ]; |
||
151 | |||
152 | return $parts[$part]; |
||
153 | })); |
||
154 | $qb->expects($this->once()) |
||
155 | ->method('addOrderBy') |
||
156 | ->with("$alias.$id", null); |
||
157 | $qb->expects($this->once()) |
||
158 | ->method('getRootEntities') |
||
159 | ->willReturn([$class]); |
||
160 | $qb->expects($this->exactly(2)) |
||
161 | ->method('getRootAliases') |
||
162 | ->willReturn([$alias]); |
||
163 | |||
164 | $pq = $this->getMockBuilder(ProxyQuery::class) |
||
165 | ->setConstructorArgs([$qb]) |
||
166 | ->setMethods(['a']) |
||
167 | ->getMock(); |
||
168 | |||
169 | /* Work */ |
||
170 | |||
171 | $pq->execute(); |
||
172 | } |
||
173 | |||
174 | public function testSetHint() |
||
198 | |||
199 | public function testSortOrderValidatesItsInput() |
||
208 | |||
209 | public function validSortOrders() |
||
220 | |||
221 | /** |
||
222 | * @dataProvider validSortOrders |
||
223 | */ |
||
224 | public function testItAllowsSortOrdersWithStrangeCase($validValue) |
||
230 | } |
||
231 |