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

DQA-5962: Refactor configurations load #647

Merged
merged 6 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
DQA-0: Cover command options configs.
  • Loading branch information
joaocsilva committed Mar 2, 2023
commit ee88abb3f9436564eb8641fe2d9f42bc348a8351
2 changes: 1 addition & 1 deletion resources/git/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Called by "git commit" with no arguments. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the commit.
#
# This hook should execute the PHPcs agaisnt the modified files.
# This hook should execute the PHPcs against the modified files.
#

./vendor/bin/run toolkit:hooks-run `basename "$0"`
10 changes: 0 additions & 10 deletions src/TaskRunner/AbstractCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public function getConfigurationFile()
return Toolkit::getToolkitRoot() . '/config/base.yml';
}

/**
* Command initialization.
*
* @hook pre-command-event *
*/
public function initializeRuntimeConfiguration()
{
Robo::loadConfiguration([$this->getConfigurationFile()], $this->getConfig());
}

/**
* Validate and return the path to given bin.
*
Expand Down
18 changes: 15 additions & 3 deletions src/TaskRunner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Runner

public const APPLICATION_NAME = 'Toolkit Runner';
public const REPOSITORY = 'ec-europa/toolkit';
public const CONFIG_DIR_KEY = 'runner.config_dir';

/**
* The input.
Expand Down Expand Up @@ -85,6 +84,13 @@ class Runner
*/
private $workingDir;

/**
* The loaded command classes.
*
* @var array
*/
private array $commandClasses;

/**
* Configurations that can be replaced by a project.
*
Expand Down Expand Up @@ -147,8 +153,8 @@ public function __construct(ClassLoader $classLoader, InputInterface $input, Out
*/
public function run()
{
$classes = $this->discoverCommandClasses();
$this->runner->registerCommandClasses($this->application, $classes);
$this->commandClasses = $this->discoverCommandClasses();
$this->runner->registerCommandClasses($this->application, $this->commandClasses);
$this->prepareConfigurations();
$this->registerConfigurationCommands();
return $this->runner->run($this->input, $this->output, $this->application);
Expand Down Expand Up @@ -233,6 +239,12 @@ private function prepareConfigurations()
$files = $this->getConfigDirFilesPaths($tkConfigDir);
$config = $this->parseConfigFiles($files, $config);

// Get the command options configurations from loaded command classes.
foreach ($this->commandClasses as $commandClass) {
$f = $this->runner->getContainer()->get("{$commandClass}Commands")->getConfigurationFile() ?? '';
$config = $this->parseConfigFiles([$f], $config);
}

// Save the project configurations separately to allow the overrides.
$projectConfig = [];
// Load the Project configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/Toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public static function getNextcloudPass(): string
*/
public static function filterFolders(array &$files)
{
$files = array_filter($files, function ($folder) {
$files = array_values(array_filter($files, function ($folder) {
return file_exists($folder);
});
}));
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/fixtures/commands/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,49 @@
- file1
- file2
- not_string_contains: src

- command: 'toolkit:test-behat --simulate'
configuration: []
resources:
- file: runner.yml.dist
content: |
toolkit:
test:
behat:
from: test-behat.yml.dist
expectations:
- contains: |
[Simulator] Simulating Exec('./vendor/bin/run toolkit:install-dependencies')
[Simulator] Running ./vendor/bin/run toolkit:install-dependencies
[Simulator] Simulating EcEuropa\Toolkit\Task\File\Process('test-behat.yml.dist', 'behat.yml')
[Simulator] Running ./vendor/bin/behat --profile=default --strict --dry-run
[Simulator] Simulating Exec('./vendor/bin/behat')
->options(array (
'profile' => 'default',
'strict' => NULL,
), '=')
[Simulator] Running ./vendor/bin/behat --profile=default --strict

- command: 'toolkit:test-behat --simulate'
configuration: []
resources:
- touch: test-behat.yml.dist
- file: runner.yml.dist
content: |
command:
toolkit:
test-behat:
options:
from: test-behat.yml.dist
expectations:
- contains: |
[Simulator] Simulating Exec('./vendor/bin/run toolkit:install-dependencies')
[Simulator] Running ./vendor/bin/run toolkit:install-dependencies
[Simulator] Simulating EcEuropa\Toolkit\Task\File\Process('test-behat.yml.dist', 'behat.yml')
[Simulator] Running ./vendor/bin/behat --profile=default --strict --dry-run
[Simulator] Simulating Exec('./vendor/bin/behat')
->options(array (
'profile' => 'default',
'strict' => NULL,
), '=')
[Simulator] Running ./vendor/bin/behat --profile=default --strict