79 lines
2.9 KiB
PHP
79 lines
2.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Phred\TaskerBridges\Tests;
|
||
|
|
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
use Phred\ConsoleContracts\CommandInterface;
|
||
|
|
use Phred\ConsoleContracts\InputInterface;
|
||
|
|
use Phred\ConsoleContracts\OutputInterface;
|
||
|
|
use Phred\TaskerBridges\Symfony\SymfonyCommandAdapter;
|
||
|
|
use Phred\TaskerBridges\Symfony\SymfonyInputAdapter;
|
||
|
|
use Phred\TaskerBridges\Symfony\SymfonyOutputAdapter;
|
||
|
|
use Symfony\Component\Console\Application;
|
||
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
||
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||
|
|
use Symfony\Component\Console\Output\OutputInterface as SymfonyOutputInterface;
|
||
|
|
|
||
|
|
class SymfonyBridgeTest extends TestCase
|
||
|
|
{
|
||
|
|
public function testSymfonyCommandAdapter(): void
|
||
|
|
{
|
||
|
|
$phredCommand = new class implements CommandInterface {
|
||
|
|
public function getName(): string { return 'test:phred'; }
|
||
|
|
public function getDescription(): string { return 'Test description'; }
|
||
|
|
public function getArguments(): array { return ['name' => 'Name']; }
|
||
|
|
public function getOptions(): array { return []; }
|
||
|
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||
|
|
{
|
||
|
|
$output->info('Hello ' . $input->getArgument('name'));
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
$adapter = new SymfonyCommandAdapter($phredCommand);
|
||
|
|
$app = new Application();
|
||
|
|
$app->add($adapter);
|
||
|
|
$app->setAutoExit(false);
|
||
|
|
|
||
|
|
$input = new ArrayInput(['test:phred', 'name' => 'John']);
|
||
|
|
$output = new BufferedOutput();
|
||
|
|
|
||
|
|
$exitCode = $app->run($input, $output);
|
||
|
|
|
||
|
|
$this->assertEquals(0, $exitCode);
|
||
|
|
$this->assertStringContainsString('Hello John', $output->fetch());
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testVerbosityMapping(): void
|
||
|
|
{
|
||
|
|
$symfonyOutput = new BufferedOutput();
|
||
|
|
$adapter = new SymfonyOutputAdapter($symfonyOutput);
|
||
|
|
|
||
|
|
$adapter->setVerbosity(0);
|
||
|
|
$this->assertEquals(SymfonyOutputInterface::VERBOSITY_QUIET, $symfonyOutput->getVerbosity());
|
||
|
|
|
||
|
|
$adapter->setVerbosity(4);
|
||
|
|
$this->assertEquals(SymfonyOutputInterface::VERBOSITY_DEBUG, $symfonyOutput->getVerbosity());
|
||
|
|
|
||
|
|
$symfonyOutput->setVerbosity(SymfonyOutputInterface::VERBOSITY_VERBOSE);
|
||
|
|
$this->assertEquals(2, $adapter->getVerbosity());
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testSymfonyHelpers(): void
|
||
|
|
{
|
||
|
|
$symfonyOutput = new BufferedOutput();
|
||
|
|
$table = new \Symfony\Component\Console\Helper\Table($symfonyOutput);
|
||
|
|
$adapter = new \Phred\TaskerBridges\Symfony\SymfonyTableAdapter($table);
|
||
|
|
|
||
|
|
$adapter->setHeaders(['ID', 'Name']);
|
||
|
|
$adapter->addRow([1, 'John']);
|
||
|
|
$adapter->render();
|
||
|
|
|
||
|
|
$output = $symfonyOutput->fetch();
|
||
|
|
$this->assertStringContainsString('ID', $output);
|
||
|
|
$this->assertStringContainsString('John', $output);
|
||
|
|
}
|
||
|
|
}
|