diff --git a/core/lib/Drupal/Core/Extension/MissingDependencyException.php b/core/lib/Drupal/Core/Extension/MissingDependencyException.php new file mode 100644 index 0000000000000000000000000000000000000000..1cb07cd19345c93c466829a13a786f4974e9aa90 --- /dev/null +++ b/core/lib/Drupal/Core/Extension/MissingDependencyException.php @@ -0,0 +1,15 @@ + implode(', ', $module_list), + '%missing' => implode(', ', $missing_modules), + ))); } // Only process currently uninstalled modules. @@ -101,7 +105,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) { foreach (array_keys($module_data[$module]->requires) as $dependency) { if (!isset($module_data[$dependency])) { // The dependency does not exist. - return FALSE; + throw new MissingDependencyException(String::format('Unable to install modules: module %module is missing its dependency module %dependency.', array( + '%module' => $module, + '%dependency' => $dependency, + ))); } // Skip already installed modules. diff --git a/core/lib/Drupal/Core/Extension/ModuleInstallerInterface.php b/core/lib/Drupal/Core/Extension/ModuleInstallerInterface.php index 95cb25e0878e13c736121f4dad6da8194e23117b..bd2923a6d493c1033e46895d86c08fda6b9d5b7b 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstallerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstallerInterface.php @@ -31,7 +31,10 @@ interface ModuleInstallerInterface { * if you know $module_list is already complete. * * @return bool - * FALSE if one or more dependencies are missing, TRUE otherwise. + * TRUE if the modules were successfully installed. + * + * @throws \Drupal\Core\Extension\MissingDependencyException + * Thrown when a requested module, or a dependency of one, can not be found. * * @see hook_module_preinstall() * @see hook_install() diff --git a/core/modules/config/src/Tests/ConfigInstallWebTest.php b/core/modules/config/src/Tests/ConfigInstallWebTest.php index 521297336ea6c8b0df326aafef61c90cf52f158e..4defbd4033e88db12a963203366f146d4d18ffc6 100644 --- a/core/modules/config/src/Tests/ConfigInstallWebTest.php +++ b/core/modules/config/src/Tests/ConfigInstallWebTest.php @@ -132,8 +132,7 @@ function testInstallProfileConfigOverwrite() { // Turn on the test module, which will attempt to replace the // configuration data. This attempt to replace the active configuration // should be ignored. - $status = \Drupal::service('module_installer')->install(array('config_existing_default_config_test')); - $this->assertTrue($status, "The module config_existing_default_config_test was installed."); + \Drupal::service('module_installer')->install(array('config_existing_default_config_test')); // Verify that the test module has not been able to change the data. $config = $this->config($config_name); diff --git a/core/modules/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php index d2949a64cee53a0ee308f8210fdc759e95c25478..69421197aaad8292a79c4278df7c845b09e5b3de 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php @@ -210,7 +210,7 @@ function assertNothing() { * Confirm that the stub test produced the desired results. */ function confirmStubTestResults() { - $this->assertAssertion(t('Enabled modules: %modules', array('%modules' => 'non_existent_module')), 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->setUp()'); + $this->assertAssertion(t('Unable to install modules %modules due to missing modules %missing.', array('%modules' => 'non_existent_module', '%missing' => 'non_existent_module')), 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->setUp()'); $this->assertAssertion($this->passMessage, 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); $this->assertAssertion($this->failMessage, 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 4109d8381b22392f343ab93513167b70a51cd77f..2bd33fc6ddd00890095be40ca8148b40e6a9ac98 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -916,8 +916,15 @@ protected function setUp() { } if ($modules) { $modules = array_unique($modules); - $success = $container->get('module_installer')->install($modules, TRUE); - $this->assertTrue($success, String::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); + try { + $success = $container->get('module_installer')->install($modules, TRUE); + $this->assertTrue($success, String::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); + } + catch (\Drupal\Core\Extension\MissingDependencyException $e) { + // The exception message has all the details. + $this->fail($e->getMessage()); + } + $this->rebuildContainer(); } diff --git a/core/modules/system/src/Form/ModulesListConfirmForm.php b/core/modules/system/src/Form/ModulesListConfirmForm.php index 2a31dbecc3d9d8d5625d195176d4f720a83c1249..279b95ebf97189663ad71c5a784b507774e91b8e 100644 --- a/core/modules/system/src/Form/ModulesListConfirmForm.php +++ b/core/modules/system/src/Form/ModulesListConfirmForm.php @@ -153,6 +153,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // Install the given modules. if (!empty($this->modules['install'])) { + // Don't catch the exception that this can throw for missing dependencies: + // the form doesn't allow modules with unmet dependencies, so the only way + // this can happen is if the filesystem changed between form display and + // submit, in which case the user has bigger problems. $this->moduleInstaller->install(array_keys($this->modules['install'])); } diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php index 48fbf0e1dd73942e2a6d204e7c3a1a090a352f3c..130ffd2de3edae305e01efe5d23a635f649a98d6 100644 --- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php +++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php @@ -116,8 +116,14 @@ function testDependencyResolution() { \Drupal::state()->set('module_test.dependency', 'missing dependency'); drupal_static_reset('system_rebuild_module_data'); - $result = $this->moduleInstaller()->install(array('color')); - $this->assertFalse($result, 'ModuleHandler::install() returns FALSE if dependencies are missing.'); + try { + $result = $this->moduleInstaller()->install(array('color')); + $this->fail(t('ModuleInstaller::install() throws an exception if dependencies are missing.')); + } + catch (\Drupal\Core\Extension\MissingDependencyException $e) { + $this->pass(t('ModuleInstaller::install() throws an exception if dependencies are missing.')); + } + $this->assertFalse($this->moduleHandler()->moduleExists('color'), 'ModuleHandler::install() aborts if dependencies are missing.'); // Fix the missing dependency.