File: GH11149Test.php

package info (click to toggle)
doctrine 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 11,236 kB
  • sloc: php: 105,633; xml: 1,312; makefile: 35; sh: 14
file content (47 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149;

use Doctrine\ORM\PersistentCollection;
use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH11149Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEntitySchema([
            Locale::class,
            EagerProduct::class,
            EagerProductTranslation::class,
        ]);
    }

    public function testFetchEagerModeWithIndexBy(): void
    {
        // Load entities into database
        $this->_em->persist($product = new EagerProduct(11149));
        $this->_em->persist($locale = new Locale('fr_FR'));
        $this->_em->persist(new EagerProductTranslation(11149, $product, $locale));
        $this->_em->flush();
        $this->_em->clear();

        // Fetch entity from database
        $product = $this->_em->find(EagerProduct::class, 11149);

        // Assert associated entity is loaded eagerly
        static::assertInstanceOf(EagerProduct::class, $product);
        static::assertInstanceOf(PersistentCollection::class, $product->translations);
        static::assertTrue($product->translations->isInitialized());
        static::assertCount(1, $product->translations);

        // Assert associated entity is indexed by given property
        $translation = $product->translations->get('fr_FR');
        static::assertInstanceOf(EagerProductTranslation::class, $translation);
        static::assertNotInstanceOf(Proxy::class, $translation);
    }
}