public function AcquiaConnectorCommands::customTestValidate in Acquia Connector 8
Same name and namespace in other branches
- 8.2 src/Commands/AcquiaConnectorCommands.php \Drupal\acquia_connector\Commands\AcquiaConnectorCommands::customTestValidate()
- 3.x src/Commands/AcquiaConnectorCommands.php \Drupal\acquia_connector\Commands\AcquiaConnectorCommands::customTestValidate()
A command callback and drush wrapper for custom test validation.
@command acquia:connector:spi-test-validate
@aliases acquia:connector:spi-tv
@usage acquia:connector:spi-test-validate Perform a validation check on any modules with Acquia SPI custom tests.
@validate-module-enabled acquia_connector
File
- src/
Commands/ AcquiaConnectorCommands.php, line 85
Class
- AcquiaConnectorCommands
- A Drush command file.
Namespace
Drupal\acquia_connector\CommandsCode
public function customTestValidate() {
$modules = \Drupal::moduleHandler()
->getImplementations('acquia_connector_spi_test');
if (!$modules) {
$this->output
->writeln((string) dt('No Acquia SPI custom tests were detected.'));
return;
}
$this->output
->writeln((string) dt('Acquia SPI custom tests were detected in: @modules ' . PHP_EOL, [
'@modules' => implode(', ', $modules),
]));
$pass = [];
$failure = [];
foreach ($modules as $module) {
$function = $module . '_acquia_connector_spi_test';
if (!function_exists($function)) {
continue;
}
$testStatus = new TestStatusController();
$result = $testStatus
->testValidate($function());
if (!$result['result']) {
$failure[] = $module;
$this->output
->writeln((string) dt("[FAILED] Validation failed for '@module' and has been logged.", [
'@module' => $module,
]));
foreach ($result['failure'] as $test_name => $test_failures) {
foreach ($test_failures as $test_param => $test_value) {
$variables = [
'@module_name' => $module,
'@message' => $test_value['message'],
'@param_name' => $test_param,
'@test_name' => $test_name,
'@value' => $test_value['value'],
];
$this->output
->writeln((string) dt("[DETAILS] @message for parameter '@param_name'; current value '@value'. (Test @test_name in module @module_name)", $variables));
$this->logger
->error("<em>Custom test validation failed</em>: @message for parameter '@param_name'; current value '@value'. (<em>Test '@test_name' in module '@module_name'</em>)", $variables);
}
}
}
else {
$pass[] = $module;
$this->output
->writeln((string) dt("[PASSED] Validation passed for '@module.'", [
'@module' => $module,
]));
}
$this->output
->writeln('');
}
$this->output
->writeln((string) dt('Validation checks completed.'));
$variables = [];
if (count($pass) > 0) {
$variables['@passes'] = implode(', ', $pass);
$variables['@pass_count'] = count($pass);
$this->output
->writeln((string) dt('@pass_count module(s) passed validation: @passes.'), $variables);
}
if (count($failure) > 0) {
$variables['@failures'] = implode(', ', $failure);
$variables['@fail_count'] = count($failure);
$this->output
->writeln((string) dt('@fail_count module(s) failed validation: @failures.'), $variables);
}
}