Skip to content

Commit ebaf24e

Browse files
authored
Drop support for DBAL 2 (#34)
1 parent d369ad1 commit ebaf24e

File tree

10 files changed

+7
-98
lines changed

10 files changed

+7
-98
lines changed

Diff for: README.md

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ Both traits provide several configuration options as protected static properties
229229
* `self::$bundles`: The list of bundles where to look for fixtures
230230
* `self::$append`: Append fixtures instead of purging
231231
* `self::$purgeWithTruncate`: Use TRUNCATE to purge
232-
* `self::$shard`: The name of the Doctrine shard to use
233232
* `self::$connection`: The name of the Doctrine connection to use
234233

235234
Use them in the `setUpBeforeClass` method.

Diff for: composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
"phpunit/phpunit": "^9.5",
4646
"phpspec/prophecy": "^1.7",
4747
"symfony/phpunit-bridge": "^6.0",
48-
"phpspec/prophecy-phpunit": "^2.0",
49-
"doctrine/shards": "^1.0"
48+
"phpspec/prophecy-phpunit": "^2.0"
5049
},
5150

5251
"extra": {

Diff for: fixtures/Functional/TestBundle/Entity/Shard.php

-30
This file was deleted.

Diff for: fixtures/Loader/FakeLoader.php

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function load(
3030
string $environment,
3131
bool $append,
3232
bool $purgeWithTruncate,
33-
string $shard = null,
3433
bool $noBundles = false
3534
): array {
3635
$this->__call(__METHOD__, func_get_args());

Diff for: src/Console/Command/Doctrine/DoctrineOrmLoadDataFixturesCommand.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ protected function configure(): void
7979
InputOption::VALUE_NONE,
8080
'Append the data fixtures instead of deleting all data from the database first.'
8181
)
82-
->addOption(
83-
'shard',
84-
null,
85-
InputOption::VALUE_REQUIRED,
86-
'The shard database id to use for this command.'
87-
)
8882
->addOption(
8983
'purge-with-truncate',
9084
null,
@@ -149,13 +143,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
149143

150144
$manager = $this->doctrine->getManager($input->getOption('manager'));
151145
$environment = $input->getOption('env');
152-
$shard = $input->getOption('shard');
153146
$append = $input->getOption('append');
154147
$truncate = $input->getOption('purge-with-truncate');
155148
/** @var FrameworkBundleConsoleApplication $application */
156149
$application = $this->getApplication();
157150

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

160153
return 0;
161154
}

Diff for: src/Loader/DoctrineOrmLoader.php

-28
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
namespace Hautelook\AliceBundle\Loader;
1515

1616
use Doctrine\ORM\EntityManagerInterface;
17-
use Doctrine\Shards\DBAL\PoolingShardConnection;
1817
use Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister;
1918
use Fidry\AliceDataFixtures\LoaderInterface;
2019
use Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface;
2120
use Fidry\AliceDataFixtures\Persistence\PersisterInterface;
2221
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
23-
use function get_class;
2422
use Hautelook\AliceBundle\BundleResolverInterface;
2523
use Hautelook\AliceBundle\FixtureLocatorInterface;
2624
use Hautelook\AliceBundle\LoaderInterface as AliceBundleLoaderInterface;
@@ -96,7 +94,6 @@ public function load(
9694
string $environment,
9795
bool $append,
9896
bool $purgeWithTruncate,
99-
string $shard = null,
10097
bool $noBundles = false
10198
): array {
10299
if ($append && $purgeWithTruncate) {
@@ -113,10 +110,6 @@ public function load(
113110

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

116-
if (null !== $shard) {
117-
$this->connectToShardConnection($manager, $shard);
118-
}
119-
120113
$purgeMode = $this->retrievePurgeMode($append, $purgeWithTruncate);
121114

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

160-
private function connectToShardConnection(EntityManagerInterface $manager, string $shard)
161-
{
162-
$connection = $manager->getConnection();
163-
164-
if ($connection instanceof PoolingShardConnection) {
165-
$connection->connect($shard);
166-
167-
return;
168-
}
169-
170-
throw new InvalidArgumentException(
171-
sprintf(
172-
'Could not establish a shard connection for the shard "%s". The connection must be an instance'
173-
.' of "%s", got "%s" instead.',
174-
$shard,
175-
PoolingShardConnection::class,
176-
get_class($connection)
177-
)
178-
);
179-
}
180-
181153
private function retrievePurgeMode(bool $append, bool $purgeWithTruncate): ?PurgeMode
182154
{
183155
if ($append) {

Diff for: src/LoaderInterface.php

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ interface LoaderInterface
3030
* @param string[] $bundles Bundle names in which the fixtures can be found
3131
* @param string $environment If set filter the fixtures by the environment given
3232
* @param bool $append If true, then the database is not purged before loading the objects
33-
* @param string|null $shard Shard connection name to use
3433
* @param bool $noBundles If true, then fixtures from other bundles will not be loaded
3534
*
3635
* @return object[] Loaded objects
@@ -42,7 +41,6 @@ public function load(
4241
string $environment,
4342
bool $append,
4443
bool $purgeWithTruncate,
45-
string $shard = null,
4644
bool $noBundles = false
4745
): array;
4846
}

Diff for: src/PhpUnit/BaseDatabaseTrait.php

-6
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ trait BaseDatabaseTrait
4141
*/
4242
protected static bool $purgeWithTruncate = true;
4343

44-
/**
45-
* @var string|null The name of the Doctrine shard to use
46-
*/
47-
protected static ?string $shard = null;
48-
4944
/**
5045
* @var string|null The name of the Doctrine connection to use
5146
*/
@@ -73,7 +68,6 @@ protected static function populateDatabase(): void
7368
static::$kernel->getEnvironment(),
7469
static::$append,
7570
static::$purgeWithTruncate,
76-
static::$shard
7771
);
7872
}
7973
}

Diff for: tests/Console/Command/Doctrine/LoadDataFixturesCommandIntegrationTest.php

+2-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use function array_merge;
1818
use function array_shift;
1919
use Doctrine\ORM\EntityManagerInterface;
20-
use Doctrine\Shards\DBAL\PoolingShardConnection;
2120
use function explode;
2221
use function getcwd;
2322
use Hautelook\AliceBundle\Functional\TestBundle\Entity\Brand;
@@ -43,8 +42,6 @@ class LoadDataFixturesCommandIntegrationTest extends TestCase
4342

4443
private KernelInterface $kernel;
4544

46-
private DoctrineOrmLoadDataFixturesCommand $command;
47-
4845
private EntityManagerInterface $defaultEntityManager;
4946

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

57-
$this->command = $this->kernel->getContainer()->get('hautelook_alice.console.command.doctrine.doctrine_orm_load_data_fixtures_command');
58-
5954
$doctrine = $this->kernel->getContainer()->get('doctrine');
6055
$this->defaultEntityManager = $doctrine->getManager();
6156

6257
// Create required MySQL databases for fixtures
6358
$this->runConsole('doctrine:database:create', ['--if-not-exists' => true, '--connection' => 'default']);
6459
$this->runConsole(
6560
'doctrine:database:create',
66-
['--if-not-exists' => true, '--connection' => 'default', '--shard' => 1]
61+
['--if-not-exists' => true, '--connection' => 'default']
6762
);
6863

6964
// Reset fixtures schemas
70-
foreach ($doctrine->getManagers() as $name => $manager) {
65+
foreach (array_keys($doctrine->getManagers()) as $name) {
7166
$this->runConsole('doctrine:schema:drop', ['--force' => true, '--em' => $name]);
7267
$this->runConsole('doctrine:schema:create', ['--em' => $name]);
73-
$connection = $manager->getConnection();
74-
75-
if ($connection instanceof PoolingShardConnection) {
76-
$connection->connect(1);
77-
$this->runConsole('doctrine:schema:drop', ['--force' => true, '--em' => $name]);
78-
$this->runConsole('doctrine:schema:create', ['--em' => $name]);
79-
$connection->connect(0);
80-
}
8168
}
8269
}
8370

Diff for: tests/Console/Command/Doctrine/LoadDataFixturesCommandTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testCallCommandWithoutArguments(): void
9393
/** @var ObjectProphecy<LoaderInterface> $loaderProphecy */
9494
$loaderProphecy = $this->prophesize(LoaderInterface::class);
9595
$loaderProphecy
96-
->load($application, $manager, [], 'fake_env', false, false, null, false)
96+
->load($application, $manager, [], 'fake_env', false, false, false)
9797
->shouldBeCalled()
9898
;
9999
/** @var LoaderInterface $loader */
@@ -121,7 +121,6 @@ public function testCallCommandWithArguments(): void
121121
'ABundle',
122122
'BBundle',
123123
],
124-
'--shard' => 'shard_id',
125124
'--append' => null,
126125
'--purge-with-truncate' => null,
127126
]);
@@ -136,7 +135,7 @@ public function testCallCommandWithArguments(): void
136135
/** @var ObjectProphecy<LoaderInterface> $loaderProphecy */
137136
$loaderProphecy = $this->prophesize(LoaderInterface::class);
138137
$loaderProphecy
139-
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, 'shard_id', false)
138+
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, false)
140139
->shouldBeCalled();
141140

142141
/** @var LoaderInterface $loader */
@@ -164,7 +163,6 @@ public function testCallCommandWithBundleAndNoBundlesFlags(): void
164163
'ABundle',
165164
'BBundle',
166165
],
167-
'--shard' => 'shard_id',
168166
'--append' => null,
169167
'--purge-with-truncate' => null,
170168
'--no-bundles' => null,
@@ -180,7 +178,7 @@ public function testCallCommandWithBundleAndNoBundlesFlags(): void
180178
/** @var ObjectProphecy<LoaderInterface> $loaderProphecy */
181179
$loaderProphecy = $this->prophesize(LoaderInterface::class);
182180
$loaderProphecy
183-
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, 'shard_id', true)
181+
->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, true)
184182
->shouldBeCalledTimes(0);
185183

186184
/** @var LoaderInterface $loader */

0 commit comments

Comments
 (0)