88use PDO ;
99use Pdo \Sqlite ;
1010use PDOStatement ;
11+ use PHPUnit \Framework \Attributes \DataProvider ;
1112use PHPUnit \Framework \TestCase ;
1213use RuntimeException ;
1314use Sloop \Database \Connection ;
@@ -527,7 +528,22 @@ public function testServerVersionCachesResultAcrossCalls(): void
527528 $ this ->assertSame ($ first , $ second );
528529 }
529530
530- public function testDialectAndServerVersionShareSingleSelectVersionQuery (): void
531+ /**
532+ * @return array<string, array{0: list<string>}>
533+ */
534+ public static function interleavedDialectAndServerVersionCallProvider (): array
535+ {
536+ return [
537+ 'serverVersion first ' => [['serverVersion ' , 'dialect ' , 'serverVersion ' , 'dialect ' ]],
538+ 'dialect first ' => [['dialect ' , 'serverVersion ' , 'dialect ' , 'serverVersion ' ]],
539+ ];
540+ }
541+
542+ /**
543+ * @param list<string> $callOrder
544+ */
545+ #[DataProvider('interleavedDialectAndServerVersionCallProvider ' )]
546+ public function testDialectAndServerVersionShareSingleSelectVersionQuery (array $ callOrder ): void
531547 {
532548 // Both getters are independently lazy via ??= but must share a single
533549 // `SELECT VERSION()` execution regardless of which is called first or
@@ -543,10 +559,13 @@ public function testDialectAndServerVersionShareSingleSelectVersionQuery(): void
543559
544560 $ connection = new Connection ($ pdo , 'test ' );
545561
546- $ connection ->serverVersion ();
547- $ connection ->dialect ();
548- $ connection ->serverVersion ();
549- $ connection ->dialect ();
562+ foreach ($ callOrder as $ method ) {
563+ if ($ method === 'dialect ' ) {
564+ $ connection ->dialect ();
565+ } else {
566+ $ connection ->serverVersion ();
567+ }
568+ }
550569
551570 $ this ->assertSame (Dialect::MariaDB, $ connection ->dialect ());
552571 $ this ->assertSame ('10.11.11-MariaDB ' , $ connection ->serverVersion ());
0 commit comments