diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 30d0020..8128fc7 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -4,38 +4,38 @@
-
-
-
+
+
-
tests
-
-
-
- src
-
+
-
-
-
-
+
+
+
+
+
diff --git a/settings/misc.settings.php b/settings/misc.settings.php
index 7e637d5..bebf464 100644
--- a/settings/misc.settings.php
+++ b/settings/misc.settings.php
@@ -22,8 +22,7 @@
* $settings['hash_salt'] = file_get_contents('/home/example/salt.txt');
* @endcode
*/
-$settings['hash_salt'] = file_get_contents(DRUPAL_ROOT . '/../salt.txt');
-
+$settings['hash_salt'] = !empty($settings['hash_salt']) ? $settings['hash_salt'] : file_get_contents(DRUPAL_ROOT . '/../salt.txt');
/**
* Deployment identifier.
*
diff --git a/settings/site/default.local.settings.php b/settings/site/default.local.settings.php
index 286dff2..b02a673 100644
--- a/settings/site/default.local.settings.php
+++ b/settings/site/default.local.settings.php
@@ -53,12 +53,14 @@
* Drupal\Component\Assertion\Handle is deprecated.
* @see https://www.drupal.org/node/3105918
*/
-if (phpversion() >= 8.3 ) {
+if (phpversion() >= 8.3) {
@ini_set('zend.assertions', 1);
}
else {
+ // phpcs:disable
assert_options(ASSERT_ACTIVE, TRUE);
assert_options(ASSERT_EXCEPTION, TRUE);
+ // phpcs:enable
}
/**
diff --git a/src/Common/IO.php b/src/Common/IO.php
index bf7e09a..6a364e4 100644
--- a/src/Common/IO.php
+++ b/src/Common/IO.php
@@ -17,7 +17,7 @@ trait IO {
/**
* Writes text to screen, without decoration.
*
- * @param string $text
+ * @param string|iterable[string] $text
* The text to write.
*/
protected function say($text): void {
@@ -145,9 +145,12 @@ protected function printArrayAsTable(
* The verbosity level at which to display the logged message.
*/
protected function logConfig(array $array, string $prefix = '', int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): void {
- if ($this->output()->getVerbosity() >= $verbosity) {
+ // We can't directly use $this->output() as it throws error with PHPUnit 10
+ // because it defines output() method with a different method signature.
+ $output = ($this->output() instanceof OutputInterface) ? $this->output() : $this->getOutput();
+ if ($output->getVerbosity() >= $verbosity) {
if ($prefix) {
- $this->output()->writeln("Configuration for $prefix:");
+ $output->writeln("Configuration for $prefix:");
foreach ($array as $key => $value) {
$array["$prefix.$key"] = $value;
unset($array[$key]);
diff --git a/src/Drush/Commands/MultisiteDrushCommands.php b/src/Drush/Commands/MultisiteDrushCommands.php
index 34ec9ca..e76afec 100644
--- a/src/Drush/Commands/MultisiteDrushCommands.php
+++ b/src/Drush/Commands/MultisiteDrushCommands.php
@@ -13,11 +13,9 @@
use Consolidation\AnnotatedCommand\Hooks\HookManager;
use Drupal\Core\Database\Database;
use Drush\Attributes as CLI;
-use Drush\Boot\BootstrapManager;
use Drush\Boot\DrupalBootLevels;
use Drush\Commands\DrushCommands;
use Drush\Drush;
-use Psr\Container\ContainerInterface as DrushContainer;
/**
* A Drush command to generate settings.php for Multisite.
diff --git a/src/Robo/Tasks/LoadTasks.php b/src/Robo/Tasks/LoadTasks.php
index 61d91b9..3e19cb6 100644
--- a/src/Robo/Tasks/LoadTasks.php
+++ b/src/Robo/Tasks/LoadTasks.php
@@ -3,6 +3,7 @@
namespace Acquia\Drupal\RecommendedSettings\Robo\Tasks;
use Robo\Collection\CollectionBuilder;
+use Symfony\Component\Console\Output\OutputInterface;
/**
* Load Settings's custom Robo tasks.
@@ -23,8 +24,11 @@ trait LoadTasks {
protected function taskDrush(): CollectionBuilder {
/** @var \Acquia\Drupal\RecommendedSettings\Robo\Tasks\DrushTask $task */
$task = $this->task($this->drushTaskClass);
+
+ // We can't directly use $this->output() as it throws error with PHPUnit 10
+ // because it defines output() method with a different method signature.
/** @var \Symfony\Component\Console\Output\OutputInterface $output */
- $output = $this->output();
+ $output = ($this->output() instanceof OutputInterface) ? $this->output() : $this->getOutput();
$task->setVerbosityThreshold($output->getVerbosity());
return $task;
diff --git a/tests/src/CommandsTestBase.php b/tests/src/CommandsTestBase.php
index ac86e24..a0b1b62 100644
--- a/tests/src/CommandsTestBase.php
+++ b/tests/src/CommandsTestBase.php
@@ -4,13 +4,13 @@
use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait;
use Acquia\Drupal\RecommendedSettings\Tests\Helpers\NullLogOutputStylers;
+use Acquia\Drupal\RecommendedSettings\Tests\Traits\OutputAwareTrait;
use Consolidation\Log\Logger;
use League\Container\Container;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Robo\Collection\CollectionBuilder;
use Robo\Common\BuilderAwareTrait;
-use Robo\Common\OutputAwareTrait;
use Robo\Config\Config;
use Robo\Robo;
use Robo\Tasks;
@@ -51,7 +51,7 @@ protected function createContainer(?ContainerInterface $container = NULL): void
$config = new Config();
$this->setConfig($config);
- $logger = new Logger($this->output());
+ $logger = new Logger($this->getOutput());
$null_log_output = new NullLogOutputStylers;
$logger->setLogOutputStyler($null_log_output);
$container->add("logger", $logger);
diff --git a/tests/src/Traits/DrsIO.php b/tests/src/Traits/DrsIO.php
new file mode 100644
index 0000000..5ac6b85
--- /dev/null
+++ b/tests/src/Traits/DrsIO.php
@@ -0,0 +1,51 @@
+getOutput()->writeln($text);
+ }
+
+ /**
+ * Formats the output message to terminal.
+ *
+ * @param string $text
+ * Output message to format.
+ * @param int $length
+ * Length of the output.
+ * @param string $format
+ * Given string format.
+ *
+ * @see \Robo\Common\IO::formattedOutput()
+ */
+ protected function formattedOutput(string $text, int $length, string $format): void {
+ $lines = explode("\n", trim($text, "\n"));
+ $maxLineLength = array_reduce(array_map('strlen', $lines), 'max');
+ $length = max($length, $maxLineLength);
+ $len = $length + 2;
+ $space = str_repeat(' ', $len);
+ $this->writeln(sprintf($format, $space));
+ foreach ($lines as $line) {
+ $line = str_pad($line, $length, ' ', STR_PAD_BOTH);
+ $this->writeln(sprintf($format, " $line "));
+ }
+ $this->writeln(sprintf($format, $space));
+ }
+
+}
diff --git a/tests/src/Traits/OutputAwareTrait.php b/tests/src/Traits/OutputAwareTrait.php
new file mode 100644
index 0000000..5d33750
--- /dev/null
+++ b/tests/src/Traits/OutputAwareTrait.php
@@ -0,0 +1,74 @@
+output = $output;
+ return $this;
+ }
+
+ /**
+ */
+ protected function stderr(): OutputInterface {
+ $output = $this->getOutput();
+ if ($output instanceof ConsoleOutputInterface) {
+ $output = $output->getErrorOutput();
+ }
+ return $output;
+ }
+
+ /**
+ * Returns an instance of OutputInterface object.
+ * This method is deprecated in Robo IO.php, hence defined here.
+ */
+ protected function getOutput(): OutputInterface {
+ if (!isset($this->output)) {
+ $this->setOutput(new NullOutput());
+ }
+ return $this->output;
+ }
+
+ /**
+ * We are using our own IO (DrsIO) instead of the IO trait provided by Robo.
+ * The PHPUnit 9 doesn't have output() method, so when DrsIO's logConfig
+ * method calls output(), it throws a "Call to undefined method" error.
+ * We are handling that case here.
+ *
+ * @todo: Remove the method below once support for the PHPUnit 9 is dropped.
+ *
+ * @param string name
+ * The method name to call.
+ * @param array $arguments
+ * An array of arguments to pass to method.
+ */
+ public function __call(string $name, array $arguments): OutputInterface {
+ if ($name == "output") {
+ return $this->getOutput();
+ }
+ throw new \BadMethodCallException("Call to undefined method " . __NAMESPACE__ . "::$name()");
+ }
+
+}
diff --git a/tests/src/unit/Common/IOTest.php b/tests/src/unit/Common/IOTest.php
index d5894e8..39ec5b9 100644
--- a/tests/src/unit/Common/IOTest.php
+++ b/tests/src/unit/Common/IOTest.php
@@ -1,10 +1,10 @@
print = [];
$this->answer = "";
- $this->output = $this->output();
+ $this->output = $this->getOutput();
}
/**
@@ -239,7 +234,7 @@ public function testLogConfig(): void {
/**
* Returns the mocked output object.
*/
- protected function output(): OutputInterface {
+ protected function getOutput(): OutputInterface {
$output = $this->createMock(OutputInterface::class);
$output->method("writeln")->willReturnCallback(fn ($input) => $this->mockPrint($input));
$output->method("getVerbosity")->willReturn(OutputInterface::VERBOSITY_VERY_VERBOSE);