Skip to content

Commit 0ea6604

Browse files
committed
feat: add InputOutput::error() for testing
1 parent 86fe095 commit 0ea6604

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/Commands/Utils/InputOutput.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ public function write(
3232
): void {
3333
CLI::write($text, $foreground, $background);
3434
}
35+
36+
/**
37+
* Outputs an error to the CLI using STDERR instead of STDOUT
38+
*/
39+
public function error(string $text, string $foreground = 'light_red', ?string $background = null): void
40+
{
41+
CLI::error($text, $foreground, $background);
42+
}
3543
}

src/Test/MockInputOutput.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,15 @@ public function write(
8585
CITestStreamFilter::removeOutputFilter();
8686
CITestStreamFilter::removeErrorFilter();
8787
}
88+
89+
public function error(string $text, string $foreground = 'light_red', ?string $background = null): void
90+
{
91+
CITestStreamFilter::registration();
92+
CITestStreamFilter::addErrorFilter();
93+
94+
CLI::error($text, $foreground, $background);
95+
$this->outputs[] = CITestStreamFilter::$buffer;
96+
97+
CITestStreamFilter::removeErrorFilter();
98+
}
8899
}

0 commit comments

Comments
 (0)