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

A whole slew of changes for 3.0.x! See the summary. #1079

Merged
merged 14 commits into from
Nov 28, 2020
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
13 changes: 12 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: "Continuous Integration"

on:
Expand All @@ -18,6 +17,18 @@ jobs:
with:
args: --from=${{ github.event.pull_request.base.sha }}

composer_normalize:
name: "Composer Normalize"
runs-on: "ubuntu-20.04"
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: "docker://ergebnis/composer-normalize-action:latest"
with:
args: "--dry-run"

phpunit:
name: "PHPUnit"
runs-on: "ubuntu-20.04"
Expand Down
57 changes: 36 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,69 @@
"name": "doctrine/migrations",
"type": "library",
"description": "PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.",
"keywords": ["php", "database", "migrations", "dbal"],
"keywords": [
"database",
"migrations",
"dbal"
],
"homepage": "https://www.doctrine-project.org/projects/migrations.html",
"license": "MIT",
"authors": [
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
{"name": "Michael Simonson", "email": "contact@mikesimonson.com" }
TomHAnderson marked this conversation as resolved.
Show resolved Hide resolved
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Michael Simonson",
"email": "contact@mikesimonson.com"
}
],
"require": {
"php": "^7.2",
"composer/package-versions-deprecated": "^1.8",
"doctrine/dbal": "^2.10",
"doctrine/event-manager": "^1.0",
"composer/package-versions-deprecated": "^1.8",
"ocramius/proxy-manager": "^2.0.2",
"psr/log": "^1.1.3",
"symfony/console": "^3.4||^4.4.16||^5.0",
"symfony/stopwatch": "^3.4||^4.0||^5.0"
"symfony/console": "^3.4 || ^4.4.16 || ^5.0",
"symfony/stopwatch": "^3.4 || ^4.0 || ^5.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"doctrine/coding-standard": "^8.0",
"doctrine/orm": "^2.6",
"doctrine/persistence": "^1.3||^2.0",
"doctrine/persistence": "^1.3 || ^2.0",
"doctrine/sql-formatter": "^1.0",
"ergebnis/composer-normalize": "^2.11",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpstan/phpstan-symfony": "^0.12",
"phpunit/phpunit": "^8.5 || ^9.4",
"symfony/process": "^3.4||^4.0||^5.0",
"symfony/yaml": "^3.4||^4.0||^5.0"
"symfony/process": "^3.4 || ^4.0 || ^5.0",
"symfony/yaml": "^3.4 || ^4.0 || ^5.0"
},
"suggest": {
"doctrine/sql-formatter": "Allows to generate formatted SQL with the diff command.",
"symfony/yaml": "Allows the use of yaml for migration configuration files."
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
},
"composer-normalize": {
"indent-size": 4,
"indent-style": "space"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Migrations\\": "lib/Doctrine/Migrations"
Expand All @@ -49,17 +75,6 @@
"Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests"
}
},
"config": {
"sort-packages": true,
"platform": {
"php": "7.2.2"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"bin": [
"bin/doctrine-migrations"
]
Expand Down
2 changes: 1 addition & 1 deletion download-box.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

if [ ! -f box.phar ]; then
wget https://github.com/box-project/box/releases/download/3.9.0/box.phar -O box.phar
wget https://github.com/box-project/box/releases/download/3.9.1/box.phar -O box.phar
fi
22 changes: 15 additions & 7 deletions lib/Doctrine/Migrations/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
use Doctrine\Migrations\Exception\MigrationException;
use Doctrine\Migrations\Metadata\Storage\MetadataStorageConfiguration;

use function strcasecmp;
use function strtolower;

/**
* The Configuration class is responsible for defining migration configuration information.
*/
final class Configuration
{
public const VERSIONS_ORGANIZATION_NONE = 'none';
public const VERSIONS_ORGANIZATION_BY_YEAR = 'year';
public const VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH = 'year_and_month';

Expand Down Expand Up @@ -177,12 +178,19 @@ public function isDatabasePlatformChecked(): bool
public function setMigrationOrganization(string $migrationOrganization): void
{
$this->assertNotFrozen();
if (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR) === 0) {
$this->setMigrationsAreOrganizedByYear();
} elseif (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH) === 0) {
$this->setMigrationsAreOrganizedByYearAndMonth();
} else {
throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization);

switch (strtolower($migrationOrganization)) {
case self::VERSIONS_ORGANIZATION_NONE:
$this->setMigrationsAreOrganizedByYearAndMonth(false);
break;
case self::VERSIONS_ORGANIZATION_BY_YEAR:
$this->setMigrationsAreOrganizedByYear();
break;
case self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
$this->setMigrationsAreOrganizedByYearAndMonth();
break;
default:
throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ public function testMigrationOrganizationWithWrongValue(): void
$config = new Configuration();
$config->setMigrationOrganization('foo');
}

public function testMigrationOrganizationCanBeReset(): void
{
$config = new Configuration();

$config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH);
self::assertTrue($config->areMigrationsOrganizedByYearAndMonth());
self::assertTrue($config->areMigrationsOrganizedByYear());

$config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_NONE);
self::assertFalse($config->areMigrationsOrganizedByYearAndMonth());
self::assertFalse($config->areMigrationsOrganizedByYear());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
use Doctrine\Migrations\Generator\ClassNameGenerator;
use PHPUnit\Framework\TestCase;

use function method_exists;

class ClassNameGeneratorTest extends TestCase
{
public function testName(): void
{
$generator = new ClassNameGenerator();
$fqcn = $generator->generateClassName('Foo');
self::assertRegExp('/^Foo\\\\Version[0-9]{14}$/', $fqcn);

if (method_exists($this, 'assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression('/^Foo\\\\Version[0-9]{14}$/', $fqcn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should use the static implementation, so self

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't play well with phpstan

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More info: method_exists cannot take self as the first parameter. So if you use $this for method_exists then use self for assertMatchesRegularExpression phpstan has a problem with that.

Copy link
Member

@greg0ire greg0ire Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the class name (can't use $this::class for now since it's PHP 8 but TestCase::class should do the trick)?

Copy link
Member Author

@TomHAnderson TomHAnderson Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. You see, phpstan is clearing (for lack of a better term) the use of $this after the method_exists function and seeing that it won't be called passes.

        if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) {
            self::assertMatchesRegularExpression('/^Foo\\\\Version[0-9]{14}$/', $fqcn);

Results in

 ------ ----------------------------------------------------------------------------------------------------------------------------------
  Line   tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------
  20     Call to an undefined static method Doctrine\Migrations\Tests\Generator\ClassNameGeneratorTest::assertMatchesRegularExpression().
 ------ ----------------------------------------------------------------------------------------------------------------------------------

} else {
self::assertRegExp('/^Foo\\\\Version[0-9]{14}$/', $fqcn);
}
}
}
36 changes: 14 additions & 22 deletions tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ static function ($name): bool {
->method('createSchema')
->willReturn($toSchema);

$toSchema->expects(self::at(1))
$toSchema->expects(self::exactly(2))
->method('dropTable')
->with('schema.table_name2');

$toSchema->expects(self::at(2))
->method('dropTable')
->with('schema.table_name3');
->will(self::onConsecutiveCalls('schema.table_name2', 'schema.table_name3'));

$fromSchema->expects(self::once())
->method('getMigrateToSql')
Expand All @@ -106,15 +102,13 @@ static function ($name): bool {
->with($toSchema, $this->platform)
->willReturn(['UPDATE table SET value = 1']);

$this->migrationSqlGenerator->expects(self::at(0))
->method('generate')
->with(['UPDATE table SET value = 2'], true, 80)
->willReturn('test1');

$this->migrationSqlGenerator->expects(self::at(1))
$this->migrationSqlGenerator->expects(self::exactly(2))
->method('generate')
->with(['UPDATE table SET value = 1'], true, 80)
->willReturn('test2');
->with(self::logicalOr(
self::equalTo(['UPDATE table SET value = 2']),
self::equalTo(['UPDATE table SET value = 1'])
), true, 80)
->will(self::onConsecutiveCalls('test1', 'test2'));

$this->migrationGenerator->expects(self::once())
->method('generateMigration')
Expand Down Expand Up @@ -163,15 +157,13 @@ public function testGenerateFromEmptySchema(): void
->with($toSchema, $this->platform)
->willReturn(['DROP TABLE table_name']);

$this->migrationSqlGenerator->expects(self::at(0))
->method('generate')
->with(['CREATE TABLE table_name'], false, 120, true)
->willReturn('test up');

$this->migrationSqlGenerator->expects(self::at(1))
$this->migrationSqlGenerator->expects(self::exactly(2))
->method('generate')
->with(['DROP TABLE table_name'], false, 120, true)
->willReturn('test down');
->with(self::logicalOr(
self::equalTo(['CREATE TABLE table_name']),
self::equalTo(['DROP TABLE table_name'])
), false, 120, true)
->will(self::onConsecutiveCalls('test up', 'test down'));

$this->migrationGenerator->expects(self::once())
->method('generateMigration')
Expand Down
7 changes: 5 additions & 2 deletions tests/Doctrine/Migrations/Tests/RollupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ public function testRollup(): void
->willReturn(new AvailableMigrationsSet([$m1]));

$this->storage
->expects(self::at(0))->method('reset')->with();
->expects(self::exactly(1))
->method('reset')
->with();

$this->storage
->expects(self::at(1))
->expects(self::exactly(1))
->method('complete')
->willReturnCallback(static function (ExecutionResult $result): void {
self::assertEquals(new Version('A'), $result->getVersion());
Expand Down
14 changes: 6 additions & 8 deletions tests/Doctrine/Migrations/Tests/SchemaDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ public function testDump(): void
->method('getDropTableSQL')
->willReturn('DROP TABLE test');

$this->migrationSqlGenerator->expects(self::at(0))
$this->migrationSqlGenerator->expects(self::exactly(2))
->method('generate')
->with(['CREATE TABLE test'])
->willReturn('up');

$this->migrationSqlGenerator->expects(self::at(1))
->method('generate')
->with(['DROP TABLE test'])
->willReturn('down');
->with(self::logicalOr(
self::equalTo(['CREATE TABLE test']),
self::equalTo(['DROP TABLE test'])
))
->will(self::onConsecutiveCalls('up', 'down'));

$this->migrationGenerator->expects(self::once())
->method('generateMigration')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Migrations\Tests\Tools\Console\Command;

use DateTimeImmutable;
use Doctrine\DBAL\Version as DBALVersion;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
use Doctrine\Migrations\Configuration\Migration\ExistingConfiguration;
Expand Down Expand Up @@ -73,6 +74,13 @@ public function testExecute(): void

$lines = array_map('trim', explode("\n", trim($this->commandTester->getDisplay(true))));

if (DBALVersion::compare('2.11.0') > 0) {
// Trailing space is necessary to pad size to match `...\PDO\SQLite\Driver` namespace length
$databaseDriver = 'Doctrine\DBAL\Driver\PDOSqlite\Driver ';
} else {
$databaseDriver = 'Doctrine\DBAL\Driver\PDO\SQLite\Driver';
}

self::assertSame(
[
'+----------------------+----------------------+------------------------------------------------------------------------+',
Expand All @@ -82,7 +90,7 @@ public function testExecute(): void
'| | Table Name | doctrine_migration_versions |',
'| | Column Name | version |',
'|----------------------------------------------------------------------------------------------------------------------|',
'| Database | Driver | Doctrine\DBAL\Driver\PDOSqlite\Driver |',
'| Database | Driver | ' . $databaseDriver . ' |',
'| | Name | |',
'|----------------------------------------------------------------------------------------------------------------------|',
'| Versions | Previous | 1230 |',
Expand Down