|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; |
| 6 | + |
| 7 | +use Doctrine\ORM\PersistentCollection; |
| 8 | +use Doctrine\Persistence\Proxy; |
| 9 | +use Doctrine\Tests\OrmFunctionalTestCase; |
| 10 | + |
| 11 | +class GH11149Test extends OrmFunctionalTestCase |
| 12 | +{ |
| 13 | + protected function setUp(): void |
| 14 | + { |
| 15 | + parent::setUp(); |
| 16 | + |
| 17 | + $this->setUpEntitySchema([ |
| 18 | + Locale::class, |
| 19 | + EagerProduct::class, |
| 20 | + EagerProductTranslation::class, |
| 21 | + ]); |
| 22 | + } |
| 23 | + |
| 24 | + public function testFetchEagerModeWithIndexBy(): void |
| 25 | + { |
| 26 | + // Load entities into database |
| 27 | + $this->_em->persist($product = new EagerProduct(11149)); |
| 28 | + $this->_em->persist($locale = new Locale('fr_FR')); |
| 29 | + $this->_em->persist(new EagerProductTranslation(11149, $product, $locale)); |
| 30 | + $this->_em->flush(); |
| 31 | + $this->_em->clear(); |
| 32 | + |
| 33 | + // Fetch entity from database |
| 34 | + $product = $this->_em->find(EagerProduct::class, 11149); |
| 35 | + |
| 36 | + // Assert associated entity is loaded eagerly |
| 37 | + static::assertInstanceOf(EagerProduct::class, $product); |
| 38 | + static::assertInstanceOf(PersistentCollection::class, $product->translations); |
| 39 | + static::assertTrue($product->translations->isInitialized()); |
| 40 | + static::assertCount(1, $product->translations); |
| 41 | + |
| 42 | + // Assert associated entity is indexed by given property |
| 43 | + $translation = $product->translations->get('fr_FR'); |
| 44 | + static::assertInstanceOf(EagerProductTranslation::class, $translation); |
| 45 | + static::assertNotInstanceOf(Proxy::class, $translation); |
| 46 | + } |
| 47 | +} |
0 commit comments