Skip to content

Commit d21c642

Browse files
committed
ACMS-3639: Refactored DrsIO class.
1 parent 31530b9 commit d21c642

File tree

5 files changed

+21
-141
lines changed

5 files changed

+21
-141
lines changed

phpunit.xml.dist

+8-27
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
6-
colors="true"
7-
cacheResultFile="./var/phpunit/test-results"
8-
bootstrap="vendor/autoload.php"
9-
failOnWarning="true"
10-
failOnRisky="true"
11-
convertErrorsToExceptions="true"
12-
convertNoticesToExceptions="true"
13-
convertWarningsToExceptions="true"
14-
convertDeprecationsToExceptions="true"
15-
>
16-
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php" failOnWarning="true" failOnRisky="true" cacheDirectory=".phpunit.cache">
174
<php>
185
<ini name="error_reporting" value="-1"/>
19-
<env name="COLUMNS" value="80" force="true" />
20-
<!-- <env name="ORCA_FIXTURE_DIR" value="/Applications/MAMP/htdocs/acquia_cms" force="true" />-->
6+
<env name="COLUMNS" value="80" force="true"/>
7+
<!-- <env name="ORCA_FIXTURE_DIR" value="/Applications/MAMP/htdocs/acquia_cms" force="true" />-->
218
</php>
22-
239
<testsuites>
2410
<testsuite name="DRS">
2511
<directory>tests</directory>
2612
</testsuite>
2713
</testsuites>
28-
29-
<coverage cacheDirectory="var/phpunit/coverage-cache"
30-
processUncoveredFiles="true">
14+
<!-- <logging>-->
15+
<!-- <testdoxHtml outputFile="testdox.html"/>-->
16+
<!-- </logging>-->
17+
<source>
3118
<include>
3219
<directory suffix=".php">src</directory>
3320
</include>
34-
<!-- <report>-->
35-
<!-- <html outputDirectory="coverage" lowUpperBound="50" highLowerBound="90"/>-->
36-
<!-- </report>-->
37-
</coverage>
38-
<!-- <logging>-->
39-
<!-- <testdoxHtml outputFile="testdox.html"/>-->
40-
<!-- </logging>-->
21+
</source>
4122
</phpunit>

src/Common/IO.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ protected function printArrayAsTable(
145145
* The verbosity level at which to display the logged message.
146146
*/
147147
protected function logConfig(array $array, string $prefix = '', int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): void {
148-
if ($this->output()->getVerbosity() >= $verbosity) {
148+
if ($this->getOutput()->getVerbosity() >= $verbosity) {
149149
if ($prefix) {
150-
$this->output()->writeln("<comment>Configuration for $prefix:</comment>");
150+
$this->getOutput()->writeln("<comment>Configuration for $prefix:</comment>");
151151
foreach ($array as $key => $value) {
152152
$array["$prefix.$key"] = $value;
153153
unset($array[$key]);

src/Drush/Commands/MultisiteDrushCommands.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
use Consolidation\AnnotatedCommand\Hooks\HookManager;
1414
use Drupal\Core\Database\Database;
1515
use Drush\Attributes as CLI;
16-
use Drush\Boot\BootstrapManager;
1716
use Drush\Boot\DrupalBootLevels;
1817
use Drush\Commands\DrushCommands;
1918
use Drush\Drush;
20-
use Psr\Container\ContainerInterface as DrushContainer;
2119

2220
/**
2321
* A Drush command to generate settings.php for Multisite.

tests/src/Traits/DrsIO.php

+5-109
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
namespace Acquia\Drupal\RecommendedSettings\Tests\Traits;
44

5-
use Acquia\Drupal\RecommendedSettings\Common\ArrayManipulator;
6-
use Symfony\Component\Console\Helper\Table;
75
use Symfony\Component\Console\Output\NullOutput;
86
use Symfony\Component\Console\Output\OutputInterface;
9-
use Symfony\Component\Console\Question\ChoiceQuestion;
10-
use Symfony\Component\Console\Question\Question;
117

128
/**
139
* An extension of \Robo\Common\IO.
@@ -16,6 +12,11 @@
1612
*/
1713
trait DrsIO {
1814

15+
/**
16+
* Stores the output.
17+
*/
18+
protected OutputInterface $output;
19+
1920
/**
2021
* Writes text to screen, without decoration.
2122
*
@@ -41,29 +42,6 @@ protected function yell($text, $length = 40, $color = 'green'): void {
4142
$this->formattedOutput($text, $length, $format);
4243
}
4344

44-
/**
45-
* Prints the message to terminal.
46-
*
47-
* @param string $message
48-
* Given message to print.
49-
* @param string $type
50-
* Type of message. Ex: error, success, info etc.
51-
* @param string $color
52-
* Given background color.
53-
*/
54-
protected function print(string $message, string $type = "success", string $color = ""): void {
55-
if (!$color) {
56-
$color = match ($type) {
57-
"warning" => "yellow",
58-
"notice" => "cyan",
59-
"error" => "red",
60-
default => "green",
61-
};
62-
}
63-
$message = " <fg=white;bg=$color;options=bold>[$type]</fg=white;bg=$color;options=bold> " . $message;
64-
$this->say($message);
65-
}
66-
6745
/**
6846
* Format text as a question.
6947
*
@@ -77,88 +55,6 @@ protected function formatQuestion($message): string {
7755
return "<question> $message</question> ";
7856
}
7957

80-
/**
81-
* Asks the user a multiple-choice question.
82-
*
83-
* @param string $question
84-
* The question text.
85-
* @param string[] $options
86-
* An array of available options.
87-
* @param mixed $default
88-
* Default.
89-
*
90-
* @return string
91-
* The chosen option.
92-
*/
93-
protected function askChoice(string $question, array $options, mixed $default = NULL): string {
94-
return $this->doAsk(new ChoiceQuestion($this->formatQuestion($question),
95-
$options, $default));
96-
}
97-
98-
/**
99-
* Asks a required question.
100-
*
101-
* @param string $message
102-
* The question text.
103-
*
104-
* @return string
105-
* The response.
106-
*/
107-
protected function askRequired(string $message): string {
108-
$question = new Question($this->formatQuestion($message));
109-
$question->setValidator(function ($answer) {
110-
if (empty($answer)) {
111-
throw new \RuntimeException(
112-
'You must enter a value!'
113-
);
114-
}
115-
116-
return $answer;
117-
});
118-
return $this->doAsk($question);
119-
}
120-
121-
/**
122-
* Writes an array to the screen as a formatted table.
123-
*
124-
* @param string[] $array
125-
* The unformatted array.
126-
* @param string[] $headers
127-
* The headers for the array. Defaults to ['Property','Value'].
128-
*/
129-
protected function printArrayAsTable(
130-
array $array,
131-
array $headers = ['Property', 'Value']
132-
): void {
133-
$table = new Table($this->output);
134-
$table->setHeaders($headers)
135-
->setRows(ArrayManipulator::convertArrayToFlatTextArray($array))
136-
->render();
137-
}
138-
139-
/**
140-
* Writes a particular configuration key's value to the log.
141-
*
142-
* @param string[] $array
143-
* The configuration.
144-
* @param string $prefix
145-
* A prefix to add to each row in the configuration.
146-
* @param int $verbosity
147-
* The verbosity level at which to display the logged message.
148-
*/
149-
protected function logConfig(array $array, string $prefix = '', int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): void {
150-
if ($this->getOutput()->getVerbosity() >= $verbosity) {
151-
if ($prefix) {
152-
$this->getOutput()->writeln("<comment>Configuration for $prefix:</comment>");
153-
foreach ($array as $key => $value) {
154-
$array["$prefix.$key"] = $value;
155-
unset($array[$key]);
156-
}
157-
}
158-
$this->printArrayAsTable($array);
159-
}
160-
}
161-
16258
/**
16359
* Asks a required question.
16460
*

tests/src/unit/Common/IOTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Acquia\Drupal\RecommendedSettings\Tests\Unit\Common;
44

5+
use Acquia\Drupal\RecommendedSettings\Common\IO;
56
use Acquia\Drupal\RecommendedSettings\Tests\Traits\DrsIO;
67
use PHPUnit\Framework\TestCase;
78
use Symfony\Component\Console\Input\InputInterface;
@@ -14,7 +15,11 @@
1415
* @covers \Acquia\Drupal\RecommendedSettings\Common\IO
1516
*/
1617
class IOTest extends TestCase {
17-
use DrsIO;
18+
use IO, DrsIO {
19+
IO::say insteadof DrsIO;
20+
IO::formatQuestion insteadof DrsIO;
21+
IO::yell insteadof DrsIO;
22+
}
1823

1924
/**
2025
* Stores the messages to print.

0 commit comments

Comments
 (0)