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

DDC3740Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCountIsCachedEvenWithZeroResult() 0 5 1
A testCountIsCached() 0 18 1
A setUp() 0 8 1
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