diff --git a/.github/workflows/drs_ci.yml b/.github/workflows/drs_ci.yml index 2282ac8..2dca280 100644 --- a/.github/workflows/drs_ci.yml +++ b/.github/workflows/drs_ci.yml @@ -60,10 +60,14 @@ jobs: coverage: xdebug - name: Download ORCA run: composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n + - name: Before Install + run: ../orca/bin/ci/before_install.sh + - name: Install + run: ../orca/bin/ci/install.sh - name: Before script run: ../orca/bin/ci/before_script.sh - name: Script - run: ../orca/bin/ci/script.sh + run: ./tests/ci/script.sh - name: After script run: | ../orca/bin/ci/after_success.sh diff --git a/README.md b/README.md index 141f90c..7e2b9d0 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # Acquia Drupal Recommended Settings -The Acquia Drupal Recommended Settings plugin adds the recommended settings to the Drupal project, so developers won't have to edit settings.php manually. +The Acquia Drupal Recommended Settings plugin adds the recommended settings to +the Drupal project, so developers won't have to edit settings.php manually. The recommended settings includes: -- the required database credentials -- configuration sync directory path. -- public/private etc. file directory path. +- The required database credentials. +- Configuration sync directory path. +- File directory path i.e public/private etc. - Acquia site studio sync directory path. -- Includes Drupal module [Config sync without site uuid](https://www.drupal.org/project/config_sync_without_site_uuid) features. -It allows your websites to be easily installed in both Acquia Cloud IDE & local and deployable on Acquia Cloud. +It allows your websites to be easily installed in both Acquia Cloud IDE & local +and deployable on Acquia Cloud. ## Installation @@ -18,43 +19,63 @@ You can also install this using Composer like so: composer require acquia/drupal-recommended-settings ``` -## Steps to switch from BLT to Acquia Drupal Recommended Settings -This plugin doesn't work with the acquia/blt plugin. If the plugin exists, it must be removed. +## Steps to use Acquia Drupal Recommended Settings with BLT. +This plugin works with acquia/blt plugin. -- Remove BLT plugin using below command +- Update BLT plugin to latest release. ``` -composer remove acquia/blt +composer update acquia/blt -W ``` -- Remove BLT reference from settings.php file located at -``/docroot/sites/default/settings.php``. -``` -require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php"; + - Latest release of BLT will download the acquia/drupal-recommended-settings + plugin automatically as dependency. + +## Steps to use Acquia Drupal Recommended Settings with BLT. + - Create an Settings object & call generate method. + ``` + [ + 'db' => [ +// Database name. + 'database' => 'drupal', +// Mysql database login username. + 'username' => 'drupal', +// Mysql database login password. + 'password' => 'drupal', +// Mysql host. + 'host' => 'localhost', +// Mysql port. + 'port' => '3306', + ], + ], +]; + +// Call generate method with database details. +$settings->generate($dbSpec); +``` # License Copyright (C) 2023 Acquia, Inc. -This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License version 2 as published by the +Free Software Foundation. -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. diff --git a/composer.json b/composer.json index 09bfdf9..beec09e 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,8 @@ "acquia/coding-standards": "^1.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", "ergebnis/composer-normalize": "~2.21.0", - "phpro/grumphp-shim": "^1.5" - }, - "conflict": { - "acquia/blt": "*" + "phpro/grumphp-shim": "^1.5", + "phpunit/phpunit": "^9 || ^10" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/config/build.yml b/config/build.yml index 680995f..a8ec6cb 100644 --- a/config/build.yml +++ b/config/build.yml @@ -5,4 +5,4 @@ drupal: username: drupal password: drupal host: localhost - port: 3306 \ No newline at end of file + port: 3306 diff --git a/settings/acquia-recommended.settings.php b/settings/acquia-recommended.settings.php index 8c5cbbf..9c57e04 100644 --- a/settings/acquia-recommended.settings.php +++ b/settings/acquia-recommended.settings.php @@ -2,7 +2,9 @@ /** * @file - * Setup Acquia Drupal Recommended Settings utility variables, include required files. + * Setup Acquia Drupal Recommended Settings utility variables. + * + * Includes required settings files. */ use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; diff --git a/settings/global/default.global.settings.php b/settings/global/default.global.settings.php index d55bba2..78e8dd1 100644 --- a/settings/global/default.global.settings.php +++ b/settings/global/default.global.settings.php @@ -2,7 +2,9 @@ /** * @file - * Generated by Acquia Drupal Recommended Settings. Serves as an example of global includes. + * Generated by Acquia Drupal Recommended Settings. + * + * Serves as an example of global includes. */ /** @@ -14,7 +16,8 @@ /** * Include settings files in docroot/sites/settings. * - * If instead you want to add settings to a specific site, see Acquia Drupal Recommended Settings includes + * If instead you want to add settings to a specific site, see + * Acquia Drupal Recommended Settings includes * file in docroot/sites/{site-name}/settings/default.includes.settings.php. */ $additionalSettingsFiles = [ diff --git a/src/Helpers/EnvironmentDetector.php b/src/Helpers/EnvironmentDetector.php index 7185935..32b221b 100644 --- a/src/Helpers/EnvironmentDetector.php +++ b/src/Helpers/EnvironmentDetector.php @@ -263,7 +263,9 @@ public static function getRepoRoot(): string { // This is a web or Drush request. return dirname(DRUPAL_ROOT); } + // phpcs:ignore global $repo_root; + // phpcs:enable return $repo_root; } diff --git a/src/Settings.php b/src/Settings.php index 78315ba..5f13a68 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -136,7 +136,6 @@ public function generate(array $overrideData = []): void { // The config directory for given site must exists, otherwise Drupal will // add database credentials to settings.php. - // @todo Using hardcoded sync directory path. Need to better optimise it. $this->fileSystem->ensureDirectoryExists($this->drupalRoot . "/../config/$site"); } diff --git a/tests/ci/script.sh b/tests/ci/script.sh new file mode 100755 index 0000000..9ffc499 --- /dev/null +++ b/tests/ci/script.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# NAME +# script.sh - Run ORCA tests. +# +# SYNOPSIS +# script.sh +# +# DESCRIPTION +# Runs static code analysis and automated tests. + +cd "$(dirname "$0")" + +# Reuse ORCA's own includes. +source ../../../orca/bin/travis/_includes.sh +cd /home/runner/work/drupal-recommended-settings/drupal-recommended-settings +composer install +./vendor/bin/phpunit tests +cd - diff --git a/tests/unit/SettingsTest.php b/tests/unit/SettingsTest.php new file mode 100644 index 0000000..72e0b71 --- /dev/null +++ b/tests/unit/SettingsTest.php @@ -0,0 +1,106 @@ +drupalRoot = dirname(__FILE__); + $docroot = $this->drupalRoot . '/docroot'; + $this->drsFileSystem = new DrsFilesystem(); + $this->drsFileSystem->ensureDirectoryExists($docroot . '/sites/default'); + $this->fileSystem = new Filesystem(); + $this->fileSystem->touch($docroot . '/sites/default/default.settings.php'); + $this->settings = new Settings($docroot, "default"); + $this->settings->generate([ + 'drupal' => [ + 'db' => [ + 'database' => 'drs', + 'username' => 'drupal', + 'password' => 'drupal', + 'host' => 'localhost', + 'port' => '3306', + ], + ], + ]); + } + + /** + * Test that the file is created. + */ + public function testFileIsCreated() { + // Assert that settings/default.global.settings.php file exist. + $this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/settings/default.global.settings.php')); + // Assert that settings.php file exist. + $this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings.php')); + // Assert that settings.php file has content. + $content = ' +require DRUPAL_ROOT . "/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php"; +/** + * IMPORTANT. + * + * Do not include additional settings here. Instead, add them to settings + * included by `acquia-recommended.settings.php`. See Acquia\'s documentation for more detail. + * + * @link https://docs.acquia.com/ + */ +'; + $this->assertEquals($content, file_get_contents($this->drupalRoot . '/docroot/sites/default/settings.php')); + // Assert that default.includes.settings.php file exist. + $this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings/default.includes.settings.php')); + // Assert that default.local.settings.php file exist. + $this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings/default.local.settings.php')); + // Assert that local.settings.php file exist. + $this->assertTrue($this->fileSystem->exists($this->drupalRoot . '/docroot/sites/default/settings/local.settings.php')); + // Get the local.settings.php file content. + $localSettings = file_get_contents($this->drupalRoot . '/docroot/sites/default/settings/local.settings.php'); + // Verify database credentials. + $this->assertStringContainsString("db_name = 'drs'", $localSettings, "The local.settings.php doesn't contains the 'drs' database."); + $this->assertStringContainsString("'username' => 'drupal'", $localSettings, "The local.settings.php doesn't contains the 'drupal' username."); + $this->assertStringContainsString("'password' => 'drupal'", $localSettings, "The local.settings.php doesn't contains the 'drupal' password."); + $this->assertStringContainsString("'host' => 'localhost'", $localSettings, "The local.settings.php doesn't contains the 'localhost' host."); + $this->assertStringContainsString("'port' => '3306'", $localSettings, "The local.settings.php doesn't contains the '3306' port."); + } + + public function tearDown(): void { + $this->fileSystem->remove($this->drupalRoot . '/docroot'); + $this->fileSystem->remove($this->drupalRoot . '/config'); + } + +}