From 7ce9d63ed62ee8965aadacbb4a050b97aa67b878 Mon Sep 17 00:00:00 2001 From: Rafael Horvat Date: Fri, 23 Sep 2022 13:44:17 +0200 Subject: [PATCH] feat(test): Make it possible to extend SetupScript (#3643) * Make it possible to extend Flarum\Testing\integration\Setup\SetupScript and added public methods to add settings or extensions to in initial installation pipeline * Fix syntax error, unexpected 'static' * Remove `addExtensions` method and document `addSettings` --- .../src/integration/Setup/SetupScript.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/php-packages/testing/src/integration/Setup/SetupScript.php b/php-packages/testing/src/integration/Setup/SetupScript.php index aefc17f75..f9c75afb2 100644 --- a/php-packages/testing/src/integration/Setup/SetupScript.php +++ b/php-packages/testing/src/integration/Setup/SetupScript.php @@ -66,7 +66,13 @@ class SetupScript /** * @var DatabaseConfig */ - private $dbConfig; + protected $dbConfig; + + /** + * Settings to be applied during installation. + * @var array + */ + protected $settings = ['mail_driver' => 'log']; public function __construct() { @@ -124,7 +130,7 @@ class SetupScript 'password', 'admin@machine.local' )) - ->settings(['mail_driver' => 'log']) + ->settings($this->settings) ->extensions([]) ->build(); @@ -145,4 +151,20 @@ class SetupScript $builder->dropAllViews(); }))->run(); } + + /** + * Can be used to add settings to the Flarum installation. + * Use this only when it is really needed. + * This can be useful in rare cases where the settings are required to be set + * already when extensions Extenders are executed. In those cases, setting the + * settings with the `setting()` method of the `TestCase` will not work. + * + * @param string $settings (key => value) + */ + public function addSettings(array $settings): self + { + $this->settings = array_merge($this->settings, $settings); + + return $this; + } }