From 7a3887f21af39c78d20126ac69daa7c01ba5f4c1 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Tue, 21 Nov 2023 11:11:24 +0530 Subject: [PATCH] ACMS-000: Fixed conflicts and minor changes. --- .github/workflows/drs_ci.yml | 6 +++-- README.md | 46 +++++++++++++++++++++++++++-------- src/Helpers/HashGenerator.php | 7 ++++-- src/Plugin.php | 5 ++-- src/Settings.php | 8 ++++++ tests/ci/script.sh | 19 --------------- 6 files changed, 56 insertions(+), 35 deletions(-) delete mode 100755 tests/ci/script.sh diff --git a/.github/workflows/drs_ci.yml b/.github/workflows/drs_ci.yml index 2dca280..8c93b18 100644 --- a/.github/workflows/drs_ci.yml +++ b/.github/workflows/drs_ci.yml @@ -66,8 +66,10 @@ jobs: run: ../orca/bin/ci/install.sh - name: Before script run: ../orca/bin/ci/before_script.sh - - name: Script - run: ./tests/ci/script.sh + - name: Run PHPUnit tests + run: | + composer install + ./vendor/bin/phpunit tests - name: After script run: | ../orca/bin/ci/after_success.sh diff --git a/README.md b/README.md index 294eb98..5c52faf 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ composer require acquia/drupal-recommended-settings + use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector; ``` -## Steps to use Acquia Drupal Recommended Settings with BLT. - - Create an Settings object & call generate method. +# Quick examples. +## Generate settings for a given site. ``` generate(); +} catch (SettingsException $e) { + echo $e->getMessage(); +} +``` + +## Generate settings for a given site passing database credentials. + +``` + [ '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); +try { + // Call generate method passing database details. + $settings->generate($dbSpec); +} catch (SettingsException $e) { + echo $e->getMessage(); +} ``` # License diff --git a/src/Helpers/HashGenerator.php b/src/Helpers/HashGenerator.php index 34b8dbd..470d3ad 100644 --- a/src/Helpers/HashGenerator.php +++ b/src/Helpers/HashGenerator.php @@ -3,6 +3,7 @@ namespace Acquia\Drupal\RecommendedSettings\Helpers; use Acquia\Drupal\RecommendedSettings\Common\RandomString; +use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; /** * Class to generate salt hash. @@ -16,6 +17,8 @@ class HashGenerator { * Given directory. * @param mixed $io * Given io object to print message to terminal. + * + * @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException */ public static function generate(string $directory, $io): void { try { @@ -30,8 +33,8 @@ public static function generate(string $directory, $io): void { $io->write("[notice] Hash salt already exists."); } } - catch (\RuntimeException $e) { - $io->write("[error] " . $e->getMessage()); + catch (\Exception $e) { + throw new SettingsException($e); } } diff --git a/src/Plugin.php b/src/Plugin.php index 6aad9ce..8ba7384 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -2,6 +2,7 @@ namespace Acquia\Drupal\RecommendedSettings; +use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; use Acquia\Drupal\RecommendedSettings\Helpers\HashGenerator; use Composer\Composer; use Composer\DependencyResolver\Operation\InstallOperation; @@ -93,7 +94,7 @@ public function onPostPackageEvent(PackageEvent $event) { /** * Includes Acquia recommended settings post composer update/install command. * - * @throws \Exception + * @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException */ public function onPostCmdEvent() { // Only install the template files, if the drupal-recommended-settings @@ -104,7 +105,7 @@ public function onPostCmdEvent() { $settings = new Settings($this->getDrupalRoot()); $settings->generate(); } - catch (\Exception $e) { + catch (SettingsException $e) { $this->io->write("[error] " . $e->getMessage()); } } diff --git a/src/Settings.php b/src/Settings.php index 5f13a68..c02b652 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -4,6 +4,7 @@ use Acquia\Drupal\RecommendedSettings\Config\ConfigInitializer; use Acquia\Drupal\RecommendedSettings\Config\SettingsConfig; +use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; use Acquia\Drupal\RecommendedSettings\Helpers\Filesystem; /** @@ -96,8 +97,11 @@ protected function copySiteSettings(): bool { * * @param array $overrideData * An array of data to override. + * + * @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException */ public function generate(array $overrideData = []): void { + try { $site = $this->site; $this->copyGlobalSettings(); $this->copySiteSettings(); @@ -137,6 +141,10 @@ public function generate(array $overrideData = []): void { // The config directory for given site must exists, otherwise Drupal will // add database credentials to settings.php. $this->fileSystem->ensureDirectoryExists($this->drupalRoot . "/../config/$site"); + } catch (\Exception $e) { + throw new SettingsException($e); + } + } /** diff --git a/tests/ci/script.sh b/tests/ci/script.sh deleted file mode 100755 index 9ffc499..0000000 --- a/tests/ci/script.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/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 -