-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
#3123 - Global D8 container is not available during container rebuild. #3124
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2fef2c7
#3123 - Global D8 container is not available during container rebuild.
kevin-dutra 213b9c6
#3123 - Coding standards adjustments.
kevin-dutra db810a3
#3123 - Missing include statement.
kevin-dutra 639c4c3
Merge branch 'master' into 3123-global-container
kevin-dutra 7c03be6
#3123 - Adding a test.
kevin-dutra 768e891
Merge branch 'master' into 3123-global-container
kevin-dutra 96df48e
Merge branch 'master' into 3123-global-container
weitzman 8db18e8
#3123 - Requested PR changes.
kevin-dutra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Unish; | ||
|
||
use Webmozart\PathUtil\Path; | ||
|
||
/** | ||
* Tests the Drush override of DrupalKernel. | ||
* | ||
* @group base | ||
*/ | ||
class containerTest extends CommandUnishTestCase { | ||
|
||
/** | ||
* Tests that the existing container is available while Drush rebuilds it. | ||
*/ | ||
public function testContainer() { | ||
$sites = $this->setUpDrupal(1, TRUE); | ||
$root = $this->webroot(); | ||
$options = array( | ||
'root' => $root, | ||
'uri' => key($sites), | ||
'yes' => NULL, | ||
); | ||
|
||
// Copy the 'woot' module over to the Drupal site we just set up. | ||
$this->setupModulesForTests($root); | ||
|
||
// Enable our module. | ||
$this->drush('pm-enable', ['woot'], $options); | ||
|
||
// Set up for a config import with just one small piece. | ||
$this->drush('config-export', array(), $options); | ||
$this->drush('config-set', array('system.site', 'name', 'config_test'), $options); | ||
|
||
// Trigger the container rebuild we need. | ||
$this->drush('cr', [], $options); | ||
$this->drush('cron', [], $options); | ||
|
||
// If the event was registered successfully, then upon a config import, we | ||
// should get the error message. | ||
$this->drush('config-import', [], $options, NULL, NULL, CommandUnishTestCase::EXIT_ERROR); | ||
$this->assertContains("woot config error", $this->getErrorOutput(), 'Event was successfully registered.'); | ||
} | ||
|
||
/** | ||
* Sets up the woot module for the test. | ||
* | ||
* @param string $root | ||
* The web root. | ||
*/ | ||
public function setupModulesForTests($root) { | ||
$wootModule = Path::join(__DIR__, '/resources/modules/d8/woot'); | ||
// We install into Unish so that we aren't cleaned up. That causes | ||
// container to go invalid after tearDownAfterClass(). | ||
$targetDir = Path::join($root, 'modules/unish/woot'); | ||
$this->mkdir($targetDir); | ||
$this->recursive_copy($wootModule, $targetDir); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
tests/resources/modules/d8/woot/src/EventSubscriber/ConfigSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Drupal\woot\EventSubscriber; | ||
|
||
use Drupal\Core\Config\ConfigEvents; | ||
use Drupal\Core\Config\ConfigImporterEvent; | ||
use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase; | ||
|
||
/** | ||
* Subscribes to Symfony events and maps them to Rules events. | ||
*/ | ||
class ConfigSubscriber extends ConfigImportValidateEventSubscriberBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
$events = []; | ||
|
||
// In this example, we would use information from the State API to determine | ||
// what events we should subscribe to. Suffice it to say we trust that the | ||
// State API works correctly, so we're only going to check if the service is | ||
// available here to make our point. | ||
if (\Drupal::hasService('state')) { | ||
$events[ConfigEvents::IMPORT_VALIDATE][] = 'onConfigImporterValidate'; | ||
} | ||
|
||
return $events; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function onConfigImporterValidate(ConfigImporterEvent $event) { | ||
// Always log an error. | ||
$importer = $event->getConfigImporter(); | ||
$importer->logError($this->t('woot config error')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
config.config_subscriber: | ||
class: Drupal\woot\EventSubscriber\ConfigSubscriber | ||
tags: | ||
- { name: event_subscriber } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now use $this->getUri() instead.