Skip to content

Commit

Permalink
Fixes #1564: Added frontend-web-test hook to BLT. (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash authored Jun 7, 2017
1 parent a6248ac commit 5a7466a
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 43 deletions.
4 changes: 2 additions & 2 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ protected function generateReleaseNotes($tag, $github_token) {
*/
public function fixCode() {
$command = "'{$this->bin}/phpcbf' --standard='{$this->drupalPhpcsStandard}' '%s'";
$task = $this->taskExecStack();
$task = $this->taskParallelExec();
foreach ($this->phpcsPaths as $path) {
$full_command = sprintf($command, $path);
$task->exec($full_command);
$task->process($full_command);
}
$result = $task->run();

Expand Down
3 changes: 2 additions & 1 deletion src/Robo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use Symfony\Component\Console\Application as ConsoleApplication;

/**
* Class Application
* Class Application.
*
* @package Acquia\Blt\Robo
*/
class Application extends ConsoleApplication {
Expand Down
13 changes: 0 additions & 13 deletions src/Robo/BltTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ class BltTasks implements ConfigAwareInterface, InspectorAwareInterface, LoggerA
use LoggerAwareTrait;
use LoadTasks;

/**
* This hook will fire for all commands.
*
* @hook init
*/
public function initialize() {
// We set the value for site late in the bootstrap process so that a user
// may define its value at runtime via --define. This can only happen after
// input has been processed.
$site = $this->getConfigValue('site', 'default');
$this->getConfig()->setSiteConfig($site);
}

/**
* The depth of command invocations, used by invokeCommands().
*
Expand Down
2 changes: 1 addition & 1 deletion src/Robo/Commands/Frontend/FrontendCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function frontend() {
$status_code = $this->invokeCommands([
'frontend:setup',
'frontend:build',
'frontend:test',
]);
return $status_code;
}
Expand Down Expand Up @@ -52,6 +51,7 @@ public function setup() {
*
* @command frontend:test
*
* @launchWebDriver
* @executeInDrupalVm
*/
public function test() {
Expand Down
25 changes: 1 addition & 24 deletions src/Robo/Commands/Tests/BehatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function initialize() {
* @validateDrupalIsInstalled
* @validateBehatIsConfigured
* @validateInsideVm
* @launchWebServer
* @executeInDrupalVm
*/
public function behat() {
Expand All @@ -90,16 +91,13 @@ public function behat() {
$this->createReportsDir();

try {
$this->launchWebServer();
$this->launchWebDriver();
$this->executeBehatTests();
$this->killWebDriver();
$this->killWebServer();
}
catch (\Exception $e) {
// Kill web driver a server to prevent Pipelines from hanging after fail.
$this->killWebDriver();
$this->killWebServer();
throw $e;
}
}
Expand Down Expand Up @@ -134,27 +132,6 @@ public function behatDefinitions($options = ['mode' => 'l']) {
return $result;
}

/**
* Launches PHP's internal web server via `drush run-server`.
*/
protected function launchWebServer() {
if ($this->getConfigValue('behat.run-server')) {
$this->killWebServer();
$this->say("Launching PHP's internal web server via drush.");
$this->logger->info("Running server at $this->serverUrl...");
$this->getContainer()->get('executor')->drush("runserver $this->serverUrl > /dev/null")->background(TRUE)->run();
$this->getContainer()->get('executor')->waitForUrlAvailable($this->serverUrl);
}
}

/**
* Kills PHP internal web server running on $this->serverUrl.
*/
protected function killWebServer() {
$this->getContainer()->get('executor')->killProcessByName('runserver');
$this->getContainer()->get('executor')->killProcessByPort($this->serverPort);
}

/**
* Launch the appropriate web driver based on configuration.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/Robo/Exceptions/BltException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace Acquia\Blt\Robo\Exceptions;

/**
* Class BltException
* Class BltException.
*
* @package Acquia\Blt\Robo\Exceptions
*/
class BltException extends \Exception {

/**
*
*/
public function __construct(
$message = "",
$code = 0,
Expand Down
36 changes: 36 additions & 0 deletions src/Robo/Hooks/InitHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Acquia\Blt\Robo\Hooks;

use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Robo\Contract\IOAwareInterface;
use Robo\Tasks;

/**
* This class defines hooks that provide user interaction.
*
* These hooks typically use a Wizard to evaluate the validity of config or
* state and guide the user toward resolving issues.
*/
class InitHook extends Tasks implements IOAwareInterface, ConfigAwareInterface, LoggerAwareInterface {

use ConfigAwareTrait;
use LoggerAwareTrait;

/**
* This hook will fire for all commands.
*
* @hook init *
*/
public function initialize() {
// We set the value for site late in the bootstrap process so that a user
// may define its value at runtime via --define. This can only happen after
// input has been processed.
$site = $this->getConfigValue('site', 'default');
$this->getConfig()->setSiteConfig($site);
}

}
51 changes: 51 additions & 0 deletions src/Robo/Hooks/WebServerHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Acquia\Blt\Robo\Hooks;

use Acquia\Blt\Robo\Common\IO;
use Acquia\Blt\Robo\Config\ConfigAwareTrait;
use Acquia\Blt\Robo\Inspector\InspectorAwareInterface;
use Acquia\Blt\Robo\Inspector\InspectorAwareTrait;
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Contract\ConfigAwareInterface;

/**
*
*/
class WebServerHook implements ConfigAwareInterface, ContainerAwareInterface, LoggerAwareInterface, InspectorAwareInterface {

use ConfigAwareTrait;
use ContainerAwareTrait;
use LoggerAwareTrait;
use InspectorAwareTrait;
use IO;

protected $serverUrl;
protected $serverPort;

/**
* @hook pre-command @launchWebServer
*/
public function launchWebServer() {
if ($this->getConfigValue('behat.run-server')) {
$this->serverUrl = $this->getConfigValue('behat.server.url');
$this->killWebServer();
$this->say("Launching PHP's internal web server via drush.");
$this->logger->info("Running server at $this->serverUrl...");
$this->getContainer()->get('executor')->drush("runserver $this->serverUrl > /dev/null")->background(TRUE)->run();
$this->getContainer()->get('executor')->waitForUrlAvailable($this->serverUrl);
}
}

/**
* @hook post-command @launchWebServer
*/
public function killWebServer() {
$this->getContainer()->get('executor')->killProcessByName('runserver');
$this->getContainer()->get('executor')->killProcessByPort($this->getConfigValue('behat.server.port'));
}

}
4 changes: 3 additions & 1 deletion src/Robo/Inspector/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function __construct(Executor $executor) {
$this->executor = $executor;
}

/**
*
*/
public function clearState() {
$this->isDrupalInstalled = NULL;
$this->isMySqlAvailable = NULL;
Expand Down Expand Up @@ -370,7 +373,6 @@ public function commandExists($command) {
*
* @return bool
* TRUE if minimum version is satisfied.
*
*/
public function isGitMinimumVersionSatisfied($minimum_version) {
exec("git --version | cut -d' ' -f3", $output, $exit_code);
Expand Down

0 comments on commit 5a7466a

Please sign in to comment.