-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: don't call deprecated method getName() on doctrine platform
- Loading branch information
1 parent
0b936c0
commit 9ca61a2
Showing
1 changed file
with
31 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,23 @@ | |
|
||
namespace Liip\TestFixturesBundle\Services\DatabaseTools; | ||
|
||
use BadMethodCallException; | ||
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader; | ||
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; | ||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform; | ||
use Doctrine\DBAL\Platforms\SqlitePlatform; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Doctrine\Persistence\ObjectManager; | ||
use InvalidArgumentException; | ||
use Liip\TestFixturesBundle\Services\DatabaseBackup\DatabaseBackupInterface; | ||
use Liip\TestFixturesBundle\Services\FixturesLoaderFactory; | ||
use ReflectionClass; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use function get_class; | ||
use function is_string; | ||
|
||
/** | ||
* @author Aleksey Tupichenkov <[email protected]> | ||
|
@@ -58,10 +66,7 @@ abstract class AbstractDatabaseTool | |
*/ | ||
protected $om; | ||
|
||
/** | ||
* @var Connection | ||
*/ | ||
protected $connection; | ||
protected Connection $connection; | ||
|
||
/** | ||
* @var int|null | ||
|
@@ -158,21 +163,21 @@ public function loadAllFixtures(array $groups = []): ?AbstractExecutor | |
$loader = $this->container->get('test.service_container')->get('doctrine.fixtures.loader'); | ||
$fixtures = $loader->getFixtures($groups); | ||
foreach ($fixtures as $fixture) { | ||
$fixtureClasses[] = \get_class($fixture); | ||
$fixtureClasses[] = get_class($fixture); | ||
} | ||
} | ||
|
||
return $this->loadFixtures($fixtureClasses); | ||
} | ||
|
||
/** | ||
* @throws \BadMethodCallException | ||
* @throws BadMethodCallException | ||
*/ | ||
public function loadAliceFixture(array $paths = [], bool $append = false): array | ||
{ | ||
$persisterLoaderServiceName = 'fidry_alice_data_fixtures.loader.doctrine'; | ||
if (!$this->container->has($persisterLoaderServiceName)) { | ||
throw new \BadMethodCallException('theofidry/alice-data-fixtures must be installed to use this method.'); | ||
throw new BadMethodCallException('theofidry/alice-data-fixtures must be installed to use this method.'); | ||
} | ||
|
||
if (false === $append) { | ||
|
@@ -193,13 +198,13 @@ protected function getBackupService(): ?DatabaseBackupInterface | |
{ | ||
$backupServiceParamName = strtolower('liip_test_fixtures.cache_db.'.( | ||
('ORM' === $this->getType()) | ||
? $this->connection->getDatabasePlatform()->getName() | ||
? $this->getPlatformName() | ||
: $this->getType() | ||
)); | ||
|
||
if ($this->container->hasParameter($backupServiceParamName)) { | ||
$backupServiceName = $this->container->getParameter($backupServiceParamName); | ||
if (\is_string($backupServiceName) && $this->container->has($backupServiceName)) { | ||
if (is_string($backupServiceName) && $this->container->has($backupServiceName)) { | ||
$backupService = $this->container->get($backupServiceName); | ||
} else { | ||
@trigger_error("Could not find {$backupServiceName} in container. Possible misconfiguration."); | ||
|
@@ -217,7 +222,7 @@ protected function cleanDatabase(): void | |
/** | ||
* Locate fixture files. | ||
* | ||
* @throws \InvalidArgumentException if a wrong path is given outside a bundle | ||
* @throws InvalidArgumentException if a wrong path is given outside a bundle | ||
*/ | ||
protected function locateResources(array $paths): array | ||
{ | ||
|
@@ -228,7 +233,7 @@ protected function locateResources(array $paths): array | |
foreach ($paths as $path) { | ||
if ('@' !== $path[0]) { | ||
if (!file_exists($path)) { | ||
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $path)); | ||
throw new InvalidArgumentException(sprintf('Unable to find file "%s".', $path)); | ||
} | ||
$files[] = $path; | ||
|
||
|
@@ -270,4 +275,19 @@ protected function getCacheMetadataParameter() | |
return $this->container->hasParameter(self::CACHE_METADATA_PARAMETER_NAME) | ||
&& false !== $this->container->getParameter(self::CACHE_METADATA_PARAMETER_NAME); | ||
} | ||
|
||
private function getPlatformName(): string | ||
{ | ||
$platform = $this->connection->getDatabasePlatform(); | ||
|
||
if ($platform instanceof AbstractMySQLPlatform) { | ||
return 'mysql'; | ||
} elseif ($platform instanceof SqlitePlatform) { | ||
return 'sqlite'; | ||
} elseif ($platform instanceof PostgreSQLPlatform) { | ||
return 'pgsql'; | ||
} | ||
|
||
return (new ReflectionClass($platform))->getShortName(); | ||
} | ||
} |