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

Merge release 3.1.3 into 3.2.x #1165

Merged
merged 7 commits into from
Jun 10, 2021
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
2 changes: 2 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
coverage: "pcov"
extensions: "pdo_sqlite"
ini-values: "zend.assertions=1"
# Remove this line when a fix for is available https://github.com/box-project/box/issues/555
tools: "composer:v2.0.14"

- name: "Download box"
run: "./download-box.sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private function isInitialized(): bool
}

if ($this->connection instanceof PrimaryReadReplicaConnection) {
$this->connection->connect('master');
$this->connection->ensureConnectedToPrimary();
}

return $this->schemaManager->tablesExist([$this->configuration->getTableName()]);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(EntityManagerInterface $em)
*/
public function createSchema(): Schema
{
/** @var array<int, ClassMetadata> $metadata */
/** @var array<int, ClassMetadata<object>> $metadata */
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();

if (count($metadata) === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ protected function configure(): void
'all-or-nothing',
null,
InputOption::VALUE_OPTIONAL,
'Wrap the entire migration in a transaction.',
false
'Wrap the entire migration in a transaction.'
)
->setHelp(<<<EOT
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu
{
$timeAllQueries = $input->hasOption('query-time') ? (bool) $input->getOption('query-time') : false;
$dryRun = $input->hasOption('dry-run') ? (bool) $input->getOption('dry-run') : false;
$allOrNothing = $input->hasOption('all-or-nothing') ? (bool) $input->getOption('all-or-nothing') : $this->configuration->isAllOrNothing();
$allOrNothing = $input->hasOption('all-or-nothing') ? $input->getOption('all-or-nothing') : null;
$allOrNothing = (bool) ($allOrNothing ?? $this->configuration->isAllOrNothing());

return (new MigratorConfiguration())
->setDryRun($dryRun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public function testPrimaryReadReplicaConnectionGetsConnected(): void
$connection = $this->createMock(PrimaryReadReplicaConnection::class);
$connection
->expects(self::atLeastOnce())
->method('connect')
->with('master');
->method('ensureConnectedToPrimary');

$connection
->expects(self::atLeastOnce())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ClassMetadataFactory extends BaseMetadataFactoryAlias
{
/**
* @return ClassMetadata[]
* @psalm-return list<ClassMetadata<object>>
*/
public function getAllMetadata(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Doctrine\Migrations\Version\ExecutionResult;
use Doctrine\Migrations\Version\MigrationFactory;
use Doctrine\Migrations\Version\Version;
use Generator;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;
Expand Down Expand Up @@ -371,28 +372,46 @@ public function testExecuteMigrateDown(): void
self::assertStringContainsString('[notice] Migrating down to A', trim($this->migrateCommandTester->getDisplay(true)));
}

public function testExecuteMigrateAllOrNothing(): void
/**
* @dataProvider allOrNothing
* @psalm-param array<string, bool> $input
*/
public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool $expected): void
{
$migrator = $this->createMock(DbalMigrator::class);
$this->dependencyFactory->setService(Migrator::class, $migrator);
$this->configuration->setAllOrNothing($default);

$migrator->expects(self::once())
->method('migrate')
->willReturnCallback(static function (MigrationPlanList $planList, MigratorConfiguration $configuration): array {
self::assertTrue($configuration->isAllOrNothing());
->willReturnCallback(static function (MigrationPlanList $planList, MigratorConfiguration $configuration) use ($expected): array {
self::assertSame($expected, $configuration->isAllOrNothing());
self::assertCount(1, $planList);

return ['A'];
});

$this->migrateCommandTester->execute(
['--all-or-nothing' => true],
$input,
['interactive' => false]
);

self::assertSame(0, $this->migrateCommandTester->getStatusCode());
}

/**
* @psalm-return Generator<array{bool, array<string, bool>, bool}>
*/
public function allOrNothing(): Generator
{
yield [false, ['--all-or-nothing' => false], false];
yield [false, ['--all-or-nothing' => true], true];
yield [true, ['--all-or-nothing' => false], false];

yield [true, [], true];
yield [false, [], false];
}

public function testExecuteMigrateCancelExecutedUnavailableMigrations(): void
{
$result = new ExecutionResult(new Version('345'));
Expand Down