Skip to content

Commit

Permalink
Return values instead of keys in discoverCommandsFromConfiguration. (#…
Browse files Browse the repository at this point in the history
…5039)

* Return values instead of keys in discoverCommandsFromConfiguration.

* Add testCommandsFromConfiguration test.

* Change wording for command not found.

* Fix wording one more time and enable commented out tests.
  • Loading branch information
kporras07 committed Jan 24, 2022
1 parent 6a9187f commit 25b52ff
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
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

0 comments on commit 25b52ff

Please sign in to comment.