Skip to content

Commit 2022f9e

Browse files
authored
Fix Symfony 8 compatibility issues (#7009)
1 parent c9011eb commit 2022f9e

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ jobs:
226226
strategy:
227227
matrix:
228228
php-version:
229-
- "7.4"
229+
- "8.4"
230230

231231
steps:
232232
- name: "Checkout"
@@ -240,7 +240,9 @@ jobs:
240240
fail-fast: true
241241

242242
- name: "Lower minimum stability"
243-
run: "composer config minimum-stability dev"
243+
run: |
244+
composer config minimum-stability dev
245+
composer require --no-update --dev symfony/console:^8 symfony/cache:^8
244246
245247
- name: "Install development dependencies with Composer"
246248
uses: "ramsey/composer-install@v3"

src/Tools/Console/Command/CommandCompatibility.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,32 @@
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
1111

12-
if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
12+
// Symfony 8
13+
if ((new ReflectionMethod(Command::class, 'configure'))->hasReturnType()) {
1314
/** @internal */
1415
trait CommandCompatibility
1516
{
17+
protected function configure(): void
18+
{
19+
$this->doConfigure();
20+
}
21+
22+
protected function execute(InputInterface $input, OutputInterface $output): int
23+
{
24+
return $this->doExecute($input, $output);
25+
}
26+
}
27+
// Symfony 7
28+
} elseif ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) {
29+
/** @internal */
30+
trait CommandCompatibility
31+
{
32+
/** @return void */
33+
protected function configure()
34+
{
35+
$this->doConfigure();
36+
}
37+
1638
protected function execute(InputInterface $input, OutputInterface $output): int
1739
{
1840
return $this->doExecute($input, $output);
@@ -22,6 +44,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2244
/** @internal */
2345
trait CommandCompatibility
2446
{
47+
/** @return void */
48+
protected function configure()
49+
{
50+
$this->doConfigure();
51+
}
52+
2553
/**
2654
* {@inheritDoc}
2755
*

src/Tools/Console/Command/ReservedWordsCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public function setKeywordListClass($name, $class)
9797
$this->keywordLists[$name] = new $class();
9898
}
9999

100-
/** @return void */
101-
protected function configure()
100+
private function doConfigure(): void
102101
{
103102
$this
104103
->setName('dbal:reserved-words')

src/Tools/Console/Command/RunSqlCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public function __construct(ConnectionProvider $connectionProvider)
3737
$this->connectionProvider = $connectionProvider;
3838
}
3939

40-
/** @return void */
41-
protected function configure()
40+
private function doConfigure(): void
4241
{
4342
$this
4443
->setName('dbal:run-sql')

tests/Tools/Console/RunSqlCommandTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Application;
1212
use Symfony\Component\Console\Tester\CommandTester;
1313

14+
use function method_exists;
1415
use function str_replace;
1516

1617
class RunSqlCommandTest extends TestCase
@@ -26,7 +27,12 @@ protected function setUp(): void
2627
$this->connectionMock = $this->createMock(Connection::class);
2728
$this->command = new RunSqlCommand(new SingleConnectionProvider($this->connectionMock));
2829

29-
(new Application())->add($this->command);
30+
if (method_exists(Application::class, 'addCommand')) {
31+
// @phpstan-ignore method.notFound (This method will be added in Symfony 7.4)
32+
(new Application())->addCommand($this->command);
33+
} else {
34+
(new Application())->add($this->command);
35+
}
3036

3137
$this->commandTester = new CommandTester($this->command);
3238
}

0 commit comments

Comments
 (0)