Skip to content

Commit

Permalink
Merge branch 'asika32764-symfony6'
Browse files Browse the repository at this point in the history
  • Loading branch information
stecman committed Nov 29, 2022
2 parents 5da449d + 582d102 commit a0b405f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ vendor
/build/
phpunit.xml
/composer.lock
/.phpunit.result.cache
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -65,6 +65,8 @@ If you don't need any custom completion behaviour, you can simply add the comple

Note: The type of shell (ZSH/BASH) is automatically detected using the `SHELL` environment variable at run time. In some circumstances, you may need to explicitly specify the shell type with the `--shell-type` option.

The current version supports Symfony 6 and PHP 8.x only, due to backwards compatibility breaks in Symfony 6. For older versions of Symfony and PHP, use [version 0.11.0](https://github.com/stecman/symfony-console-completion/releases/tag/0.11.0).


## How it works

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -9,11 +9,12 @@
}
],
"require": {
"php": ">=5.3.2",
"symfony/console": "~2.3 || ~3.0 || ~4.0 || ~5.0"
"php": ">=8.0.2",
"symfony/console": "~6.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8.36 || ~5.7 || ~6.4"
"phpunit/phpunit": "^9.5",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
Expand Down
7 changes: 2 additions & 5 deletions src/CompletionCommand.php
Expand Up @@ -34,16 +34,13 @@ protected function configure()
);

// Hide this command from listing if supported
// Command::setHidden() was not available before Symfony 3.2.0
if (method_exists($this, 'setHidden')) {
$this->setHidden(true);
}
$this->setHidden(true);
}

/**
* {@inheritdoc}
*/
public function getNativeDefinition()
public function getNativeDefinition(): InputDefinition
{
return $this->createDefinition();
}
Expand Down
27 changes: 7 additions & 20 deletions src/CompletionHandler.php
Expand Up @@ -451,28 +451,15 @@ protected function getAllOptions()
*/
protected function getCommandNames()
{
// Command::Hidden isn't supported before Symfony Console 3.2.0
// We don't complete hidden command names as these are intended to be private
if (method_exists('\Symfony\Component\Console\Command\Command', 'isHidden')) {
$commands = array();

foreach ($this->application->all() as $name => $command) {
if (!$command->isHidden()) {
$commands[] = $name;
}
}

return $commands;

} else {

// Fallback for compatibility with Symfony Console < 3.2.0
// This was the behaviour prior to pull #75
$commands = $this->application->all();
unset($commands['_completion']);
$commands = array();

return array_keys($commands);
foreach ($this->application->all() as $name => $command) {
if (!$command->isHidden()) {
$commands[] = $name;
}
}

return $commands;
}

/**
Expand Down
Expand Up @@ -2,6 +2,7 @@

namespace Stecman\Component\Symfony\Console\BashCompletion\Tests\Common;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use PHPUnit\Framework\TestCase;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionHandler;
Expand All @@ -12,20 +13,22 @@
*/
abstract class CompletionHandlerTestCase extends TestCase
{
use ArraySubsetAsserts;

/**
* @var Application
*/
protected $application;

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
require_once __DIR__ . '/../Fixtures/CompletionAwareCommand.php';
require_once __DIR__ . '/../Fixtures/HiddenCommand.php';
require_once __DIR__ . '/../Fixtures/TestBasicCommand.php';
require_once __DIR__ . '/../Fixtures/TestSymfonyStyleCommand.php';
}

protected function setUp()
protected function setUp(): void
{
$this->application = new Application('Base application');
$this->application->addCommands(array(
Expand Down
Expand Up @@ -16,6 +16,8 @@ class CompletionCommandTest extends TestCase
*/
public function testConflictingGlobalOptions()
{
$this->expectNotToPerformAssertions();

$app = new Application('Base application');

// Conflicting option shortcut
Expand Down
Expand Up @@ -21,7 +21,7 @@ public function testCompleteCommandNames()
{
$handler = $this->createHandler('app ');
$this->assertEquals(
array('help', 'list', 'completion-aware', 'wave', 'walk:north'),
array('help', 'list', 'completion', 'completion-aware', 'wave', 'walk:north'),
$this->getTerms($handler->runCompletion())
);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testHelpCommandCompletion()
{
$handler = $this->createHandler('app help ');
$this->assertEquals(
array('help', 'list', 'completion-aware', 'wave', 'walk:north'),
array('help', 'list', 'completion', 'completion-aware', 'wave', 'walk:north'),
$this->getTerms($handler->runCompletion())
);
}
Expand Down
Expand Up @@ -12,7 +12,7 @@ class HookFactoryTest extends TestCase
*/
protected $factory;

protected function setUp()
protected function setUp(): void
{
$this->factory = new HookFactory();
}
Expand Down Expand Up @@ -56,6 +56,8 @@ public function generateHookDataProvider()

public function testForMissingSemiColons()
{
$this->expectNotToPerformAssertions();

$class = new \ReflectionClass('Stecman\Component\Symfony\Console\BashCompletion\HookFactory');
$properties = $class->getStaticProperties();
$hooks = $properties['hooks'];
Expand Down

0 comments on commit a0b405f

Please sign in to comment.