52 lines
1.9 KiB
PHP
52 lines
1.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\Laravel\LaravelCommandAdapter;
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
|
|
class LaravelBridgeTest extends TestCase
|
|
{
|
|
public function testLaravelCommandAdapter(): 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 LaravelCommandAdapter($phredCommand);
|
|
|
|
// Mock Laravel components
|
|
$symfonyInput = new ArrayInput(['name' => 'John'], $adapter->getDefinition());
|
|
$symfonyOutput = new BufferedOutput();
|
|
|
|
// Use reflection to set protected properties as Laravel's constructor and run logic is complex
|
|
$refl = new \ReflectionClass($adapter);
|
|
|
|
$inputProp = $refl->getProperty('input');
|
|
$inputProp->setValue($adapter, $symfonyInput);
|
|
|
|
$outputProp = $refl->getProperty('output');
|
|
$outputProp->setValue($adapter, $symfonyOutput);
|
|
|
|
$exitCode = $adapter->handle();
|
|
|
|
$this->assertEquals(0, $exitCode);
|
|
$this->assertStringContainsString('Hello John', $symfonyOutput->fetch());
|
|
}
|
|
}
|