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 3.8.x into 4.0.x #1403

Merged
merged 16 commits into from
Mar 1, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/bc-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
- "*.x"
paths:
- .github/workflows/bc-check.yml
- lib/**
- src/**
push:
branches:
- "*.x"
paths:
- .github/workflows/bc-check.yml
- lib/**
- src/**

jobs:
roave_bc_check:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- .github/workflows/continuous-integration.yml
- composer.*
- download-box.sh
- lib/**
- src/**
- phpunit.xml.dist
- tests/**
push:
Expand All @@ -18,7 +18,7 @@ on:
- .github/workflows/continuous-integration.yml
- composer.*
- download-box.sh
- lib/**
- src/**
- phpunit.xml.dist
- tests/**

Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
- name: "Upload coverage file"
uses: "actions/upload-artifact@v3"
with:
name: "phpunit-${{ matrix.deps }}-${{ matrix.php-version }}.coverage"
name: "phpunit-${{ matrix.dependencies }}-${{ matrix.php-version }}.coverage"
path: "coverage.xml"

upload_coverage:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
paths:
- .github/workflows/static-analysis.yml
- composer.*
- lib/**
- src/**
- phpstan*
- tests/**
push:
Expand All @@ -17,7 +17,7 @@ on:
paths:
- .github/workflows/static-analysis.yml
- composer.*
- lib/**
- src/**
- phpstan*
- tests/**

Expand All @@ -29,11 +29,11 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.3"

steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
},
"autoload": {
"psr-4": {
"Doctrine\\Migrations\\": "lib/Doctrine/Migrations"
"Doctrine\\Migrations\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests"
"Doctrine\\Migrations\\Tests\\": "tests"
}
},
"bin": [
Expand Down
10 changes: 7 additions & 3 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,21 @@ Now update your ``cli-config.php`` in the root of your project to look like the
require 'vendor/autoload.php';

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\ORMSetup;
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Configuration\Migration\PhpFile;
use Doctrine\DBAL\DriverManager;

$config = new PhpFile('migrations.php'); // Or use one of the Doctrine\Migrations\Configuration\Configuration\* loaders

$paths = [__DIR__.'/lib/MyProject/Entities'];
$isDevMode = true;

$ORMconfig = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $ORMconfig);
$ORMConfig = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode);
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);

$entityManager = new EntityManager($connection, $ORMConfig);

return DependencyFactory::fromEntityManager($config, new ExistingEntityManager($entityManager));

Expand Down
18 changes: 12 additions & 6 deletions docs/en/reference/generating-migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ the ORM. To test this functionality, create a new ``User`` entity located at ``l

namespace MyProject\Entities;

/**
* @Entity
* @Table(name="users")
*/
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;

#[Entity]
#[Table(name: 'users')]
class User
{
/** @Id @Column(type="integer") @GeneratedValue */
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue]
private $id;

/** @Column(type="string", nullable=true) */
#[Column(type: 'string', nullable: true)]
private $username;

public function setId(int $id)
Expand Down
18 changes: 9 additions & 9 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<arg value="nps"/>

<file>bin</file>
<file>lib</file>
<file>src</file>
<file>tests</file>

<rule ref="Doctrine"/>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/src/*</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
Expand All @@ -30,25 +30,25 @@
</rule>

<rule ref="Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase">
<exclude-pattern>lib/Doctrine/Migrations/Events.php</exclude-pattern>
<exclude-pattern>src/Events.php</exclude-pattern>
</rule>

<rule ref="Generic.Strings.UnnecessaryStringConcat.Found">
<exclude-pattern>lib/Doctrine/Migrations/MigrationsVersion.php</exclude-pattern>
<exclude-pattern>src/MigrationsVersion.php</exclude-pattern>
</rule>

<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<exclude-pattern>tests/Doctrine/Migrations/Tests/TestLogger.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php</exclude-pattern>
<exclude-pattern>tests/TestLogger.php</exclude-pattern>
<exclude-pattern>src/Tools/Console/ConsoleLogger.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming">
<exclude-pattern>lib/Doctrine/Migrations/AbstractMigration.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/Migrations/Configuration/Loader/AbstractFileLoader.php</exclude-pattern>
<exclude-pattern>src/AbstractMigration.php</exclude-pattern>
<exclude-pattern>src/Configuration/Loader/AbstractFileLoader.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
<exclude-pattern>tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php</exclude-pattern>
<exclude-pattern>tests/Stub/DoctrineRegistry.php</exclude-pattern>
</rule>

</ruleset>
52 changes: 19 additions & 33 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,69 +1,55 @@
parameters:
level: 7
paths:
- lib
- src
- tests
excludePaths:
- tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php
- tests/Configuration/ConfigurationTestSource/Migrations/Version123.php
- tests/Tools/Console/legacy-config-orm/cli-config.php
ignoreErrors:
- '~Variable method call on Doctrine\\Migrations\\AbstractMigration~'
-
message: '~^Call to function in_array\(\) requires parameter #3 to be true\.$~'
path: lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php
path: src/Version/SortedMigrationPlanCalculator.php
-
message: '~^Variable property access on SimpleXMLElement\.$~'
path: lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php
path: src/Configuration/Migration/XmlFile.php
-
message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~'
path: lib/Doctrine/Migrations/InlineParameterFormatter.php
path: src/InlineParameterFormatter.php
-
message: '~^Call to an undefined method Symfony\\Component\\Console\\Output\\OutputInterface\:\:getErrorOutput\(\)\.$~'
path: lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php
path: src/Tools/Console/ConsoleLogger.php
-
message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~'
path: tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php
path: tests/Stub/DoctrineRegistry.php

# https://github.com/phpstan/phpstan/issues/5982
-
message: '~^Cannot call method getWrappedConnection\(\) on class-string\|object\.~'
path: lib/Doctrine/Migrations/Tools/TransactionHelper.php
path: src/Tools/TransactionHelper.php

# TODO: Be more precise about class-strings
-
message: '~^Method Doctrine\\Migrations\\Version\\DbalMigrationFactory::createVersion\(\) should return Doctrine\\Migrations\\AbstractMigration but returns object\.$~'
paths:
- lib/Doctrine/Migrations/Version/DbalMigrationFactory.php
- src/Version/DbalMigrationFactory.php

# We're testing legacy functionality here.
# ORM 2 + DBAL 3 backwards compatibility
-
message: """
#^Instantiation of deprecated class Doctrine\\\\ORM\\\\Tools\\\\Console\\\\Helper\\\\EntityManagerHelper\\:
This class will be removed in ORM 3\\.0 without replacement\\.$#
"""
count: 1
path: tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/cli-config.php
message: '~^Call to an undefined method Doctrine\\DBAL\\Connection\:\:getEventManager\(\)\.$~'
path: src/DependencyFactory.php

-
message: """
#^Fetching class constant class of deprecated class Doctrine\\\\ORM\\\\Tools\\\\Console\\\\Helper\\\\EntityManagerHelper\\:
This class will be removed in ORM 3\\.0 without replacement\\.$#
"""
count: 1
path: tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php
message: '~^Strict comparison using !== between callable\(\)\: mixed and null will always evaluate to true\.$~'
path: src/Generator/DiffGenerator.php

# TODO: deprecate using the connection event manager and expose
# our own event manager instead.
-
message: '~^Call to deprecated method getEventManager\(\) of class Doctrine\\DBAL\\Connection\.$~'
path: lib/Doctrine/Migrations/DependencyFactory.php
message: '~Doctrine\\ORM\\Tools\\Console\\Helper\\EntityManagerHelper~'
path: src/Tools/Console/ConsoleRunner.php

# DBAL 4 forward compatibility
- '~^Call to function method_exists\(\) with ''Doctrine\\\\DBAL\\\\Connection'' and ''getEventManager'' will always evaluate to true\.$~'
- '~^Class Doctrine\\DBAL\\Platforms\\SQLitePlatform not found\.$~'
- '~^Instantiated class Doctrine\\DBAL\\Platforms\\SQLitePlatform not found\.$~'
- '~^Access to constant class on an unknown class Doctrine\\DBAL\\Platforms\\SQLitePlatform\.$~'
- '~expects Doctrine\\DBAL\\Platforms\\AbstractPlatform, Doctrine\\DBAL\\Platforms\\SQLitePlatform given\.$~'
symfony:
console_application_loader: tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php
console_application_loader: tests/doctrine-migrations-phpstan-app.php
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

<testsuites>
<testsuite name="Doctrine2 Database Migrations Test Suite">
<directory>./tests/Doctrine/</directory>
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>./lib/</directory>
<directory>src</directory>
</include>
</source>
</phpunit>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function formatParameters(array $params, array $types): string
return sprintf('with parameters (%s)', implode(', ', $formattedParameters));
}

private function formatParameter(mixed $value, string|int $type): string|int|float|null
private function formatParameter(mixed $value, string|int $type): string|int|bool|float|null
{
if (is_string($type) && Type::hasType($type)) {
return Type::getType($type)->convertToDatabaseValue(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\Migrations\Exception\NoMigrationsToExecute;
use Doctrine\Migrations\Exception\UnknownMigrationVersion;
use Doctrine\Migrations\Metadata\ExecutedMigrationsList;
use Doctrine\Migrations\Tools\Console\ConsoleInputMigratorConfigurationFactory;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -75,7 +76,7 @@ protected function configure(): void
null,
InputOption::VALUE_OPTIONAL,
'Wrap the entire migration in a transaction.',
'notprovided',
ConsoleInputMigratorConfigurationFactory::ABSENT_CONFIG_VALUE,
)
->setHelp(<<<'EOT'
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version:
Expand All @@ -96,7 +97,7 @@ protected function configure(): void
<info>%command.full_name% prev</info>
<info>These alias are defined: first, latest, prev, current and next</info>

You can specify the version you wish to migrate to using an number against the current version:
You can specify the version you wish to migrate to using a number against the current version:

<info>%command.full_name% current+3</info>

Expand All @@ -108,15 +109,21 @@ protected function configure(): void

<info>%command.full_name% FQCN --write-sql</info>

Or you can also execute the migration without a warning message which you need to interact with:
Or you can also execute the migration without a warning message which you need to interact with <comment>--no-interaction</comment>:

<info>%command.full_name% --no-interaction</info>

You can also time all the different queries if you wanna know which one is taking so long:
You can also time all the different queries if you want to know which one is taking so long with <comment>--query-time</comment>:

<info>%command.full_name% --query-time</info>

Use the --all-or-nothing option to wrap the entire migration in a transaction.
You can skip throwing an exception if no migration is available with <comment>--allow-no-migration</comment>:

<info>%command.full_name% --allow-no-migration</info>

You can wrap the entire migration in a transaction with <comment>--all-or-nothing</comment>:

<info>%command.full_name% --all-or-nothing</info>

EOT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class ConsoleInputMigratorConfigurationFactory implements MigratorConfigurationFactory
{
public const ABSENT_CONFIG_VALUE = 'notprovided';

public function __construct(private readonly Configuration $configuration)
{
}
Expand All @@ -36,7 +38,7 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul
$allOrNothingOption = $input->getOption('all-or-nothing');
}

if ($wasOptionExplicitlyPassed && $allOrNothingOption !== null) {
if ($wasOptionExplicitlyPassed && ($allOrNothingOption !== null && $allOrNothingOption !== self::ABSENT_CONFIG_VALUE)) {
Deprecation::trigger(
'doctrine/migrations',
'https://github.com/doctrine/migrations/issues/1304',
Expand All @@ -49,10 +51,10 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul
);
}

if ($allOrNothingOption === 'notprovided') {
return null;
}

return (bool) ($allOrNothingOption ?? false);
return match ($allOrNothingOption) {
self::ABSENT_CONFIG_VALUE => null,
null => false,
default => (bool) $allOrNothingOption,
};
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading