Skip to content

Commit 7da1c50

Browse files
committed
adjust how we add commands to application in tests for symfony 8
1 parent 08f88c1 commit 7da1c50

17 files changed

+38
-15
lines changed

.github/workflows/test-application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
dependencies: 'lowest'
2222
symfony-version: '*'
2323
- php-version: '8.1'
24-
symfony-version: '7.*'
24+
symfony-version: '6.*'
2525
- php-version: '8.2'
2626
symfony-version: '7.*'
2727
- php-version: '8.3'

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Changelog
44
2.x
55
---
66

7+
2.0.3
8+
-----
9+
10+
* Allow installation with Symfony Console 8.x.
11+
* Test with PHP 8.5.
12+
713
2.0.2
814
-----
915

tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHPUnit\Framework\MockObject\MockObject;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Component\Console\Application;
20+
use Symfony\Component\Console\Command\Command;
2021
use Symfony\Component\Console\Helper\HelperSet;
2122
use Symfony\Component\Console\Tester\CommandTester;
2223

@@ -110,6 +111,22 @@ public function setUp(): void
110111
$this->application->setHelperSet($this->helperSet);
111112
}
112113

114+
protected function addCommand(callable|Command $command): void
115+
{
116+
/* @phpstan-ignore function.alreadyNarrowedType */
117+
if (method_exists($this->application, 'addCommand')) {
118+
$this->application->addCommand($command);
119+
120+
return;
121+
}
122+
123+
if (!$command instanceof Command) {
124+
throw new \InvalidArgumentException('Until we remove support for symfony console < 7.4, all commands must extend the base class');
125+
}
126+
127+
$this->application->add($command);
128+
}
129+
113130
/**
114131
* Build and execute the command tester.
115132
*

tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setUp(): void
2323
->getMock();
2424

2525
$ndCommand = new NodeDumpCommand();
26-
$this->application->add($ndCommand);
26+
$this->addCommand($ndCommand);
2727
}
2828

2929
public function testCommand(): void

tests/PHPCR/Tests/Util/Console/Command/NodeMoveCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testCommand(array $args): void
3737
$this->session->expects($this->once())
3838
->method('save');
3939

40-
$this->application->add(new NodeMoveCommand());
40+
$this->addCommand(new NodeMoveCommand());
4141
$this->executeCommand('phpcr:node:move', $args);
4242
}
4343
}

tests/PHPCR/Tests/Util/Console/Command/NodeRemoveCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function setUp(): void
1212
{
1313
parent::setUp();
1414

15-
$this->application->add(new NodeRemoveCommand());
15+
$this->addCommand(new NodeRemoveCommand());
1616
}
1717

1818
public function testRemove(): void

tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setUp(): void
2626
parent::setUp();
2727

2828
$command = new NodeTouchCommand();
29-
$this->application->add($command);
29+
$this->addCommand($command);
3030

3131
// Override default concrete instance with mock
3232
$this->phpcrHelper = $this->getMockBuilder(PhpcrHelper::class)

tests/PHPCR/Tests/Util/Console/Command/NodeTypeListCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function setUp(): void
1919
{
2020
parent::setUp();
2121

22-
$this->application->add(new NodeTypeListCommand());
22+
$this->addCommand(new NodeTypeListCommand());
2323
$this->nodeTypeManager = $this->getMockBuilder(MockNodeTypeManager::class)
2424
->disableOriginalConstructor()
2525
->getMock();

tests/PHPCR/Tests/Util/Console/Command/NodeTypeRegisterCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function setUp(): void
1919
{
2020
parent::setUp();
2121

22-
$this->application->add(new NodeTypeRegisterCommand());
22+
$this->addCommand(new NodeTypeRegisterCommand());
2323
$this->nodeTypeManager = $this->getMockBuilder(MockNodeTypeManager::class)
2424
->disableOriginalConstructor()
2525
->getMock();

tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function setUp(): void
1919
{
2020
parent::setUp();
2121

22-
$this->application->add(new NodesUpdateCommand());
22+
$this->addCommand(new NodesUpdateCommand());
2323
$this->query = $this->createMock(QueryInterface::class);
2424
}
2525

0 commit comments

Comments
 (0)