|
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
|
|
|
|