-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from acquia/ACMS-3639-1
ACMS-3639: Refactored DRS tests to remove RoboIo dependency.
- Loading branch information
Showing
9 changed files
with
164 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Acquia\Drupal\RecommendedSettings\Tests\Traits; | ||
|
||
use Robo\Common\InputAwareTrait; | ||
|
||
/** | ||
* An extension of \Robo\Common\IO. | ||
*/ | ||
trait DrsIO { | ||
|
||
use OutputAwareTrait; | ||
use InputAwareTrait; | ||
|
||
/** | ||
* Writes the text to screen. | ||
* | ||
* @param string|iterable[string] $text | ||
* Prints the output text. | ||
*/ | ||
protected function writeln(string|iterable $text): void { | ||
$this->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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Acquia\Drupal\RecommendedSettings\Tests\Traits; | ||
|
||
use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Custom OutputAwareTrait defined by the DRS without defining | ||
* method output() as it throws error with PHPUnit 10. | ||
* | ||
* @see \Robo\Common\OutputAwareTrait | ||
*/ | ||
trait OutputAwareTrait { | ||
|
||
/** | ||
* Holds Console output object. | ||
*/ | ||
protected OutputInterface $output; | ||
|
||
/** | ||
* | ||
* @return $this | ||
* | ||
* @see \Robo\Contract\OutputAwareInterface::setOutput() | ||
*/ | ||
public function setOutput(OutputInterface $output): static { | ||
$this->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<string> $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()"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters