/** * @test */ public function getServerVersionReportsPlatformVersion() { /** @var MysqliConnection|ObjectProphecy $driverProphet */ $driverProphet = $this->prophesize(\Doctrine\DBAL\Driver\Mysqli\Driver::class); $driverProphet->willImplement(\Doctrine\DBAL\VersionAwarePlatformDriver::class); /** @var MysqliConnection|ObjectProphecy $wrappedConnectionProphet */ $wrappedConnectionProphet = $this->prophesize(\Doctrine\DBAL\Driver\Mysqli\MysqliConnection::class); $wrappedConnectionProphet->willImplement(\Doctrine\DBAL\Driver\ServerInfoAwareConnection::class); $wrappedConnectionProphet->requiresQueryForServerVersion()->willReturn(false); $wrappedConnectionProphet->getServerVersion()->willReturn('5.7.11'); $this->connection->expects($this->any())->method('getDriver')->willReturn($driverProphet->reveal()); $this->connection->expects($this->any())->method('getWrappedConnection')->willReturn($wrappedConnectionProphet->reveal()); $this->assertSame('mock 5.7.11', $this->connection->getServerVersion()); }
/** * Get COLLATION, ROW_FORMAT, COMMENT and ENGINE table options on MySQL connections. * * @param string[] $tableNames * @return array[] * @throws \InvalidArgumentException */ protected function getTableOptions(array $tableNames) : array { $tableOptions = []; if (strpos($this->connection->getServerVersion(), 'MySQL') !== 0) { foreach ($tableNames as $tableName) { $tableOptions[$tableName] = []; } return $tableOptions; } $queryBuilder = $this->connection->createQueryBuilder(); $result = $queryBuilder->select('TABLE_NAME AS table', 'ENGINE AS engine', 'ROW_FORMAT AS row_format', 'TABLE_COLLATION AS collate', 'TABLE_COMMENT AS comment')->from('information_schema.TABLES')->where($queryBuilder->expr()->eq('TABLE_TYPE', $queryBuilder->createNamedParameter('BASE TABLE', \PDO::PARAM_STR)), $queryBuilder->expr()->eq('TABLE_SCHEMA', $queryBuilder->createNamedParameter($this->connection->getDatabase(), \PDO::PARAM_STR)))->execute(); while ($row = $result->fetch()) { $index = $row['table']; unset($row['table']); $tableOptions[$index] = $row; } return $tableOptions; }
/** * This database backend uses some optimized queries for mysql * to get maximum performance. * * @param Connection $connection * @return bool */ protected function isConnectionMysql(Connection $connection) : bool { $serverVersion = $connection->getServerVersion(); return (bool) (strpos($serverVersion, 'MySQL') === 0); }