Passed
Pull Request — master (#7468)
by Caio
12:28
created

DDC3740Test::testCountIsCached()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\Common\Collections\Criteria;
8
use Doctrine\ORM\LazyCriteriaCollection;
9
use Doctrine\Tests\Models\Tweet\Tweet;
10
use Doctrine\Tests\Models\Tweet\User as TweetUser;
11
use Doctrine\Tests\OrmFunctionalTestCase;
12
13
class DDC3740Test extends OrmFunctionalTestCase
14
{
15
    /** @var LazyCriteriaCollection */
16
    private $lazyCriteriaCollection;
17
18
    protected function setUp() : void
19
    {
20
        $this->useModelSet('tweet');
21
        parent::setUp();
22
23
        $this->lazyCriteriaCollection = new LazyCriteriaCollection(
24
            $this->em->getUnitOfWork()->getEntityPersister(Tweet::class),
25
            new Criteria()
26
        );
27
    }
28
29
    public function testCountIsCached() : void
30
    {
31
        $user       = new TweetUser();
32
        $user->name = 'Caio';
33
34
        $tweet          = new Tweet();
35
        $tweet->content = 'I am a teapot!';
36
37
        $user->addTweet($tweet);
38
39
        $this->em->persist($user);
40
        $this->em->persist($tweet);
41
        $this->em->flush();
42
        $this->em->clear();
43
44
        self::assertSame(1, $this->lazyCriteriaCollection->count());
45
        self::assertSame(1, $this->lazyCriteriaCollection->count());
46
        self::assertSame(1, $this->lazyCriteriaCollection->count());
47
    }
48
49
    public function testCountIsCachedEvenWithZeroResult() : void
50
    {
51
        self::assertSame(0, $this->lazyCriteriaCollection->count());
52
        self::assertSame(0, $this->lazyCriteriaCollection->count());
53
        self::assertSame(0, $this->lazyCriteriaCollection->count());
54
    }
55
}
56