Skip to content

Commit ee2c3a5

Browse files
authored
Merge pull request #12097 from mvorisek/add_fixed_id_insert_count_query_test
Add 2nd level cache test for insert without post-inserted ID
2 parents 04694a9 + 5b2060e commit ee2c3a5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/Tests/ORM/Functional/SecondLevelCacheCountQueriesTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Functional;
66

7+
use Doctrine\ORM\Id\AssignedGenerator;
78
use Doctrine\ORM\Mapping\ClassMetadata;
89
use Doctrine\ORM\Mapping\ClassMetadataInfo;
910
use Doctrine\Tests\Models\Cache\Country;
@@ -62,6 +63,24 @@ private function setupCountryModel(int $cacheUsage): void
6263
$metadata->enableCache(['usage' => $cacheUsage]);
6364
}
6465

66+
private function loadFixturesCountriesWithoutPostInsertIdentifier(): void
67+
{
68+
$metadata = $this->_em->getClassMetaData(Country::class);
69+
$metadata->setIdGenerator(new AssignedGenerator());
70+
71+
$c1 = new Country('Brazil');
72+
$c1->setId(10);
73+
$c2 = new Country('Germany');
74+
$c2->setId(20);
75+
76+
$this->countries[] = $c1;
77+
$this->countries[] = $c2;
78+
79+
$this->_em->persist($c1);
80+
$this->_em->persist($c2);
81+
$this->_em->flush();
82+
}
83+
6584
/** @param 'INSERT'|'UPDATE'|'DELETE' $type */
6685
private function assertQueryCountByType(string $type, int $expectedCount): void
6786
{
@@ -77,7 +96,7 @@ private function assertQueryCountByType(string $type, int $expectedCount): void
7796
*
7897
* @dataProvider cacheUsageProvider
7998
*/
80-
public function testInsert(int $cacheUsage): void
99+
public function testInsertWithPostInsertIdentifier(int $cacheUsage): void
81100
{
82101
$this->setupCountryModel($cacheUsage);
83102

@@ -89,6 +108,23 @@ public function testInsert(int $cacheUsage): void
89108
self::assertQueryCountByType('INSERT', 2);
90109
}
91110

111+
/**
112+
/* @param SupportedCacheUsage $cacheUsage
113+
*
114+
* @dataProvider cacheUsageProvider
115+
*/
116+
public function testInsertWithoutPostInsertIdentifier(int $cacheUsage): void
117+
{
118+
$this->setupCountryModel($cacheUsage);
119+
120+
self::assertQueryCountByType('INSERT', 0);
121+
122+
$this->loadFixturesCountriesWithoutPostInsertIdentifier();
123+
124+
self::assertCount(2, $this->countries);
125+
self::assertQueryCountByType('INSERT', 2);
126+
}
127+
92128
/**
93129
/* @param SupportedCacheUsage $cacheUsage
94130
*

0 commit comments

Comments
 (0)