From 55486e782d54361f8dee05a54fac491ed73c928a Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Thu, 15 Feb 2024 11:33:38 -0500 Subject: [PATCH] feat: require PHP 8.1+ and Symfony 6.4+ --- .github/workflows/ci.yml | 23 ++++++++- composer.json | 15 +++--- src/InvokableServiceCommand.php | 23 +-------- tests/Fixture/Kernel.php | 5 +- .../WithAttributesServiceCommandTest.php | 8 --- tests/Unit/AutoNameTest.php | 20 -------- tests/Unit/ConfigureWithAttributesTest.php | 4 -- tests/Unit/ConfigureWithDocblocksTest.php | 49 ------------------- 8 files changed, 32 insertions(+), 115 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6a7702..7c8f866 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,26 @@ on: jobs: test: - uses: zenstruck/.github/.github/workflows/php-test-symfony.yml@main + name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.deps }} + runs-on: ubuntu-latest + strategy: + matrix: + php: [8.1, 8.2, 8.3 ] + deps: [highest] + symfony: [6.4.*, 7.0.*] + include: + - php: 8.1 + deps: lowest + symfony: '*' + exclude: + - php: 8.1 + symfony: 7.0.* + steps: + - uses: zenstruck/.github/actions/php-test-symfony@main + with: + php: ${{ matrix.php }} + symfony: ${{ matrix.symfony }} + deps: ${{ matrix.deps }} code-coverage: uses: zenstruck/.github/.github/workflows/php-coverage-codecov.yml@main @@ -27,7 +46,7 @@ jobs: steps: - uses: zenstruck/.github@php-cs-fixer with: - php: 8.0 + php: 8.1 key: ${{ secrets.GPG_PRIVATE_KEY }} token: ${{ secrets.COMPOSER_TOKEN }} diff --git a/composer.json b/composer.json index c3d2852..9bc2a16 100644 --- a/composer.json +++ b/composer.json @@ -12,22 +12,25 @@ } ], "require": { - "php": ">=8.0", - "symfony/console": "^5.4|^6.0|^7.0", + "php": ">=8.1", + "symfony/console": "^6.4|^7.0", "symfony/deprecation-contracts": "^2.2|^3.0", - "symfony/string": "^5.4|^6.0|^7.0", + "symfony/string": "^6.4|^7.0", "zenstruck/callback": "^1.4.2" }, "require-dev": { "phpdocumentor/reflection-docblock": "^5.2", "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^9.5", - "symfony/framework-bundle": "^5.4|^6.0|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", "symfony/phpunit-bridge": "^6.2|^7.0", - "symfony/process": "^5.4|^6.0|^7.0", - "symfony/var-dumper": "^5.4|^6.0|^7.0", + "symfony/process": "^6.4|^7.0", + "symfony/var-dumper": "^6.4|^7.0", "zenstruck/console-test": "^1.3" }, + "conflict": { + "symfony/service-contracts": "<3.2" + }, "config": { "preferred-install": "dist", "sort-packages": true diff --git a/src/InvokableServiceCommand.php b/src/InvokableServiceCommand.php index fe9efb3..61fbcf5 100644 --- a/src/InvokableServiceCommand.php +++ b/src/InvokableServiceCommand.php @@ -18,7 +18,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\StyleInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Contracts\Service\Attribute\Required; use Symfony\Contracts\Service\Attribute\SubscribedService; use Symfony\Contracts\Service\ServiceSubscriberInterface; @@ -41,12 +40,10 @@ abstract class InvokableServiceCommand extends Command implements ServiceSubscri public static function getSubscribedServices(): array { - $supportsAttributes = self::supportsAttributes(); - $services = \array_values( \array_filter( \array_map( - static function(\ReflectionParameter $parameter) use ($supportsAttributes) { + static function(\ReflectionParameter $parameter) { if (!$type = $parameter->getType()) { return null; } @@ -69,14 +66,6 @@ static function(\ReflectionParameter $parameter) use ($supportsAttributes) { return null; } - if (!$supportsAttributes && $type->isBuiltin()) { - return null; - } - - if (!$supportsAttributes) { - return $type->allowsNull() ? '?'.$name : $name; - } - if ($parameter->getAttributes(Option::class) || $parameter->getAttributes(Argument::class)) { return null; // don't auto-inject options/arguments } @@ -131,16 +120,6 @@ final protected function parameter(string $name): mixed return $this->container()->get(ParameterBagInterface::class)->get($name); } - private static function supportsAttributes(): bool - { - if (!$constructor = (new \ReflectionClass(TypedReference::class))->getConstructor()) { - return false; - } - - // super hacky... but it's the only way currently to detect if symfony/di supports SubscribedService with attributes - return $constructor->getNumberOfParameters() > 4; - } - /** * @return array{0:string,1:bool} */ diff --git a/tests/Fixture/Kernel.php b/tests/Fixture/Kernel.php index 77757f4..0b8d31e 100644 --- a/tests/Fixture/Kernel.php +++ b/tests/Fixture/Kernel.php @@ -39,10 +39,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load { $c->register(ServiceCommand::class)->setAutowired(true)->setAutoconfigured(true); $c->register(ServiceSubscriberTraitCommand::class)->setAutowired(true)->setAutoconfigured(true); - - if (self::VERSION_ID >= 60200) { - $c->register(WithAttributesServiceCommand::class)->setAutowired(true)->setAutoconfigured(true); - } + $c->register(WithAttributesServiceCommand::class)->setAutowired(true)->setAutoconfigured(true); $c->register('imp1', Implementation1::class); $c->register('imp2', Implementation2::class); diff --git a/tests/Integration/WithAttributesServiceCommandTest.php b/tests/Integration/WithAttributesServiceCommandTest.php index f19ab08..a5d7397 100644 --- a/tests/Integration/WithAttributesServiceCommandTest.php +++ b/tests/Integration/WithAttributesServiceCommandTest.php @@ -13,7 +13,6 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Console\Test\InteractsWithConsole; -use Zenstruck\Console\Tests\Fixture\Kernel; /** * @author Kevin Bond @@ -22,13 +21,6 @@ final class WithAttributesServiceCommandTest extends KernelTestCase { use InteractsWithConsole; - protected function setUp(): void - { - if (Kernel::VERSION_ID < 60200) { - $this->markTestSkipped('Requires Symfony 6.2+'); - } - } - /** * @test */ diff --git a/tests/Unit/AutoNameTest.php b/tests/Unit/AutoNameTest.php index 871ba62..1e63f3a 100644 --- a/tests/Unit/AutoNameTest.php +++ b/tests/Unit/AutoNameTest.php @@ -16,7 +16,6 @@ use Zenstruck\Console\AutoName; use Zenstruck\Console\Tests\Fixture\Command\AutoNameCommand; use Zenstruck\Console\Tests\Fixture\Command\AutoNameNoPrefixCommand; -use Zenstruck\Console\Tests\Fixture\Kernel; /** * @author Kevin Bond @@ -43,25 +42,6 @@ public function can_remove_prefix(): void $this->assertSame('auto-name-no-prefix', (new AutoNameNoPrefixCommand())->getName()); } - /** - * @test - */ - public function can_use_traditional_naming_method(): void - { - if (Kernel::MAJOR_VERSION > 6) { - $this->markTestSkipped(); - } - - $command = new class() extends Command { - use AutoName; - - protected static $defaultName = 'override'; - }; - - $this->assertSame('override', $command::getDefaultName()); - $this->assertSame('override', $command->getName()); - } - /** * @test */ diff --git a/tests/Unit/ConfigureWithAttributesTest.php b/tests/Unit/ConfigureWithAttributesTest.php index 0fe5bc4..adb4ee9 100644 --- a/tests/Unit/ConfigureWithAttributesTest.php +++ b/tests/Unit/ConfigureWithAttributesTest.php @@ -121,10 +121,6 @@ public function option_attribute_name_required_when_using_on_class(): void */ public function negatable_parameter_attribute_options(): void { - if (!\defined(InputOption::class.'::VALUE_NEGATABLE')) { - $this->markTestSkipped('Negatable arguments not available.'); - } - $command = TestCommand::for( new class() extends Command { use ConfigureWithAttributes, Invokable; diff --git a/tests/Unit/ConfigureWithDocblocksTest.php b/tests/Unit/ConfigureWithDocblocksTest.php index 9176bd1..b444ce1 100644 --- a/tests/Unit/ConfigureWithDocblocksTest.php +++ b/tests/Unit/ConfigureWithDocblocksTest.php @@ -15,7 +15,6 @@ use Zenstruck\Console\Configuration\DocblockConfiguration; use Zenstruck\Console\Tests\Fixture\Command\AutoNameDocblockCommand; use Zenstruck\Console\Tests\Fixture\Command\DocblockCommand; -use Zenstruck\Console\Tests\Fixture\Kernel; /** * @author Kevin Bond @@ -154,54 +153,6 @@ public function parse_arguments_and_options(): void $this->assertTrue($option->isValueRequired()); } - /** - * @test - */ - public function can_override_docblock_configuration_with_traditional_configuration(): void - { - if (Kernel::MAJOR_VERSION > 6) { - $this->markTestSkipped(); - } - - /** - * Not used description. - * - * Not used help. - * - * @command not:used:name - * - * @argument arg not used - * @option option not used - */ - $command = new class() extends DocblockCommand { - protected static $defaultName = 'traditional:name'; - protected static $defaultDescription = 'Traditional description'; - - protected function configure(): void - { - $this - ->setDescription(self::$defaultDescription) - ->setHelp('Traditional help') - ->addArgument('t1') - ->addOption('t2') - ; - } - }; - - if (DocblockConfiguration::supportsLazy()) { - // Symfony <5.3 does not have this feature - $this->assertSame('Traditional description', $command::getDefaultDescription()); - } - - $this->assertSame('traditional:name', $command::getDefaultName()); - $this->assertSame('Traditional description', $command->getDescription()); - $this->assertSame('Traditional help', $command->getHelp()); - $this->assertTrue($command->getDefinition()->hasArgument('t1')); - $this->assertTrue($command->getDefinition()->hasOption('t2')); - $this->assertFalse($command->getDefinition()->hasArgument('arg')); - $this->assertFalse($command->getDefinition()->hasOption('option')); - } - /** * @test */