Skip to content

Commit 57c9f41

Browse files
authored
Merge pull request #29 from IonBazan/feature/symfony-7
Symfony 7 support
2 parents 972f371 + 005967f commit 57c9f41

12 files changed

+140
-32
lines changed

.github/workflows/test.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- '8.1'
2525
- '8.2'
2626
- '8.3'
27+
- '8.4'
2728
include:
2829
- php-versions: '5.3'
2930
dependencies: 'lowest'
@@ -38,7 +39,7 @@ jobs:
3839
operating-system: windows-latest
3940
steps:
4041
- name: Checkout
41-
uses: actions/checkout@v3
42+
uses: actions/checkout@v4
4243
- name: Setup PHP, with composer and extensions
4344
uses: shivammathur/setup-php@v2
4445
with:
@@ -57,15 +58,15 @@ jobs:
5758
- name: Upload coverage to Codecov
5859
uses: codecov/codecov-action@v3
5960
- name: Run mutation tests
60-
if: ${{ matrix.php-versions == 8.2 && matrix.operating-system == 'ubuntu-latest' }}
61+
if: ${{ matrix.php-versions == 8.3 && matrix.operating-system == 'ubuntu-latest' }}
6162
env:
6263
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
6364
run: |
6465
composer config --no-plugins allow-plugins.infection/extension-installer true
6566
composer req infection/infection -W
6667
vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=100 --min-msi=100 -s -j4
6768
- name: Run phpstan
68-
if: ${{ matrix.php-versions == 8.2 && matrix.operating-system == 'ubuntu-latest' }}
69+
if: ${{ matrix.php-versions == 8.3 && matrix.operating-system == 'ubuntu-latest' }}
6970
run: |
7071
composer req phpstan/phpstan
7172
vendor/bin/phpstan

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
"require-dev": {
2828
"composer/composer": "^1.1 || ^2.0",
29-
"symfony/console": "^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
30-
"symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0"
29+
"symfony/console": "^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
30+
"symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0 || ^7.0"
3131
},
3232
"suggest": {
3333
"composer/composer": "To use the binary without composer runtime",

infection.json.dist

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"source": {
33
"directories": [
44
"src"
5+
],
6+
"excludes": [
7+
"src/Command/BaseNotTypedCommand.php"
58
]
69
},
710
"logs": {

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ parameters:
44
- src
55
checkGenericClassInNonGenericObjectType: true
66
checkMissingIterableValueType: true
7+
bootstrapFiles:
8+
- src/Command/DiffCommand.php # contains class alias

src/Command/BaseNotTypedCommand.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Command;
4+
5+
use Composer\Command\BaseCommand;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
/**
10+
* @codeCoverageIgnore
11+
*
12+
* This class contains a non-typed version of execute() method (for PHP 5).
13+
*/
14+
abstract class BaseNotTypedCommand extends BaseCommand
15+
{
16+
protected function execute(InputInterface $input, OutputInterface $output)
17+
{
18+
return $this->handle($input, $output);
19+
}
20+
21+
/**
22+
* @return int
23+
*/
24+
abstract protected function handle(InputInterface $input, OutputInterface $output);
25+
}

src/Command/BaseTypedCommand.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Command;
4+
5+
use Composer\Command\BaseCommand;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
/**
10+
* @codeCoverageIgnore
11+
*
12+
* This class contains a typed version of execute() method (PHP 7+).
13+
*/
14+
abstract class BaseTypedCommand extends BaseCommand
15+
{
16+
protected function execute(InputInterface $input, OutputInterface $output): int
17+
{
18+
return $this->handle($input, $output);
19+
}
20+
21+
/**
22+
* @return int
23+
*/
24+
abstract protected function handle(InputInterface $input, OutputInterface $output);
25+
}

src/Command/DiffCommand.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace IonBazan\ComposerDiff\Command;
44

5-
use Composer\Command\BaseCommand;
65
use IonBazan\ComposerDiff\Diff\DiffEntries;
76
use IonBazan\ComposerDiff\Diff\DiffEntry;
87
use IonBazan\ComposerDiff\Formatter\Formatter;
@@ -17,6 +16,17 @@
1716
use Symfony\Component\Console\Input\InputOption;
1817
use Symfony\Component\Console\Output\OutputInterface;
1918

19+
/*
20+
* This is a trick to maintain compatibility with both PHP 5 and 7 with Symfony 2.3 all the way to 7 with typed returns.
21+
* This is only needed when using this package as a dependency with Symfony 7+, not when using as Composer plugin.
22+
*/
23+
class_alias(
24+
PHP_VERSION_ID >= 70000
25+
? 'IonBazan\ComposerDiff\Command\BaseTypedCommand'
26+
: 'IonBazan\ComposerDiff\Command\BaseNotTypedCommand',
27+
'IonBazan\ComposerDiff\Command\BaseCommand'
28+
);
29+
2030
class DiffCommand extends BaseCommand
2131
{
2232
const CHANGES_PROD = 2;
@@ -122,9 +132,9 @@ protected function configure()
122132
}
123133

124134
/**
125-
* {@inheritdoc}
135+
* @return int
126136
*/
127-
protected function execute(InputInterface $input, OutputInterface $output)
137+
protected function handle(InputInterface $input, OutputInterface $output)
128138
{
129139
$base = null !== $input->getArgument('base') ? $input->getArgument('base') : $input->getOption('base');
130140
$target = null !== $input->getArgument('target') ? $input->getArgument('target') : $input->getOption('target');
@@ -205,7 +215,7 @@ private function getFormatter(InputInterface $input, OutputInterface $output)
205215
return new MarkdownListFormatter($output, $urlGenerators);
206216
case 'github':
207217
return new GitHubFormatter($output, $urlGenerators);
208-
// case 'mdtable':
218+
// case 'mdtable':
209219
default:
210220
return new MarkdownTableFormatter($output, $urlGenerators);
211221
}

tests/Command/DiffCommandTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Composer\DependencyResolver\Operation\UninstallOperation;
88
use Composer\DependencyResolver\Operation\UpdateOperation;
99
use IonBazan\ComposerDiff\Command\DiffCommand;
10-
use IonBazan\ComposerDiff\Tests\Integration\ComposerApplication;
1110
use IonBazan\ComposerDiff\Tests\TestCase;
1211
use Symfony\Component\Console\Tester\CommandTester;
1312

@@ -21,7 +20,7 @@ class DiffCommandTest extends TestCase
2120
public function testItGeneratesReportInGivenFormat($expectedOutput, array $options)
2221
{
2322
$diff = $this->getMockBuilder('IonBazan\ComposerDiff\PackageDiff')->getMock();
24-
$application = new ComposerApplication();
23+
$application = $this->getComposerApplication();
2524
$command = new DiffCommand($diff, array('gitlab2.org'));
2625
$command->setApplication($application);
2726
$tester = new CommandTester($command);
@@ -53,7 +52,7 @@ public function testItGeneratesReportInGivenFormat($expectedOutput, array $optio
5352
public function testStrictMode($exitCode, array $prodOperations, array $devOperations)
5453
{
5554
$diff = $this->getMockBuilder('IonBazan\ComposerDiff\PackageDiff')->getMock();
56-
$application = new ComposerApplication();
55+
$application = $this->getComposerApplication();
5756
$command = new DiffCommand($diff, array('gitlab2.org'));
5857
$command->setApplication($application);
5958
$tester = new CommandTester($command);
@@ -252,7 +251,7 @@ public function outputDataProvider()
252251
'packages-dev' => array(
253252
),
254253
),
255-
128
254+
128
256255
).PHP_EOL,
257256
array(
258257
'--no-dev' => null,

tests/Integration/DiffCommandTest.php

+2-19
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace IonBazan\ComposerDiff\Tests\Integration;
44

5-
use Composer\Composer;
6-
use Composer\Console\Application;
75
use Composer\Factory;
8-
use Composer\IO\IOInterface;
96
use Composer\IO\NullIO;
107
use Composer\Package\Package;
118
use Composer\Plugin\PluginManager;
@@ -25,9 +22,8 @@ class DiffCommandTest extends TestCase
2522
*/
2623
public function testCommand($expectedOutput, array $input)
2724
{
28-
$application = new ComposerApplication();
2925
$command = new DiffCommand(new PackageDiff());
30-
$command->setApplication($application);
26+
$command->setApplication($this->getComposerApplication());
3127
$tester = new CommandTester($command);
3228
$result = $tester->execute($input);
3329
$this->assertSame(0, $result);
@@ -44,7 +40,7 @@ public function testCommand($expectedOutput, array $input)
4440
public function testComposerApplication($expectedOutput, array $input)
4541
{
4642
$input = array_merge(array('command' => 'diff'), $input);
47-
$app = new ComposerApplication();
43+
$app = $this->getComposerApplication();
4844
$app->setIO(new NullIO()); // For Composer v1
4945
$app->setAutoExit(false);
5046
$plugin = $this->getPluginPackage();
@@ -247,16 +243,3 @@ private function getPluginPackage()
247243
return $plugin;
248244
}
249245
}
250-
251-
class ComposerApplication extends Application
252-
{
253-
public function setIO(IOInterface $io)
254-
{
255-
$this->io = $io;
256-
}
257-
258-
public function setComposer(Composer $composer)
259-
{
260-
$this->composer = $composer;
261-
}
262-
}

tests/TestCase.php

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Composer\Package\PackageInterface;
77
use IonBazan\ComposerDiff\Diff\DiffEntries;
88
use IonBazan\ComposerDiff\Diff\DiffEntry;
9+
use IonBazan\ComposerDiff\Tests\Util\ComposerApplication;
10+
use IonBazan\ComposerDiff\Tests\Util\TypedComposerApplication;
911
use PHPUnit\Framework\MockObject\MockObject;
1012
use PHPUnit\Framework\TestCase as BaseTestCase;
1113

@@ -73,4 +75,12 @@ protected function getEntries(array $operations)
7375
return new DiffEntry($operation);
7476
}, $operations));
7577
}
78+
79+
/**
80+
* @return ComposerApplication|TypedComposerApplication
81+
*/
82+
protected function getComposerApplication()
83+
{
84+
return PHP_VERSION_ID >= 70000 ? new TypedComposerApplication() : new ComposerApplication();
85+
}
7686
}

tests/Util/ComposerApplication.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Tests\Util;
4+
5+
use Composer\Composer;
6+
use Composer\Console\Application;
7+
use Composer\IO\IOInterface;
8+
9+
class ComposerApplication extends Application
10+
{
11+
public function setIO(IOInterface $io)
12+
{
13+
$this->io = $io;
14+
}
15+
16+
public function setComposer(Composer $composer)
17+
{
18+
$this->composer = $composer;
19+
}
20+
21+
protected function getDefaultCommands()
22+
{
23+
return array();
24+
}
25+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Tests\Util;
4+
5+
use Composer\Composer;
6+
use Composer\Console\Application;
7+
use Composer\IO\IOInterface;
8+
9+
class TypedComposerApplication extends Application
10+
{
11+
public function setIO(IOInterface $io)
12+
{
13+
$this->io = $io;
14+
}
15+
16+
public function setComposer(Composer $composer)
17+
{
18+
$this->composer = $composer;
19+
}
20+
21+
protected function getDefaultCommands(): array
22+
{
23+
return array();
24+
}
25+
}

0 commit comments

Comments
 (0)