Skip to content

Commit 1dcbe58

Browse files
committed
Fixes acquia#1472: Execute Tests inside the VM where possible.
1 parent 03352b8 commit 1dcbe58

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

src/Robo/Commands/Frontend/FrontendCommand.php

+9-22
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,44 +25,25 @@ 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-
3828
/**
3929
* Invokes a frontend hook.
4030
*
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-
*
4431
* @param string $hook
4532
* The hook to invoke. E.g., "build" would invoke "frontend-build" hook.
4633
*
4734
* @return int|\Robo\Result
4835
* The status code or result object.
4936
*/
5037
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-
}
38+
return $this->invokeHook("frontend-$hook");
5839
}
5940

6041
/**
6142
* Executes frontend-build target hook.
6243
*
6344
* @command frontend:build
45+
*
46+
* @executeInDrupalVm
6447
*/
6548
public function build() {
6649
return $this->invokeFrontendHook('build');
@@ -70,6 +53,8 @@ public function build() {
7053
* Executes frontend-setup target hook.
7154
*
7255
* @command frontend:setup
56+
*
57+
* @executeInDrupalVm
7358
*/
7459
public function setup() {
7560
return $this->invokeFrontendHook('setup');
@@ -79,6 +64,8 @@ public function setup() {
7964
* Executes frontend-test target hook.
8065
*
8166
* @command frontend:test
67+
*
68+
* @executeInDrupalVm
8269
*/
8370
public function test() {
8471
return $this->invokeFrontendHook('test');

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

+23
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,27 @@ public function skipDisabledCommands(ConsoleCommandEvent $event) {
3333
}
3434
}
3535

36+
/**
37+
* Execute a command inside of Drupal VM.
38+
*
39+
* @hook command-event @executeInDrupalVm
40+
*/
41+
public function executeInDrupalVm(ConsoleCommandEvent $event) {
42+
if ($this->shouldExecuteInDrupalVm()) {
43+
$event->disableCommand();
44+
return $this->executeCommandInDrupalVm($event->getCommand()->getName());
45+
}
46+
}
47+
48+
/**
49+
* Indicates whether a frontend hook should be invoked inside of Drupal VM.
50+
*
51+
* @return bool
52+
* TRUE if it should be invoked inside of Drupal VM.
53+
*/
54+
protected function shouldExecuteInDrupalVm() {
55+
return $this->getInspector()->isDrupalVmLocallyInitialized()
56+
&& $this->getInspector()->isDrupalVmBooted()
57+
&& !$this->getInspector()->isVmCli();
58+
}
3659
}

0 commit comments

Comments
 (0)