From 34b8601efcafed90418906f50461b55f90b060a6 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Mon, 15 Jan 2018 19:39:22 +0100 Subject: [PATCH] Issue #29: Add php server command. --- config/commands/drupal.yml | 2 +- src/Commands/DrupalCommands.php | 35 +++++++++++++++++++++++++++++++++ tests/fixtures/simulation.yml | 12 +++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/config/commands/drupal.yml b/config/commands/drupal.yml index f19a9f23..05000098 100644 --- a/config/commands/drupal.yml +++ b/config/commands/drupal.yml @@ -21,4 +21,4 @@ command: sites-subdir: ${drupal.site.sites_subdir} drush-setup: options: - config-dir: ${drupal.root}/drush \ No newline at end of file + config-dir: ${drupal.root}/drush diff --git a/src/Commands/DrupalCommands.php b/src/Commands/DrupalCommands.php index 74d91054..3c8b8504 100644 --- a/src/Commands/DrupalCommands.php +++ b/src/Commands/DrupalCommands.php @@ -244,4 +244,39 @@ public function settingsSetup(array $options = [ $this->taskAppendConfiguration($options['root'].'/sites/default/default.settings.php', $this->getConfig())->setConfigKey('drupal.settings'), ]); } + + /** + * Run PHP server. + * + * Run a PHP server using default configuration values provided in local + * runner.yml.dist/runner.yml files. + * + * @command drupal:run-server + * + * @option root Drupal site root. + * @option base-url Drupal site base URL + * @option background Run in background. + * + * @aliases drupal:rs + * + * @param array $options + * + * @return \Robo\Contract\TaskInterface + */ + public function runServer(array $options = [ + 'root' => InputOption::VALUE_REQUIRED, + 'base-url' => InputOption::VALUE_REQUIRED, + 'background' => InputOption::VALUE_NONE, + ]) + { + $host = parse_url($options['base-url'], PHP_URL_HOST); + $port = parse_url($options['base-url'], PHP_URL_PORT); + $port = ($port === null) ? 80 : $port; + + return $this->taskServer($port) + ->rawArg('-dalways_populate_raw_post_data=-1') + ->host($host) + ->dir($options['root']) + ->background($options['background']); + } } diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index edd15adb..1b6c0f0a 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -165,6 +165,18 @@ contains: - "AppendConfiguration('web/sites/default/default.settings.php'" +- command: 'drupal:run-server' + configuration: [] + composer: '' + contains: + - "[Simulator] Running exec php -S 127.0.0.1:8888 -t build -dalways_populate_raw_post_data=-1" + +- command: 'drupal:run-server --base-url=http://example.com' + configuration: [] + composer: '' + contains: + - "[Simulator] Running exec php -S example.com:80 -t build -dalways_populate_raw_post_data=-1" + - command: 'drupal:site-setup' configuration: drupal: