File: DDC7969Test.php

package info (click to toggle)
doctrine 3.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,556 kB
  • sloc: php: 108,620; xml: 1,340; makefile: 35; sh: 14
file content (46 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (3)
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
<?php

declare(strict_types=1);

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

use Doctrine\Tests\Models\Cache\Attraction;
use Doctrine\Tests\Models\Cache\Bar;
use Doctrine\Tests\ORM\Functional\SecondLevelCacheFunctionalTestCase;

use function assert;

class DDC7969Test extends SecondLevelCacheFunctionalTestCase
{
    public function testChildEntityRetrievedFromCache(): void
    {
        $this->loadFixturesCountries();
        $this->loadFixturesStates();
        $this->loadFixturesCities();
        $this->loadFixturesAttractions();

        // Entities are already cached due to fixtures - hence flush before testing
        $this->cache->getEntityCacheRegion(Attraction::class)->evictAll();

        $bar = $this->attractions[0];
        assert($bar instanceof Bar);

        $repository = $this->_em->getRepository(Bar::class);

        self::assertFalse($this->cache->containsEntity(Bar::class, $bar->getId()));
        self::assertFalse($this->cache->containsEntity(Attraction::class, $bar->getId()));

        $repository->findOneBy([
            'name' => $bar->getName(),
        ]);

        self::assertTrue($this->cache->containsEntity(Bar::class, $bar->getId()));

        $repository->findOneBy([
            'name' => $bar->getName(),
        ]);

        // One hit for entity cache, one hit for query cache
        self::assertEquals(2, $this->secondLevelCacheLogger->getHitCount());
    }
}