From 106ae642f3f08783caa2447721c5e9655cc565f8 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 14 Sep 2020 10:51:04 +0200 Subject: [PATCH] MySQLi - max_prepared_stmt_count: Add failing test case --- tests/TDBMDaoGeneratorTest.php | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/TDBMDaoGeneratorTest.php b/tests/TDBMDaoGeneratorTest.php index c4bc19f2..26bd651a 100644 --- a/tests/TDBMDaoGeneratorTest.php +++ b/tests/TDBMDaoGeneratorTest.php @@ -22,6 +22,7 @@ namespace TheCodingMachine\TDBM; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\MySQL57Platform; @@ -2208,4 +2209,40 @@ public function testFindFromRawSQLOnInheritance(): void $this->assertNotNull($objects->first()); $this->assertEquals(6, $objects->count()); } + + public function testMysqlStatementCount(): void + { + if (! $this->tdbmService->getConnection()->getDriver() instanceof MySQLiDriver) { + $this->markTestSkipped('This test only applies for MySQLi driver.'); + } + + $this->tdbmService->getConnection()->exec('set global max_prepared_stmt_count = 2;'); + try { + $objectBaseDao = new BaseObjectDao($this->tdbmService); + $objectInheritedDao = new InheritedObjectDao($this->tdbmService); + + $objectBase = new BaseObjectBean('label-1'); + $objectBaseDao->save($objectBase); + $objectInherited = new InheritedObjectBean($objectBase); + $objectInheritedDao->save($objectInherited); + + $objectBase = new BaseObjectBean('label-2'); + $objectBaseDao->save($objectBase); + $objectInherited = new InheritedObjectBean($objectBase); + $objectInheritedDao->save($objectInherited); + + $objectBase = new BaseObjectBean('label-3'); + $objectBaseDao->save($objectBase); + $objectInherited = new InheritedObjectBean($objectBase); + $objectInheritedDao->save($objectInherited); + + $objects = $objectBaseDao->findAll(); + $this->assertGreaterThanOrEqual(3, $objects->count()); + foreach ($objects->take(0, 1) as $objectBean) { $objectBean->getInheritedObject()->getId(); } + foreach ($objects->take(1, 2) as $objectBean) { $objectBean->getInheritedObject()->getId(); } + foreach ($objects->take(2, 3) as $objectBean) { $objectBean->getInheritedObject()->getId(); } + } finally { + $this->tdbmService->getConnection()->exec('set global max_prepared_stmt_count = 16382;'); + } + } }