Skip to content

Commit

Permalink
Drop support for DBAL 2 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
intranettus authored Mar 26, 2023
1 parent d369ad1 commit ebaf24e
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 98 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ Both traits provide several configuration options as protected static properties
* `self::$bundles`: The list of bundles where to look for fixtures
* `self::$append`: Append fixtures instead of purging
* `self::$purgeWithTruncate`: Use TRUNCATE to purge
* `self::$shard`: The name of the Doctrine shard to use
* `self::$connection`: The name of the Doctrine connection to use

Use them in the `setUpBeforeClass` method.
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
"phpunit/phpunit": "^9.5",
"phpspec/prophecy": "^1.7",
"symfony/phpunit-bridge": "^6.0",
"phpspec/prophecy-phpunit": "^2.0",
"doctrine/shards": "^1.0"
"phpspec/prophecy-phpunit": "^2.0"
},

"extra": {
Expand Down
30 changes: 0 additions & 30 deletions fixtures/Functional/TestBundle/Entity/Shard.php

This file was deleted.

1 change: 0 additions & 1 deletion fixtures/Loader/FakeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function load(
string $environment,
bool $append,
bool $purgeWithTruncate,
string $shard = null,
bool $noBundles = false
): array {
$this->__call(__METHOD__, func_get_args());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Append the data fixtures instead of deleting all data from the database first.'
)
->addOption(
'shard',
null,
InputOption::VALUE_REQUIRED,
'The shard database id to use for this command.'
)
->addOption(
'purge-with-truncate',
null,
Expand Down Expand Up @@ -149,13 +143,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$manager = $this->doctrine->getManager($input->getOption('manager'));
$environment = $input->getOption('env');
$shard = $input->getOption('shard');
$append = $input->getOption('append');
$truncate = $input->getOption('purge-with-truncate');
/** @var FrameworkBundleConsoleApplication $application */
$application = $this->getApplication();

$this->loader->load($application, $manager, $bundles, $environment, $append, $truncate, $shard, $noBundles);
$this->loader->load($application, $manager, $bundles, $environment, $append, $truncate, $noBundles);

return 0;
}
Expand Down
28 changes: 0 additions & 28 deletions src/Loader/DoctrineOrmLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
namespace Hautelook\AliceBundle\Loader;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Shards\DBAL\PoolingShardConnection;
use Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister;
use Fidry\AliceDataFixtures\LoaderInterface;
use Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface;
use Fidry\AliceDataFixtures\Persistence\PersisterInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use function get_class;
use Hautelook\AliceBundle\BundleResolverInterface;
use Hautelook\AliceBundle\FixtureLocatorInterface;
use Hautelook\AliceBundle\LoaderInterface as AliceBundleLoaderInterface;
Expand Down Expand Up @@ -96,7 +94,6 @@ public function load(
string $environment,
bool $append,
bool $purgeWithTruncate,
string $shard = null,
bool $noBundles = false
): array {
if ($append && $purgeWithTruncate) {
Expand All @@ -113,10 +110,6 @@ public function load(

$this->logger->info('fixtures found', ['files' => $fixtureFiles]);

if (null !== $shard) {
$this->connectToShardConnection($manager, $shard);
}

$purgeMode = $this->retrievePurgeMode($append, $purgeWithTruncate);

$fixtures = $this->loadFixtures(
Expand Down Expand Up @@ -157,27 +150,6 @@ protected function loadFixtures(
return $loader->load($files, $parameters, [], $purgeMode);
}

private function connectToShardConnection(EntityManagerInterface $manager, string $shard)
{
$connection = $manager->getConnection();

if ($connection instanceof PoolingShardConnection) {
$connection->connect($shard);

return;
}

throw new InvalidArgumentException(
sprintf(
'Could not establish a shard connection for the shard "%s". The connection must be an instance'
.' of "%s", got "%s" instead.',
$shard,
PoolingShardConnection::class,
get_class($connection)
)
);
}

private function retrievePurgeMode(bool $append, bool $purgeWithTruncate): ?PurgeMode
{
if ($append) {
Expand Down
2 changes: 0 additions & 2 deletions src/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ interface LoaderInterface
* @param string[] $bundles Bundle names in which the fixtures can be found
* @param string $environment If set filter the fixtures by the environment given
* @param bool $append If true, then the database is not purged before loading the objects
* @param string|null $shard Shard connection name to use
* @param bool $noBundles If true, then fixtures from other bundles will not be loaded
*
* @return object[] Loaded objects
Expand All @@ -42,7 +41,6 @@ public function load(
string $environment,
bool $append,
bool $purgeWithTruncate,
string $shard = null,
bool $noBundles = false
): array;
}
6 changes: 0 additions & 6 deletions src/PhpUnit/BaseDatabaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ trait BaseDatabaseTrait
*/
protected static bool $purgeWithTruncate = true;

/**
* @var string|null The name of the Doctrine shard to use
*/
protected static ?string $shard = null;

/**
* @var string|null The name of the Doctrine connection to use
*/
Expand Down Expand Up @@ -73,7 +68,6 @@ protected static function populateDatabase(): void
static::$kernel->getEnvironment(),
static::$append,
static::$purgeWithTruncate,
static::$shard
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use function array_merge;
use function array_shift;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Shards\DBAL\PoolingShardConnection;
use function explode;
use function getcwd;
use Hautelook\AliceBundle\Functional\TestBundle\Entity\Brand;
Expand All @@ -43,8 +42,6 @@ class LoadDataFixturesCommandIntegrationTest extends TestCase

private KernelInterface $kernel;

private DoctrineOrmLoadDataFixturesCommand $command;

private EntityManagerInterface $defaultEntityManager;

protected function setUp(): void
Expand All @@ -54,30 +51,20 @@ protected function setUp(): void
$this->application = new Application($this->kernel);
$this->application->setAutoExit(false);

$this->command = $this->kernel->getContainer()->get('hautelook_alice.console.command.doctrine.doctrine_orm_load_data_fixtures_command');

$doctrine = $this->kernel->getContainer()->get('doctrine');
$this->defaultEntityManager = $doctrine->getManager();

// Create required MySQL databases for fixtures
$this->runConsole('doctrine:database:create', ['--if-not-exists' => true, '--connection' => 'default']);
$this->runConsole(
'doctrine:database:create',
['--if-not-exists' => true, '--connection' => 'default', '--shard' => 1]
['--if-not-exists' => true, '--connection' => 'default']
);

// Reset fixtures schemas
foreach ($doctrine->getManagers() as $name => $manager) {
foreach (array_keys($doctrine->getManagers()) as $name) {
$this->runConsole('doctrine:schema:drop', ['--force' => true, '--em' => $name]);
$this->runConsole('doctrine:schema:create', ['--em' => $name]);
$connection = $manager->getConnection();

if ($connection instanceof PoolingShardConnection) {
$connection->connect(1);
$this->runConsole('doctrine:schema:drop', ['--force' => true, '--em' => $name]);
$this->runConsole('doctrine:schema:create', ['--em' => $name]);
$connection->connect(0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testCallCommandWithoutArguments(): void
/** @var ObjectProphecy<LoaderInterface> $loaderProphecy */
$loaderProphecy = $this->prophesize(LoaderInterface::class);
$loaderProphecy
->load($application, $manager, [], 'fake_env', false, false, null, false)
->load($application, $manager, [], 'fake_env', false, false, false)
->shouldBeCalled()
;
/** @var LoaderInterface $loader */
Expand Down Expand Up @@ -121,7 +121,6 @@ public function testCallCommandWithArguments(): void
'ABundle',
'BBundle',
],
'--shard' => 'shard_id',
'--append' => null,
'--purge-with-truncate' => null,
]);
Expand All @@ -136,7 +135,7 @@ public function testCallCommandWithArguments(): void
/** @var ObjectProphecy<LoaderInterface> $loaderProphecy */
$loaderProphecy = $this->prophesize(LoaderInterface::class);
$loaderProphecy
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, 'shard_id', false)
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, false)
->shouldBeCalled();

/** @var LoaderInterface $loader */
Expand Down Expand Up @@ -164,7 +163,6 @@ public function testCallCommandWithBundleAndNoBundlesFlags(): void
'ABundle',
'BBundle',
],
'--shard' => 'shard_id',
'--append' => null,
'--purge-with-truncate' => null,
'--no-bundles' => null,
Expand All @@ -180,7 +178,7 @@ public function testCallCommandWithBundleAndNoBundlesFlags(): void
/** @var ObjectProphecy<LoaderInterface> $loaderProphecy */
$loaderProphecy = $this->prophesize(LoaderInterface::class);
$loaderProphecy
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, 'shard_id', true)
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, true)
->shouldBeCalledTimes(0);

/** @var LoaderInterface $loader */
Expand Down

0 comments on commit ebaf24e

Please sign in to comment.