-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce results writer for existing cli text
- Loading branch information
Showing
4 changed files
with
123 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRequireChecker\Cli\ResultsWriter; | ||
|
||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use function count; | ||
use function implode; | ||
|
||
final class CliText implements ResultsWriter | ||
{ | ||
private OutputInterface $output; | ||
|
||
public function __construct(OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function write(array $unknownSymbols): void | ||
{ | ||
if (! $unknownSymbols) { | ||
$this->output->writeln('There were no unknown symbols found.'); | ||
|
||
return; | ||
} | ||
|
||
$this->output->writeln('The following ' . count($unknownSymbols) . ' unknown symbols were found:'); | ||
$table = new Table($this->output); | ||
$table->setHeaders(['Unknown Symbol', 'Guessed Dependency']); | ||
foreach ($unknownSymbols as $unknownSymbol => $guessedDependencies) { | ||
$table->addRow([$unknownSymbol, implode("\n", $guessedDependencies)]); | ||
} | ||
|
||
$table->render(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/ComposerRequireChecker/Cli/ResultsWriter/ResultsWriter.php
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRequireChecker\Cli\ResultsWriter; | ||
|
||
interface ResultsWriter | ||
{ | ||
/** | ||
* @param array<array-key, string[]> $unknownSymbols the unknown symbols found | ||
*/ | ||
public function write(array $unknownSymbols): void; | ||
} |
50 changes: 50 additions & 0 deletions
50
test/ComposerRequireCheckerTest/Cli/ResultsWriter/CliTextTest.php
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRequireCheckerTest\Cli\ResultsWriter; | ||
|
||
use ComposerRequireChecker\Cli\ResultsWriter\CliText; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
|
||
use const PHP_EOL; | ||
|
||
final class CliTextTest extends TestCase | ||
{ | ||
private CliText $writer; | ||
private BufferedOutput $output; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->output = new BufferedOutput(); | ||
$this->writer = new CliText($this->output); | ||
} | ||
|
||
public function testWriteReportNoUnknownSymbolsFound(): void | ||
{ | ||
$this->writer->write([]); | ||
|
||
self::assertSame('There were no unknown symbols found.' . PHP_EOL, $this->output->fetch()); | ||
} | ||
|
||
public function testWriteReportWithUnknownSymbols(): void | ||
{ | ||
$this->writer->write([ | ||
'Foo' => [], | ||
'opcache_get_status' => ['ext-opcache'], | ||
'dummy' => ['ext-dummy', 'ext-other'], | ||
]); | ||
|
||
$buffer = $this->output->fetch(); | ||
self::assertStringContainsString('The following 3 unknown symbols were found:', $buffer); | ||
self::assertStringContainsString('Foo', $buffer); | ||
self::assertStringContainsString('| opcache_get_status', $buffer); | ||
self::assertStringContainsString('| ext-opcache', $buffer); | ||
self::assertStringContainsString('| dummy', $buffer); | ||
self::assertStringContainsString('| ext-dummy', $buffer); | ||
self::assertStringContainsString('| ext-other', $buffer); | ||
} | ||
} |