@@ 215-263 (lines=49) @@ | ||
212 | * SELECT PARTIAL u.{id, name} AS user, PARTIAL a.{id, topic} |
|
213 | * FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a |
|
214 | */ |
|
215 | public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() |
|
216 | { |
|
217 | $rsm = new ResultSetMapping; |
|
218 | ||
219 | $rsm->addEntityResult(CmsUser::class, 'u', 'user'); |
|
220 | $rsm->addEntityResult(CmsArticle::class, 'a'); |
|
221 | $rsm->addFieldResult('u', 'u__id', 'id'); |
|
222 | $rsm->addFieldResult('u', 'u__name', 'name'); |
|
223 | $rsm->addFieldResult('a', 'a__id', 'id'); |
|
224 | $rsm->addFieldResult('a', 'a__topic', 'topic'); |
|
225 | ||
226 | // Faked result set |
|
227 | $resultSet = [ |
|
228 | [ |
|
229 | 'u__id' => '1', |
|
230 | 'u__name' => 'romanb', |
|
231 | 'a__id' => '1', |
|
232 | 'a__topic' => 'Cool things.' |
|
233 | ], |
|
234 | [ |
|
235 | 'u__id' => '2', |
|
236 | 'u__name' => 'jwage', |
|
237 | 'a__id' => '2', |
|
238 | 'a__topic' => 'Cool things II.' |
|
239 | ] |
|
240 | ]; |
|
241 | ||
242 | $stmt = new HydratorMockStatement($resultSet); |
|
243 | $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->em); |
|
244 | $result = $hydrator->hydrateAll($stmt, $rsm); |
|
245 | ||
246 | self::assertCount(4, $result); |
|
247 | ||
248 | self::assertArrayHasKey('user', $result[0]); |
|
249 | self::assertEquals(1, $result[0]['user']['id']); |
|
250 | self::assertEquals('romanb', $result[0]['user']['name']); |
|
251 | ||
252 | self::assertArrayHasKey(0, $result[1]); |
|
253 | self::assertEquals(1, $result[1][0]['id']); |
|
254 | self::assertEquals('Cool things.', $result[1][0]['topic']); |
|
255 | ||
256 | self::assertArrayHasKey('user', $result[2]); |
|
257 | self::assertEquals(2, $result[2]['user']['id']); |
|
258 | self::assertEquals('jwage', $result[2]['user']['name']); |
|
259 | ||
260 | self::assertArrayHasKey(0, $result[3]); |
|
261 | self::assertEquals(2, $result[3][0]['id']); |
|
262 | self::assertEquals('Cool things II.', $result[3][0]['topic']); |
|
263 | } |
|
264 | ||
265 | /** |
|
266 | * SELECT PARTIAL u.{id, name}, PARTIAL a.{id, topic} AS article |
|
@@ 269-317 (lines=49) @@ | ||
266 | * SELECT PARTIAL u.{id, name}, PARTIAL a.{id, topic} AS article |
|
267 | * FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a |
|
268 | */ |
|
269 | public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() |
|
270 | { |
|
271 | $rsm = new ResultSetMapping; |
|
272 | ||
273 | $rsm->addEntityResult(CmsUser::class, 'u'); |
|
274 | $rsm->addEntityResult(CmsArticle::class, 'a', 'article'); |
|
275 | $rsm->addFieldResult('u', 'u__id', 'id'); |
|
276 | $rsm->addFieldResult('u', 'u__name', 'name'); |
|
277 | $rsm->addFieldResult('a', 'a__id', 'id'); |
|
278 | $rsm->addFieldResult('a', 'a__topic', 'topic'); |
|
279 | ||
280 | // Faked result set |
|
281 | $resultSet = [ |
|
282 | [ |
|
283 | 'u__id' => '1', |
|
284 | 'u__name' => 'romanb', |
|
285 | 'a__id' => '1', |
|
286 | 'a__topic' => 'Cool things.' |
|
287 | ], |
|
288 | [ |
|
289 | 'u__id' => '2', |
|
290 | 'u__name' => 'jwage', |
|
291 | 'a__id' => '2', |
|
292 | 'a__topic' => 'Cool things II.' |
|
293 | ] |
|
294 | ]; |
|
295 | ||
296 | $stmt = new HydratorMockStatement($resultSet); |
|
297 | $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->em); |
|
298 | $result = $hydrator->hydrateAll($stmt, $rsm); |
|
299 | ||
300 | self::assertCount(4, $result); |
|
301 | ||
302 | self::assertArrayHasKey(0, $result[0]); |
|
303 | self::assertEquals(1, $result[0][0]['id']); |
|
304 | self::assertEquals('romanb', $result[0][0]['name']); |
|
305 | ||
306 | self::assertArrayHasKey('article', $result[1]); |
|
307 | self::assertEquals(1, $result[1]['article']['id']); |
|
308 | self::assertEquals('Cool things.', $result[1]['article']['topic']); |
|
309 | ||
310 | self::assertArrayHasKey(0, $result[2]); |
|
311 | self::assertEquals(2, $result[2][0]['id']); |
|
312 | self::assertEquals('jwage', $result[2][0]['name']); |
|
313 | ||
314 | self::assertArrayHasKey('article', $result[3]); |
|
315 | self::assertEquals(2, $result[3]['article']['id']); |
|
316 | self::assertEquals('Cool things II.', $result[3]['article']['topic']); |
|
317 | } |
|
318 | ||
319 | /** |
|
320 | * SELECT PARTIAL u.{id, name} AS user, PARTIAL a.{id, topic} AS article |
|
@@ 323-371 (lines=49) @@ | ||
320 | * SELECT PARTIAL u.{id, name} AS user, PARTIAL a.{id, topic} AS article |
|
321 | * FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a |
|
322 | */ |
|
323 | public function testSimpleMultipleRootEntityQueryWithAliasedEntities() |
|
324 | { |
|
325 | $rsm = new ResultSetMapping; |
|
326 | ||
327 | $rsm->addEntityResult(CmsUser::class, 'u', 'user'); |
|
328 | $rsm->addEntityResult(CmsArticle::class, 'a', 'article'); |
|
329 | $rsm->addFieldResult('u', 'u__id', 'id'); |
|
330 | $rsm->addFieldResult('u', 'u__name', 'name'); |
|
331 | $rsm->addFieldResult('a', 'a__id', 'id'); |
|
332 | $rsm->addFieldResult('a', 'a__topic', 'topic'); |
|
333 | ||
334 | // Faked result set |
|
335 | $resultSet = [ |
|
336 | [ |
|
337 | 'u__id' => '1', |
|
338 | 'u__name' => 'romanb', |
|
339 | 'a__id' => '1', |
|
340 | 'a__topic' => 'Cool things.' |
|
341 | ], |
|
342 | [ |
|
343 | 'u__id' => '2', |
|
344 | 'u__name' => 'jwage', |
|
345 | 'a__id' => '2', |
|
346 | 'a__topic' => 'Cool things II.' |
|
347 | ] |
|
348 | ]; |
|
349 | ||
350 | $stmt = new HydratorMockStatement($resultSet); |
|
351 | $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->em); |
|
352 | $result = $hydrator->hydrateAll($stmt, $rsm); |
|
353 | ||
354 | self::assertCount(4, $result); |
|
355 | ||
356 | self::assertArrayHasKey('user', $result[0]); |
|
357 | self::assertEquals(1, $result[0]['user']['id']); |
|
358 | self::assertEquals('romanb', $result[0]['user']['name']); |
|
359 | ||
360 | self::assertArrayHasKey('article', $result[1]); |
|
361 | self::assertEquals(1, $result[1]['article']['id']); |
|
362 | self::assertEquals('Cool things.', $result[1]['article']['topic']); |
|
363 | ||
364 | self::assertArrayHasKey('user', $result[2]); |
|
365 | self::assertEquals(2, $result[2]['user']['id']); |
|
366 | self::assertEquals('jwage', $result[2]['user']['name']); |
|
367 | ||
368 | self::assertArrayHasKey('article', $result[3]); |
|
369 | self::assertEquals(2, $result[3]['article']['id']); |
|
370 | self::assertEquals('Cool things II.', $result[3]['article']['topic']); |
|
371 | } |
|
372 | ||
373 | /** |
|
374 | * SELECT PARTIAL u.{id, status}, COUNT(p.phonenumber) AS numPhones |