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

ISAICP-6037: Move changelog command in its own repo #148

Merged
merged 5 commits into from
Feb 24, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ The Task Runner comes with the following built-in commands:

| Command | Description |
| ---------------------------- |-------------|
| `changelog:generate` | Generate a changelog for the current project based on its GitHub issues and pull requests |
| `drupal:site-install` | Install a target Drupal site using default configuration values and/or CLI options |
| `drupal:site-pre-install` | Run Drupal pre-install commands as listed under the `drupal.pre_install` property |
| `drupal:site-post-install` | Run Drupal post-install commands as listed under the `drupal.post_install` property |
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"gitonomy/gitlib": "^1.0",
"jakeasmith/http_build_url": "^1.0.1",
"nuvoleweb/robo-config": "^0.2.1",
"openeuropa/task-runner-changelog": "^1.0",
"symfony/console": "^3.4.21|^4|^5"
},
"require-dev": {
Expand Down
6 changes: 0 additions & 6 deletions config/commands/changelog.yml

This file was deleted.

62 changes: 0 additions & 62 deletions src/Commands/ChangelogCommands.php

This file was deleted.

35 changes: 20 additions & 15 deletions src/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Consolidation\Config\Loader\ConfigProcessor;
use Gitonomy\Git\Repository;
use League\Container\ContainerAwareTrait;
use OpenEuropa\TaskRunner\Commands\ChangelogCommands;
use OpenEuropa\TaskRunner\Commands\DrupalCommands;
use OpenEuropa\TaskRunner\Commands\DynamicCommands;
use OpenEuropa\TaskRunner\Commands\ReleaseCommands;
Expand Down Expand Up @@ -73,7 +72,6 @@ class TaskRunner
* @var array
*/
private $defaultCommandClasses = [
ChangelogCommands::class,
DrupalCommands::class,
ReleaseCommands::class,
RunnerCommands::class,
Expand Down Expand Up @@ -130,17 +128,7 @@ public function __construct(InputInterface $input, OutputInterface $output, Clas
*/
public function run()
{
// Discover early the commands to allow dynamic command overrides.
$commandClasses = $this->discoverCommandClasses();
$commandClasses = array_merge($this->defaultCommandClasses, $commandClasses);

// Register command classes.
$this->runner->registerCommandClasses($this->application, $commandClasses);

// Register commands defined in runner.yml file. These are registered
// after the command classes so that dynamic commands can override
// commands defined in classes.
$this->registerDynamicCommands($this->application);
$this->registerCommands();

// Run the command entered by the user in the CLI.
return $this->runner->run($this->input, $this->output, $this->application);
Expand All @@ -157,8 +145,7 @@ public function run()
public function getCommands($class)
{
// Register command classes.
$this->runner->registerCommandClasses($this->application, $this->defaultCommandClasses);

$this->registerCommands();
return $this->getContainer()->get("{$class}Commands");
}

Expand Down Expand Up @@ -319,6 +306,24 @@ private function getWorkingDir(InputInterface $input)
return $input->getParameterOption('--working-dir', getcwd());
}

/**
* Register all commands.
*/
private function registerCommands(): void
{
// Discover early the commands to allow dynamic command overrides.
$commandClasses = $this->discoverCommandClasses();
$commandClasses = array_merge($this->defaultCommandClasses, $commandClasses);

// Register command classes.
$this->runner->registerCommandClasses($this->application, $commandClasses);

// Register commands defined in runner.yml file. These are registered
// after the command classes so that dynamic commands can override
// commands defined in classes.
$this->registerDynamicCommands($this->application);
}

/**
* Registers dynamic commands in the container so Robo can find them.
*
Expand Down
81 changes: 81 additions & 0 deletions tests/CommandSimulationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Tests;

use OpenEuropa\TaskRunner\TaskRunner;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Yaml\Yaml;

/**
* Tests command simulation.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CommandSimulationTest extends AbstractTest
{
/**
* Runs simulations of commands and checks the command output.
*
* Robo allows tasks to be simulated. If a command is executed with the
* `--simulate` option, then instead of actually performing the tasks that
* are included in the command, Robo will output the parameters that have
* been passed in.
*
* This test is used for commands that pass data through to tasks that are
* provided by third parties. By using the simulator we can assert that we
* are passing the right parameters. This is where our responsibility ends.
*
* Custom commands may reuse this test by overriding the data provider.
*
* @see \Robo\Task\Simulator
*
* @param string $command
* The command to test, including any command line arguments and options.
* @param array $config
* Configuration in YAML format that will be provided to the command being
* tested, as provided by `runner.yml`.
* @param string $composer
* Composer manifest in JSON format. This can be used to test the output
* of commands that read data from `composer.json`.
* @param array $expected
* An array of strings that are expected to be present in the simulated
* output.
* @param array $absent
* An optional array of strings that are expected to be absent in the
* simulated output.
*
* @dataProvider simulationDataProvider
*/
public function testSimulation($command, array $config, $composer, array $expected, array $absent = [])
{
$configFile = $this->getSandboxFilepath('runner.yml');
$composerFile = $this->getSandboxFilepath('composer.json');

file_put_contents($configFile, Yaml::dump($config));
file_put_contents($composerFile, $composer);

$input = new StringInput("{$command} --simulate --working-dir=" . $this->getSandboxRoot());
$output = new BufferedOutput();
$runner = new TaskRunner($input, $output, $this->getClassLoader());
$runner->run();

$text = $output->fetch();
foreach ($expected as $row) {
$this->assertContains($row, $text);
}
foreach ($absent as $row) {
$this->assertNotContains($row, $text);
}
}

/**
* @return array
*/
public function simulationDataProvider()
{
return $this->getFixtureContent('simulation.yml');
}
}
90 changes: 1 addition & 89 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Tests\Commands;
namespace OpenEuropa\TaskRunner\Tests;

use OpenEuropa\TaskRunner\Commands\ChangelogCommands;
use OpenEuropa\TaskRunner\TaskRunner;
use OpenEuropa\TaskRunner\Tests\AbstractTest;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\NullOutput;
Expand All @@ -19,59 +17,6 @@
*/
class CommandsTest extends AbstractTest
{
/**
* Runs simulations of commands and checks the command output.
*
* Robo allows tasks to be simulated. If a command is executed with the
* `--simulate` option, then instead of actually performing the tasks that
* are included in the command, Robo will output the parameters that have
* been passed in.
*
* This test is used for commands that pass data through to tasks that are
* provided by third parties. By using the simulator we can assert that we
* are passing the right parameters. This is where our responsibility ends.
*
* @see \Robo\Task\Simulator
*
* @param string $command
* The command to test, including any command line arguments and options.
* @param array $config
* Configuration in YAML format that will be provided to the command being
* tested, as provided by `runner.yml`.
* @param string $composer
* Composer manifest in JSON format. This can be used to test the output
* of commands that read data from `composer.json`.
* @param array $expected
* An array of strings that are expected to be present in the simulated
* output.
* @param array $absent
* An optional array of strings that are expected to be absent in the
* simulated output.
*
* @dataProvider simulationDataProvider
*/
public function testSimulation($command, array $config, $composer, array $expected, array $absent = [])
{
$configFile = $this->getSandboxFilepath('runner.yml');
$composerFile = $this->getSandboxFilepath('composer.json');

file_put_contents($configFile, Yaml::dump($config));
file_put_contents($composerFile, $composer);

$input = new StringInput("{$command} --simulate --working-dir=" . $this->getSandboxRoot());
$output = new BufferedOutput();
$runner = new TaskRunner($input, $output, $this->getClassLoader());
$runner->run();

$text = $output->fetch();
foreach ($expected as $row) {
$this->assertContains($row, $text);
}
foreach ($absent as $row) {
$this->assertNotContains($row, $text);
}
}

/**
* @param string $command
* @param string $source
Expand Down Expand Up @@ -100,23 +45,6 @@ public function testSetupCommands($command, $source, $destination, array $config
$this->assertEquals($expected, $actual);
}

/**
* @param array $options
* @param string $expected
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*
* @dataProvider changelogDataProvider
*/
public function testChangelogCommands(array $options, $expected)
{
$runner = new TaskRunner(new StringInput(''), new NullOutput(), $this->getClassLoader());
/** @var ChangelogCommands $commands */
$commands = $runner->getCommands(ChangelogCommands::class);
$this->assertEquals($expected, $commands->generateChangelog($options)->getCommand());
}

/**
* Test custom commands.
*/
Expand Down Expand Up @@ -413,14 +341,6 @@ public function testOverrideCommand($command, array $runnerConfig, array $expect
}
}

/**
* @return array
*/
public function simulationDataProvider()
{
return $this->getFixtureContent('simulation.yml');
}

/**
* @return array
*/
Expand Down Expand Up @@ -461,14 +381,6 @@ public function setupDataProvider()
return $this->getFixtureContent('setup.yml');
}

/**
* @return array
*/
public function changelogDataProvider()
{
return $this->getFixtureContent('changelog.yml');
}

/**
* Provides test cases for ::testOverrideCommand().
*
Expand Down
9 changes: 0 additions & 9 deletions tests/fixtures/changelog.yml

This file was deleted.

Loading