Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 5516671

Browse files
authored
Fixes #1472: Execute Tests inside the VM where possible. (#1475)
* Fixes #1472: Execute Tests inside the VM where possible. * Removing superfluous function. * Fixing recursive command execution. * Fixing PHPCS
1 parent 62a9f6d commit 5516671

File tree

8 files changed

+57
-52
lines changed

8 files changed

+57
-52
lines changed

src/Robo/BltTasks.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Robo\Contract\BuilderAwareInterface;
1616
use Robo\Contract\ConfigAwareInterface;
1717
use Robo\Contract\IOAwareInterface;
18+
use Robo\Contract\VerbosityThresholdInterface;
1819
use Robo\LoadAllTasks;
1920
use Symfony\Component\Console\Helper\Table;
2021
use Symfony\Component\Console\Input\ArrayInput;
@@ -180,10 +181,13 @@ protected function installVagrantPlugin($plugin) {
180181
* The command result.
181182
*/
182183
protected function executeCommandInDrupalVm($command) {
184+
$this->say("Executing command <comment>$command</comment> inside of Drupal VM...");
183185
$this->installVagrantPlugin('vagrant-exec');
184-
$result = $this->taskExec("vagrant exec '$command'")
186+
$result = $this->taskExecStack()
187+
->exec("vagrant exec --tty '$command'")
185188
->dir($this->getConfigValue('repo.root'))
186-
->detectInteractive()
189+
->interactive(TRUE)
190+
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
187191
->run();
188192

189193
return $result;

src/Robo/Commands/Drupal/DrupalCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function install() {
2828
function ($string) {
2929
return !preg_match('/[^\x{80}-\x{F7} a-z0-9@+_.\'-]/i', $string);
3030
},
31-
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_-?/.,+=><'
31+
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#%^&*()_?/.,+=><'
3232
);
3333

3434
$task = $this->taskDrush()

src/Robo/Commands/Frontend/FrontendCommand.php

+11-37
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class FrontendCommand extends BltTasks {
1313
* Runs all frontend targets.
1414
*
1515
* @command frontend
16+
*
17+
* @executeInDrupalVm
1618
*/
1719
public function frontend() {
1820
$status_code = $this->invokeCommands([
@@ -23,65 +25,37 @@ public function frontend() {
2325
return $status_code;
2426
}
2527

26-
/**
27-
* Indicates whether a frontend hook should be invoked inside of Drupal VM.
28-
*
29-
* @return bool
30-
* TRUE if it should be invoked inside of Drupal VM.
31-
*/
32-
protected function shouldExecuteInDrupalVm() {
33-
return $this->getInspector()->isDrupalVmLocallyInitialized()
34-
&& $this->getInspector()->isDrupalVmBooted()
35-
&& !$this->getInspector()->isVmCli();
36-
}
37-
38-
/**
39-
* Invokes a frontend hook.
40-
*
41-
* The hook will be invoked in Drupal VM if is initialized and booted.
42-
* Otherwise, it will be invoked on the host machine.
43-
*
44-
* @param string $hook
45-
* The hook to invoke. E.g., "build" would invoke "frontend-build" hook.
46-
*
47-
* @return int|\Robo\Result
48-
* The status code or result object.
49-
*/
50-
protected function invokeFrontendHook($hook) {
51-
if ($this->shouldExecuteInDrupalVm()) {
52-
$this->say("Executing $hook target hook inside of Drupal VM...");
53-
return $this->executeCommandInDrupalVm("blt frontend:$hook");
54-
}
55-
else {
56-
return $this->invokeHook("frontend-$hook");
57-
}
58-
}
59-
6028
/**
6129
* Executes frontend-build target hook.
6230
*
6331
* @command frontend:build
32+
*
33+
* @executeInDrupalVm
6434
*/
6535
public function build() {
66-
return $this->invokeFrontendHook('build');
36+
return $this->invokeHook('frontend-build');
6737
}
6838

6939
/**
7040
* Executes frontend-setup target hook.
7141
*
7242
* @command frontend:setup
43+
*
44+
* @executeInDrupalVm
7345
*/
7446
public function setup() {
75-
return $this->invokeFrontendHook('setup');
47+
return $this->invokeHook('frontend-setup');
7648
}
7749

7850
/**
7951
* Executes frontend-test target hook.
8052
*
8153
* @command frontend:test
54+
*
55+
* @executeInDrupalVm
8256
*/
8357
public function test() {
84-
return $this->invokeFrontendHook('test');
58+
return $this->invokeHook('frontend-test');
8559
}
8660

8761
}

src/Robo/Commands/Setup/BuildCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function setup() {
4242
* @todo Add a @validateSettingsFilesArePresent
4343
*/
4444
public function drupalInstall() {
45-
$status_code = $this->invokeCommands(['drupal:install']);
45+
$status_code = $this->invokeCommands([
46+
'drupal:install',
47+
]);
4648
if ($status_code) {
4749
return $status_code;
4850
}

src/Robo/Commands/Tests/AllCommand.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class AllCommand extends BltTasks {
1313
* Runs all tests, including Behat, PHPUnit, and Security Update check.
1414
*
1515
* @command tests:all
16+
*
17+
* @executeInDrupalVm
1618
*/
1719
public function tests() {
1820
$status_code = $this->invokeCommands([

src/Robo/Commands/Tests/BehatCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function initialize() {
6060
* @validateDrupalIsInstalled
6161
* @validateBehatIsConfigured
6262
* @validateInsideVm
63+
* @executeInDrupalVm
6364
*/
6465
public function behat() {
6566
// Log config for debugging purposes.

src/Robo/Hooks/CommandEventHook.php

+30-9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
namespace Acquia\Blt\Robo\Hooks;
44

55
use Acquia\Blt\Robo\BltTasks;
6-
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
7-
use Psr\Log\LoggerAwareInterface;
8-
use Psr\Log\LoggerAwareTrait;
9-
use Robo\Contract\ConfigAwareInterface;
10-
use Robo\Contract\IOAwareInterface;
116
use Symfony\Component\Console\Event\ConsoleCommandEvent;
127

138
/**
@@ -16,10 +11,7 @@
1611
* These hooks typically use a Wizard to evaluate the validity of config or
1712
* state and guide the user toward resolving issues.
1813
*/
19-
class CommandEventHook extends BltTasks implements IOAwareInterface, ConfigAwareInterface, LoggerAwareInterface {
20-
21-
use ConfigAwareTrait;
22-
use LoggerAwareTrait;
14+
class CommandEventHook extends BltTasks {
2315

2416
/**
2517
* Disable any command listed in the `disable-target` config key.
@@ -33,4 +25,33 @@ public function skipDisabledCommands(ConsoleCommandEvent $event) {
3325
}
3426
}
3527

28+
/**
29+
* Execute a command inside of Drupal VM.
30+
*
31+
* @hook command-event *
32+
*/
33+
public function executeInDrupalVm(ConsoleCommandEvent $event) {
34+
$command = $event->getCommand();
35+
if (method_exists($command, 'getAnnotationData')) {
36+
/* @var \Consolidation\AnnotatedCommand\AnnotationData */
37+
$annotation_data = $event->getCommand()->getAnnotationData();
38+
if ($annotation_data->has('executeInDrupalVm') && $this->shouldExecuteInDrupalVm()) {
39+
$event->disableCommand();
40+
return $this->executeCommandInDrupalVm("blt " . $event->getCommand()->getName());
41+
}
42+
}
43+
}
44+
45+
/**
46+
* Indicates whether a frontend hook should be invoked inside of Drupal VM.
47+
*
48+
* @return bool
49+
* TRUE if it should be invoked inside of Drupal VM.
50+
*/
51+
protected function shouldExecuteInDrupalVm() {
52+
return $this->getInspector()->isDrupalVmLocallyInitialized()
53+
&& $this->getInspector()->isDrupalVmBooted()
54+
&& !$this->getInspector()->isVmCli();
55+
}
56+
3657
}

src/Robo/Wizards/SetupWizard.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ public function wizardInstallDrupal() {
4040
$confirm = $this->confirm("Do you want to install Drupal?");
4141
if ($confirm) {
4242
$bin = $this->getConfigValue('composer.bin');
43-
4443
$this->executor
45-
->execute("$bin/blt setup:drupal:install")->printOutput(TRUE)->run();
44+
->execute("$bin/blt setup")
45+
->interactive(TRUE)
46+
->run();
4647
}
4748
}
4849
}

0 commit comments

Comments
 (0)