Last active
February 19, 2018 18:25
-
-
Save dpagini/3a2c49ade20a521b2b6eec7df0f43876 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace Acquia\Blt\Custom\Commands; | |
use Acquia\Blt\Robo\BltTasks; | |
use Acquia\Blt\Robo\Exceptions\BltException; | |
/** | |
* Defines commands in the "tests" namespace. | |
*/ | |
class TestsDrupalCommand extends BltTasks { | |
/** | |
* The server url. | |
* | |
* @var string | |
*/ | |
protected $serverUrl; | |
/** | |
* Array that contains configuration for Drupal tests. | |
* | |
* @var array | |
*/ | |
protected $testsDrupalConfig; | |
/** | |
* This hook will fire for all commands in this command file. | |
* | |
* @hook init | |
*/ | |
public function initialize() { | |
$this->serverUrl = $this->getConfigValue('tests.server.url'); | |
$this->testsDrupalConfig = $this->getConfigValue('tests.drupal'); | |
} | |
/** | |
* Executes all behat tests. | |
* | |
* @command tests:drupal | |
* @description Executes drupal tests. | |
* | |
* @validateMySqlAvailable | |
* @validateDrupalIsInstalled | |
* @validateVmConfig | |
* @launchWebServer | |
* @executeInDrupalVm | |
*/ | |
public function drupalTests() { | |
// @TODO: Logging? | |
// @TODO: This needs to fail the build. | |
// @TODO: Run unit then functional tests. See drupal.org/node/2469723. | |
// @TODO: Cleanup? Uninstall simpletest? | |
$this->createDefaultSettings(); | |
$this->setupSimpletest(); | |
foreach ($this->testsDrupalConfig as $test) { | |
// @TODO: Run "run-tests.sh" as web user. | |
$task = $this->taskExec('php') | |
->dir($this->getConfigValue('docroot')) | |
// Call the core script. | |
->arg('./core/scripts/run-tests.sh') | |
->option('verbose') | |
->option('color') | |
// @TODO: Need to figure out if this is needed...? | |
->option('url', $this->serverUrl) | |
// This seems to be needed by Travis. | |
->rawArg('--php "$(which php)"'); | |
if (isset($test['path'])) { | |
$task->option('directory', $test['path']); | |
} | |
if (isset($test['module'])) { | |
$task->option('module', $test['module']); | |
} | |
if (isset($test['class'])) { | |
$task->option('class', $test['class']); | |
} | |
if (isset($test['file'])) { | |
$task->option('file', $test['file']); | |
} | |
// Run which path? | |
$result = $task->run(); | |
if (!$result->wasSuccessful()) { | |
throw new BltException("Testing Drupal failed!"); | |
} | |
} | |
} | |
/** | |
* Installs the simpletest Drupal core module and exports variables. | |
*/ | |
protected function setupSimpletest() { | |
$this->taskExec('export') | |
->arg('SIMPLETEST_BASE_URL=' . $this->serverUrl) | |
// @TODO: Make dynamic somehow. | |
->arg('SIMPLETEST_DB=' . 'mysql://drupal:drupal@localhost/drupal') | |
->run(); | |
$this->taskDrush() | |
->drush('pm-enable') | |
->arg('simpletest') | |
->verbose(TRUE) | |
->assume(TRUE) | |
->printOutput(TRUE) | |
->run(); | |
// @TODO: Check for success. | |
} | |
/** | |
* Moves sites/all/default.settings.php to sites/default. | |
* | |
* Project custom requirement. | |
*/ | |
protected function createDefaultSettings() { | |
$sites = $this->getConfigValue('docroot') . "/sites"; | |
$result = $this->taskFilesystemStack() | |
->stopOnFail() | |
->chmod($sites . "/default/", 0777) | |
->copy($sites . "/all/default.settings.php", $sites . "/default/default.settings.php") | |
->run(); | |
if (!$result->wasSuccessful()) { | |
throw new BltException("Unable to copy all/default.settings.php file to default/default.settings.php."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment