Skip to content

Commit

Permalink
feat: require PHP 8.1+ and Symfony 6.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Feb 15, 2024
1 parent e5308d7 commit 55486e7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 115 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 1 addition & 22 deletions src/InvokableServiceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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}
*/
Expand Down
5 changes: 1 addition & 4 deletions tests/Fixture/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions tests/Integration/WithAttributesServiceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Console\Test\InteractsWithConsole;
use Zenstruck\Console\Tests\Fixture\Kernel;

/**
* @author Kevin Bond <kevinbond@gmail.com>
Expand All @@ -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
*/
Expand Down
20 changes: 0 additions & 20 deletions tests/Unit/AutoNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kevinbond@gmail.com>
Expand All @@ -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
*/
Expand Down
4 changes: 0 additions & 4 deletions tests/Unit/ConfigureWithAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 0 additions & 49 deletions tests/Unit/ConfigureWithDocblocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kevinbond@gmail.com>
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 55486e7

Please sign in to comment.