From f6ce970d9933f93e9fcdc5ab5b9f125184139725 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Fri, 12 Feb 2021 15:10:38 +0200 Subject: [PATCH 1/5] ISAICP-6037: Move command simulation tests in its own class. The reason is to allow 3rd party command providers to reuse this test by supplying a different data provider. --- tests/CommandSimulationTest.php | 82 +++++++++++++++++++++++++++++++++ tests/CommandsTest.php | 61 ------------------------ 2 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 tests/CommandSimulationTest.php diff --git a/tests/CommandSimulationTest.php b/tests/CommandSimulationTest.php new file mode 100644 index 0000000..7bd378b --- /dev/null +++ b/tests/CommandSimulationTest.php @@ -0,0 +1,82 @@ +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'); + } +} diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index d1ba659..d27b337 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -19,59 +19,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 @@ -413,14 +360,6 @@ public function testOverrideCommand($command, array $runnerConfig, array $expect } } - /** - * @return array - */ - public function simulationDataProvider() - { - return $this->getFixtureContent('simulation.yml'); - } - /** * @return array */ From 5501cb77f90ccdc57313e9168037987d935419d1 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Fri, 12 Feb 2021 15:25:29 +0200 Subject: [PATCH 2/5] ISAICP-6037: Fix some test classes namespaces. --- tests/CommandSimulationTest.php | 3 +-- tests/CommandsTest.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/CommandSimulationTest.php b/tests/CommandSimulationTest.php index 7bd378b..338a0c2 100644 --- a/tests/CommandSimulationTest.php +++ b/tests/CommandSimulationTest.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace OpenEuropa\TaskRunner\Tests\Commands; +namespace OpenEuropa\TaskRunner\Tests; use OpenEuropa\TaskRunner\TaskRunner; -use OpenEuropa\TaskRunner\Tests\AbstractTest; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Yaml\Yaml; diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index d27b337..d862209 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -2,11 +2,10 @@ 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; From ccaa56107503045804ddb17e95c891aca3c4d568 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Fri, 12 Feb 2021 18:28:10 +0200 Subject: [PATCH 3/5] ISAICP-6037: Drop changelog command. --- README.md | 1 - config/commands/changelog.yml | 6 --- src/Commands/ChangelogCommands.php | 62 ------------------------------ src/TaskRunner.php | 2 - tests/CommandsTest.php | 26 ------------- tests/fixtures/changelog.yml | 9 ----- tests/fixtures/simulation.yml | 44 --------------------- 7 files changed, 150 deletions(-) delete mode 100644 config/commands/changelog.yml delete mode 100644 src/Commands/ChangelogCommands.php delete mode 100644 tests/fixtures/changelog.yml diff --git a/README.md b/README.md index 6de9987..485e5b2 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/config/commands/changelog.yml b/config/commands/changelog.yml deleted file mode 100644 index 698fa93..0000000 --- a/config/commands/changelog.yml +++ /dev/null @@ -1,6 +0,0 @@ -command: - changelog: - generate: - options: - token: ${github.token} - tag: ~ diff --git a/src/Commands/ChangelogCommands.php b/src/Commands/ChangelogCommands.php deleted file mode 100644 index 2949366..0000000 --- a/src/Commands/ChangelogCommands.php +++ /dev/null @@ -1,62 +0,0 @@ - InputOption::VALUE_REQUIRED, - 'tag' => InputOption::VALUE_OPTIONAL, - ]) - { - $projectName = $this->getComposer()->getName(); - $exec = "{$projectName} -t {$options['token']}"; - if (!empty($options['tag'])) { - $exec .= " --future-release={$options['tag']}"; - } - - $task = $this->taskDockerRun('muccg/github-changelog-generator') - ->option('rm') - ->rawArg('-v $(pwd):$(pwd)') - ->rawArg('-w $(pwd)') - ->exec($exec); - - return $task; - } -} diff --git a/src/TaskRunner.php b/src/TaskRunner.php index 78e90ab..30ba8cc 100644 --- a/src/TaskRunner.php +++ b/src/TaskRunner.php @@ -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; @@ -73,7 +72,6 @@ class TaskRunner * @var array */ private $defaultCommandClasses = [ - ChangelogCommands::class, DrupalCommands::class, ReleaseCommands::class, RunnerCommands::class, diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index d862209..6b5b27e 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -4,7 +4,6 @@ namespace OpenEuropa\TaskRunner\Tests; -use OpenEuropa\TaskRunner\Commands\ChangelogCommands; use OpenEuropa\TaskRunner\TaskRunner; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -46,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. */ @@ -399,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(). * diff --git a/tests/fixtures/changelog.yml b/tests/fixtures/changelog.yml deleted file mode 100644 index cb15441..0000000 --- a/tests/fixtures/changelog.yml +++ /dev/null @@ -1,9 +0,0 @@ -- options: - token: "abc" - tag: ~ - expected: 'docker run --rm -v $(pwd):$(pwd) -w $(pwd) -i muccg/github-changelog-generator openeuropa/task-runner -t abc' - -- options: - token: "abc" - tag: "1.2.3" - expected: 'docker run --rm -v $(pwd):$(pwd) -w $(pwd) -i muccg/github-changelog-generator openeuropa/task-runner -t abc --future-release=1.2.3' diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index 0d60fb4..18fffbf 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -91,50 +91,6 @@ - "[Simulator] Running ./vendor/bin/drush -y --root=$(pwd)/build --site-name='Test site' --site-mail=info@example.org --locale=en --account-mail=admin@example.org --account-name=admin --account-pass=admin --sites-subdir=default --db-url='mysql://root:root@127.0.0.1:3306/drupal' --existing-config site-install standard" - "[WARNING] The 'config-dir' option is deprecated. Use 'existing-config' instead." -- command: 'changelog:generate' - configuration: - github: - token: "abc" - composer: > - { - "name": "foo/bar" - } - contains: - - "exec('foo/bar -t abc')" - -- command: 'changelog:generate --token def' - configuration: - github: - token: "abc" - composer: > - { - "name": "foo/bar" - } - contains: - - "exec('foo/bar -t def')" - -- command: 'changelog:generate --tag 1.2.3' - configuration: - github: - token: "abc" - composer: > - { - "name": "foo/bar" - } - contains: - - "exec('foo/bar -t abc --future-release=1.2.3')" - -- command: 'changelog:generate --token 123 --tag 1.2.3' - configuration: - github: - token: "abc" - composer: > - { - "name": "foo/bar" - } - contains: - - "exec('foo/bar -t 123 --future-release=1.2.3')" - - command: 'drupal:site-post-install' configuration: drupal: From 533e5d08d8a748396f9d4a92d2487501e65d60a1 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Wed, 17 Feb 2021 17:21:44 +0200 Subject: [PATCH 4/5] ISAICP-6037: Make command registration reusable. --- src/TaskRunner.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/TaskRunner.php b/src/TaskRunner.php index 30ba8cc..a10d97c 100644 --- a/src/TaskRunner.php +++ b/src/TaskRunner.php @@ -128,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); @@ -155,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"); } @@ -317,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. * From 9f22618a3075ea01d8f271ebfac36200e53f9f14 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 22 Feb 2021 11:37:54 +0200 Subject: [PATCH 5/5] ISAICP-6037: Depend on openeuropa/task-runner-changelog for BC. --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 655b6c1..80f95bd 100644 --- a/composer.json +++ b/composer.json @@ -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": {