Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ORCA_DRUPAL_CORE_VERSION environment variable with fixture:init --core option #19

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
parameters:

# Environment variables for dynamic configuration override:
env(ORCA_DRUPAL_CORE_VERSION): ~
env(ORCA_FIXTURE_DIR): "%app.fixture_dir%"
env(ORCA_PACKAGES_CONFIG): config/packages.yml
env(ORCA_PACKAGES_CONFIG_ALTER): ~
Expand All @@ -17,7 +16,7 @@ services:
autowire: true
bind:
$drupal_core_dev_version: "%drupal_core_dev_version%"
$drupal_core_version: "%env(ORCA_DRUPAL_CORE_VERSION)%"
$drupal_core_version: "%drupal_core_dev_version%"
$fixture_dir: "%env(ORCA_FIXTURE_DIR)%"
$project_dir: "%kernel.project_dir%"
$packages_config: "%env(ORCA_PACKAGES_CONFIG)%"
Expand Down
2 changes: 0 additions & 2 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

Various aspects of ORCA's behavior can be altered at runtime through the use of environment variables. These can be set or exported in a local terminal session or [in various ways on Travis CI](https://docs.travis-ci.com/user/environment-variables/).

* <a name="ORCA_DRUPAL_CORE_VERSION"></a>**`ORCA_DRUPAL_CORE_VERSION`**: Change the version of Drupal core ORCA creates test fixtures with. This can be useful for testing upgrade paths, for example. Acceptable values are any version strings Composer understands, e.g., `8.6.0`, `~8.6`, or `8.6.x-dev`.

* <a name="ORCA_FIXTURE_DIR"></a>**`ORCA_FIXTURE_DIR`**: Change the directory ORCA uses for test fixtures. Acceptable values are any valid, local directory reference, e.g., `/var/www/example`, or `../example`.

* <a name="ORCA_PACKAGES_CONFIG"></a>**`ORCA_PACKAGES_CONFIG`**: Completely replace the list of packages ORCA installs in fixtures and runs tests on. Acceptable values are any valid path to a YAML file relative to ORCA itself, e.g., `../example/tests/packages.yml`. See [`config/packages.yml`](../config/packages.yml) for an example and explanation of the schema.
Expand Down
14 changes: 14 additions & 0 deletions src/Command/Fixture/FixtureInitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protected function configure() {
->setHelp('Creates a BLT-based Drupal site build, includes the system under test using Composer, optionally includes all other Acquia packages, and installs Drupal.')
->addOption('sut', NULL, InputOption::VALUE_REQUIRED, 'The system under test (SUT) in the form of its package name, e.g., "drupal/example"')
->addOption('sut-only', NULL, InputOption::VALUE_NONE, 'Add only the system under test (SUT). Omit all other non-required Acquia packages')
->addOption('core', NULL, InputOption::VALUE_REQUIRED, 'Change the version of Drupal core installed, e.g., "8.6.0", "~8.6", or "8.6.x-dev"')
->addOption('dev', NULL, InputOption::VALUE_NONE, 'Use dev (HEAD) branches instead of stable releases of Drupal core and Acquia packages')
->addOption('force', 'f', InputOption::VALUE_NONE, 'If the fixture already exists, remove it first without confirmation')
->addOption('profile', NULL, InputOption::VALUE_REQUIRED, 'The Drupal installation profile to use, e.g., "lightning"', self::DEFAULT_PROFILE)
Expand Down Expand Up @@ -119,6 +120,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$this->setSut($sut);
$this->setSutOnly($sut_only);
$this->setDev($input->getOption('dev'));
$this->setCore($input->getOption('core'));
$this->setProfile($input->getOption('profile'));
$this->setSqlite($input->getOption('no-sqlite'));

Expand Down Expand Up @@ -198,6 +200,18 @@ private function setDev($dev): void {
}
}

/**
* Sets the Drupal core version.
*
* @param string|string[]|bool|null $version
* The version string.
*/
private function setCore($version): void {
if ($version) {
$this->fixtureCreator->setCoreVersion($version);
}
}

/**
* Sets the installation profile.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Fixture/FixtureCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ public function create(): void {
$this->createAndCheckoutBackupTag();
}

/**
* Sets the Drupal core version to install.
*
* @param string $version
* The version string, e.g., "8.6.0".
*/
public function setCoreVersion(string $version): void {
$this->drupalCoreVersion = $version;
}

/**
* Sets the dev flag.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Command/Fixture/FixtureInitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
class FixtureInitCommandTest extends CommandTestBase {

private const DRUPAL_CORE_VERSION = '8.6.0';

protected function setUp() {
$this->fixtureCreator = $this->prophesize(FixtureCreator::class);
$this->fixtureRemover = $this->prophesize(FixtureRemover::class);
Expand Down Expand Up @@ -56,6 +58,9 @@ public function testCommand($fixture_exists, $args, $methods_called, $exception,
$this->fixtureCreator
->setDev(TRUE)
->shouldBeCalledTimes((int) in_array('setDev', $methods_called));
$this->fixtureCreator
->setCoreVersion(self::DRUPAL_CORE_VERSION)
->shouldBeCalledTimes((int) in_array('setCoreVersion', $methods_called));
$this->fixtureCreator
->setSqlite(FALSE)
->shouldBeCalledTimes((int) in_array('setSqlite', $methods_called));
Expand Down Expand Up @@ -86,6 +91,7 @@ public function providerCommand() {
[FALSE, ['--sut' => self::INVALID_PACKAGE], ['PackageManager::exists'], 0, StatusCodes::ERROR, sprintf("Error: Invalid value for \"--sut\" option: \"%s\".\n", self::INVALID_PACKAGE)],
[FALSE, ['--sut' => self::VALID_PACKAGE], ['PackageManager::exists', 'Fixture::exists', 'create', 'setSut'], 0, StatusCodes::OK, ''],
[FALSE, ['--sut' => self::VALID_PACKAGE, '--sut-only' => TRUE], ['PackageManager::exists', 'Fixture::exists', 'create', 'setSut', 'setSutOnly'], 0, StatusCodes::OK, ''],
[FALSE, ['--core' => self::DRUPAL_CORE_VERSION], ['Fixture::exists', 'setCoreVersion', 'create'], 0, StatusCodes::OK, ''],
[FALSE, ['--dev' => TRUE], ['Fixture::exists', 'setDev', 'create'], 0, StatusCodes::OK, ''],
[FALSE, ['--no-sqlite' => TRUE], ['Fixture::exists', 'setSqlite', 'create'], 0, StatusCodes::OK, ''],
[FALSE, ['--profile' => 'lightning'], ['Fixture::exists', 'setProfile', 'create'], 0, StatusCodes::OK, ''],
Expand Down