Skip to content

Commit cc2b638

Browse files
authored
Merge pull request #12011 from greg0ire/3.4.x
Merge 2.20.x up into 3.4.x
2 parents 3272e1c + a64bed9 commit cc2b638

10 files changed

+65
-11
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ parameters:
4545
path: src/UnitOfWork.php
4646

4747
-
48-
message: '~^Parameter #1 \$command of method Symfony\\Component\\Console\\Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
48+
message: '~^Parameter #2 \$command of static method Doctrine\\ORM\\Tools\\Console\\ConsoleRunner::addCommandToApplication\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
4949
path: src/Tools/Console/ConsoleRunner.php
5050

5151
-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Tools\Console;
6+
7+
use Symfony\Component\Console\Application;
8+
use Symfony\Component\Console\Command\Command;
9+
10+
use function method_exists;
11+
12+
/**
13+
* Forward compatibility with Symfony Console 7.4
14+
*
15+
* @internal
16+
*/
17+
trait ApplicationCompatibility
18+
{
19+
private static function addCommandToApplication(Application $application, Command $command): Command|null
20+
{
21+
if (method_exists(Application::class, 'addCommand')) {
22+
// @phpstan-ignore method.notFound (This method will be added in Symfony 7.4)
23+
return $application->addCommand($command);
24+
}
25+
26+
return $application->add($command);
27+
}
28+
}

src/Tools/Console/ConsoleRunner.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
final class ConsoleRunner
2121
{
22+
use ApplicationCompatibility;
23+
2224
/**
2325
* Runs console with the given helper set.
2426
*
@@ -59,7 +61,10 @@ public static function addCommands(Application $cli, EntityManagerProvider $enti
5961
$connectionProvider = new ConnectionFromManagerProvider($entityManagerProvider);
6062

6163
if (class_exists(DBALConsole\Command\ReservedWordsCommand::class)) {
62-
$cli->add(new DBALConsole\Command\ReservedWordsCommand($connectionProvider));
64+
self::addCommandToApplication(
65+
$cli,
66+
new DBALConsole\Command\ReservedWordsCommand($connectionProvider),
67+
);
6368
}
6469

6570
$cli->addCommands(

tests/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Tools\Console\Command;
66

7+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
78
use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand;
89
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
910
use Doctrine\Tests\Models\Cache\State;
@@ -15,6 +16,8 @@
1516
#[Group('DDC-2183')]
1617
class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
1718
{
19+
use ApplicationCompatibility;
20+
1821
private Application $application;
1922

2023
private CollectionRegionCommand $command;
@@ -28,7 +31,7 @@ protected function setUp(): void
2831
$this->command = new CollectionRegionCommand(new SingleManagerProvider($this->_em));
2932

3033
$this->application = new Application();
31-
$this->application->add($this->command);
34+
self::addCommandToApplication($this->application, $this->command);
3235
}
3336

3437
public function testClearAllRegion(): void

tests/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Tools\Console\Command;
66

7+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
78
use Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand;
89
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
910
use Doctrine\Tests\Models\Cache\Country;
@@ -18,6 +19,8 @@
1819
#[Group('DDC-2183')]
1920
class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
2021
{
22+
use ApplicationCompatibility;
23+
2124
private Application $application;
2225

2326
private EntityRegionCommand $command;
@@ -31,7 +34,7 @@ protected function setUp(): void
3134
$this->command = new EntityRegionCommand(new SingleManagerProvider($this->_em));
3235

3336
$this->application = new Application();
34-
$this->application->add($this->command);
37+
self::addCommandToApplication($this->application, $this->command);
3538
}
3639

3740
public function testClearAllRegion(): void

tests/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Tools\Console\Command;
66

7+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
78
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand;
89
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
910
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -14,6 +15,8 @@
1415
#[Group('DDC-2183')]
1516
class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
1617
{
18+
use ApplicationCompatibility;
19+
1720
private Application $application;
1821

1922
private QueryRegionCommand $command;
@@ -27,7 +30,7 @@ protected function setUp(): void
2730
$this->command = new QueryRegionCommand(new SingleManagerProvider($this->_em));
2831

2932
$this->application = new Application();
30-
$this->application->add($this->command);
33+
self::addCommandToApplication($this->application, $this->command);
3134
}
3235

3336
public function testClearAllRegion(): void

tests/Tests/ORM/Tools/Console/Command/InfoCommandTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ORM\Configuration;
88
use Doctrine\ORM\EntityManagerInterface;
99
use Doctrine\ORM\Mapping\MappingException;
10+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
1011
use Doctrine\ORM\Tools\Console\Command\InfoCommand;
1112
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
1213
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
@@ -18,6 +19,8 @@
1819

1920
class InfoCommandTest extends OrmFunctionalTestCase
2021
{
22+
use ApplicationCompatibility;
23+
2124
private Application $application;
2225
private InfoCommand $command;
2326
private CommandTester $tester;
@@ -28,7 +31,7 @@ protected function setUp(): void
2831

2932
$this->application = new Application();
3033

31-
$this->application->add(new InfoCommand(new SingleManagerProvider($this->_em)));
34+
self::addCommandToApplication($this->application, new InfoCommand(new SingleManagerProvider($this->_em)));
3235

3336
$this->command = $this->application->find('orm:info');
3437
$this->tester = new CommandTester($this->command);
@@ -58,7 +61,7 @@ public function testEmptyEntityClassNames(): void
5861
->willReturn($configuration);
5962

6063
$application = new Application();
61-
$application->add(new InfoCommand(new SingleManagerProvider($em)));
64+
self::addCommandToApplication($application, new InfoCommand(new SingleManagerProvider($em)));
6265

6366
$command = $application->find('orm:info');
6467
$tester = new CommandTester($command);
@@ -96,7 +99,7 @@ public function testInvalidEntityClassMetadata(): void
9699
->willThrowException(new MappingException('exception message'));
97100

98101
$application = new Application();
99-
$application->add(new InfoCommand(new SingleManagerProvider($em)));
102+
self::addCommandToApplication($application, new InfoCommand(new SingleManagerProvider($em)));
100103

101104
$command = $application->find('orm:info');
102105
$tester = new CommandTester($command);

tests/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Tools\Console\Command;
66

7+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
78
use Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand;
89
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
910
use Doctrine\Tests\Models\Cache\AttractionInfo;
@@ -19,6 +20,8 @@
1920
#[CoversClass(MappingDescribeCommand::class)]
2021
class MappingDescribeCommandTest extends OrmFunctionalTestCase
2122
{
23+
use ApplicationCompatibility;
24+
2225
private Application $application;
2326

2427
private MappingDescribeCommand $command;
@@ -30,7 +33,7 @@ protected function setUp(): void
3033
parent::setUp();
3134

3235
$this->application = new Application();
33-
$this->application->add(new MappingDescribeCommand(new SingleManagerProvider($this->_em)));
36+
self::addCommandToApplication($this->application, new MappingDescribeCommand(new SingleManagerProvider($this->_em)));
3437

3538
$this->command = $this->application->find('orm:mapping:describe');
3639
$this->tester = new CommandTester($this->command);

tests/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Tools\Console\Command;
66

7+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
78
use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
89
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
910
use Doctrine\Tests\Models\Generic\DateTimeModel;
@@ -20,6 +21,8 @@
2021
#[CoversClass(RunDqlCommand::class)]
2122
class RunDqlCommandTest extends OrmFunctionalTestCase
2223
{
24+
use ApplicationCompatibility;
25+
2326
private Application $application;
2427

2528
private RunDqlCommand $command;
@@ -35,7 +38,7 @@ protected function setUp(): void
3538
$this->command = new RunDqlCommand(new SingleManagerProvider($this->_em));
3639

3740
$this->application = new Application();
38-
$this->application->add($this->command);
41+
self::addCommandToApplication($this->application, $this->command);
3942

4043
$this->tester = new CommandTester($this->command);
4144
}

tests/Tests/ORM/Tools/Console/Command/ValidateSchemaCommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Platforms\SQLitePlatform;
88
use Doctrine\DBAL\Schema\SchemaDiff;
9+
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
910
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand;
1011
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
1112
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -22,6 +23,8 @@
2223
#[CoversClass(ValidateSchemaCommand::class)]
2324
class ValidateSchemaCommandTest extends OrmFunctionalTestCase
2425
{
26+
use ApplicationCompatibility;
27+
2528
private ValidateSchemaCommand $command;
2629

2730
private CommandTester $tester;
@@ -39,7 +42,7 @@ protected function setUp(): void
3942
}
4043

4144
$application = new Application();
42-
$application->add(new ValidateSchemaCommand(new SingleManagerProvider($this->_em)));
45+
self::addCommandToApplication($application, new ValidateSchemaCommand(new SingleManagerProvider($this->_em)));
4346

4447
$this->command = $application->find('orm:validate-schema');
4548
$this->tester = new CommandTester($this->command);

0 commit comments

Comments
 (0)