Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return values instead of keys in discoverCommandsFromConfiguration. #5039

Merged
merged 4 commits into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Application.php
Expand Up @@ -351,7 +351,7 @@ protected function discoverCommandsFromConfiguration()
}
}
$this->loadCommandClasses($commandList);
return array_keys($commandList);
return array_values($commandList);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/drush-extensions/DrushExtensionsCommands.php
@@ -0,0 +1,20 @@
<?php

namespace Drush\Commands\drush_extensions;

use Drush\Commands\DrushCommands;

class DrushExtensionsCommands extends DrushCommands
{
/**
* Command to load from this file using drush config.
*
* @command drush-extensions-hello
* @bootstrap none
* @hidden
*/
public function customCommand(): void
{
$this->io()->text('Hello world!');
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/drush-extensions/drush.yml
@@ -0,0 +1,8 @@
#
# Drush configuration file used to configure the System Unter Test (sut)
#
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml
#
drush:
commands:
'\Drush\Commands\drush_extensions\DrushExtensionsCommands': '${env.FIXTURES_DIR}/drush-extensions/DrushExtensionsCommands.php'
27 changes: 27 additions & 0 deletions tests/integration/CommandsFromConfigurationTest.php
@@ -0,0 +1,27 @@
<?php

namespace Unish;

/**
* @group commands
*/
class CommandsFromConfigurationTest extends UnishIntegrationTestCase
{
/**
* Tests that commands provided by custom libraries are registered.
*/
public function testCommandsFromConfiguration(): void
{
$this->drush('drush-extensions-hello', [], ['help' => null], self::EXIT_ERROR);
$this->assertStringContainsString('Command "drush-extensions-hello" is not defined.', $this->getErrorOutput());
$this->drush('drush-extensions-hello', [], [
'help' => null,
'config' => getenv('FIXTURES_DIR') . '/drush-extensions/drush.yml',
]);
$this->assertStringContainsString('Command to load from this file using drush config.', $this->getOutput());
$this->drush('drush-extensions-hello', [], [
'config' => getenv('FIXTURES_DIR') . '/drush-extensions/drush.yml',
]);
$this->assertStringContainsString('Hello world!', $this->getOutput());
}
}
1 change: 1 addition & 0 deletions tests/unish/UnishTestCase.php
Expand Up @@ -71,6 +71,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
self::setEnv(['ETC_PREFIX' => $unish_sandbox]);
self::setEnv(['SHARE_PREFIX' => $unish_sandbox]);
self::setEnv(['TEMP' => Path::join($unish_sandbox, 'tmp')]);
self::setEnv(['FIXTURES_DIR' => Path::join(dirname(__DIR__), 'fixtures')]);
}

/**
Expand Down