Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Avoid calling deprecated Platform->getName() #522

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Snapshot;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SqlitePlatform as DoctrineSQLitePlatform;

/**
* Implement the database snapshot and callback logic.
Expand Down Expand Up @@ -61,7 +62,7 @@ private function __construct(string $sqliteDir, string $identifier)
*/
public function create(DatabaseAccessor $accessor, Connection $connection): void
{
if ($connection->getDatabasePlatform()->getName() === 'sqlite') {
if ($connection->getDatabasePlatform() instanceof DoctrineSQLitePlatform) {
// With sqlite, we simply copy the db-file to a different place
$connection->close();
copy(
Expand All @@ -87,7 +88,7 @@ public function create(DatabaseAccessor $accessor, Connection $connection): void
*/
public function restore(DatabaseAccessor $accessor, Connection $connection): void
{
if ($connection->getDatabasePlatform()->getName() === 'sqlite') {
if ($connection->getDatabasePlatform() instanceof DoctrineSQLitePlatform) {
$connection->close();
copy(
$this->sqliteDir . 'test_' . $this->identifier . '.snapshot.sqlite',
Expand Down
4 changes: 2 additions & 2 deletions Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform as DoctrinePostgreSQLPlatform;
use PHPUnit\Framework\ExpectationFailedException;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -855,7 +855,7 @@ protected function setUpFrontendRootPage(int $pageId, array $typoScriptFiles = [
}
// @todo: Check if this constant is still needed
$databasePlatform = 'mysql';
if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
if ($connection->getDatabasePlatform() instanceof DoctrinePostgreSQLPlatform) {
$databasePlatform = 'postgresql';
}
$templateFields['constants'] .= 'databasePlatform = ' . $databasePlatform . LF;
Expand Down
17 changes: 10 additions & 7 deletions Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\MariaDBPlatform as DoctrineMariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform as DoctrineMySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform as DoctrinePostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform as DoctrineSQLitePlatform;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use TYPO3\CMS\Core\Core\Bootstrap;
Expand Down Expand Up @@ -662,8 +663,10 @@ public function setUpTestDatabase(string $databaseName, string $originalDatabase
unset($connectionParameters['dbname']);
$connection = DriverManager::getConnection($connectionParameters);
$schemaManager = $connection->createSchemaManager();
$platform = $connection->getDatabasePlatform();
$isSQLite = $platform instanceof DoctrineSQLitePlatform;

if ($connection->getDatabasePlatform()->getName() === 'sqlite') {
if ($isSQLite) {
// This is the "path" option in sqlite: one file = one db
$schemaManager->dropDatabase($databaseName);
} elseif (in_array($databaseName, $schemaManager->listDatabases(), true)) {
Expand Down Expand Up @@ -742,7 +745,7 @@ public function initializeTestDatabaseAndTruncateTables(string $dbPathSqlite = '
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
$platform = $connection->getDatabasePlatform();
if ($platform instanceof MySQLPlatform) {
if ($platform instanceof DoctrineMariaDBPlatform || $platform instanceof DoctrineMySQLPlatform) {
$this->truncateAllTablesForMysql();
} else {
$this->truncateAllTablesForOtherDatabases();
Expand Down Expand Up @@ -866,7 +869,7 @@ public function createDatabaseStructure(ContainerInterface $container): void
public static function resetTableSequences(Connection $connection, string $tableName): void
{
$platform = $connection->getDatabasePlatform();
if ($platform instanceof PostgreSqlPlatform) {
if ($platform instanceof DoctrinePostgreSQLPlatform) {
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();
$row = $queryBuilder->select('PGT.schemaname', 'S.relname', 'C.attname', 'T.relname AS tablename')
Expand Down Expand Up @@ -897,7 +900,7 @@ public static function resetTableSequences(Connection $connection, string $table
)
);
}
} elseif ($platform instanceof SqlitePlatform) {
} elseif ($platform instanceof DoctrineSQLitePlatform) {
// Drop eventually existing sqlite sequence for this table
$connection->executeStatement(
sprintf(
Expand Down