-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* Credits: Spiral Cycle Bridge. | ||
* | ||
* @see https://github.com/spiral/cycle-bridge | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wakebit\CycleBridge\Console\Command\Schema; | ||
|
||
use Cycle\ORM\SchemaInterface; | ||
use Cycle\Schema\Renderer\OutputSchemaRenderer; | ||
use Cycle\Schema\Renderer\SchemaToArrayConverter; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class RenderCommand extends Command | ||
{ | ||
private string $name = 'cycle:schema:render'; | ||
private string $description = 'Render available CycleORM schemas.'; | ||
|
||
public function __construct( | ||
private SchemaInterface $schema, | ||
private SchemaToArrayConverter $converter, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setName($this->name) | ||
->setDescription($this->description) | ||
->addOption('no-color', 'nc', InputOption::VALUE_NONE, 'Display output without colors.'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$format = $input->getOption('no-color') ? | ||
OutputSchemaRenderer::FORMAT_PLAIN_TEXT : | ||
OutputSchemaRenderer::FORMAT_CONSOLE_COLOR; | ||
|
||
$renderer = new OutputSchemaRenderer($format); | ||
|
||
$output->writeln( | ||
$renderer->render( | ||
$this->converter->convert($this->schema), | ||
), | ||
); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wakebit\CycleBridge\Tests\Console\Command\Schema; | ||
|
||
use Cycle\ORM\Mapper\Mapper; | ||
use Cycle\ORM\Select\Repository; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Wakebit\CycleBridge\Console\Command\Schema\RenderCommand; | ||
use Wakebit\CycleBridge\TestApp\Entity\Article; | ||
use Wakebit\CycleBridge\TestApp\Entity\Customer; | ||
use Wakebit\CycleBridge\Tests\Constraints\SeeInOrder; | ||
use Wakebit\CycleBridge\Tests\TestCase; | ||
|
||
final class RenderCommandTest extends TestCase | ||
{ | ||
public function testRender(): void | ||
{ | ||
$commandTester = new CommandTester($this->container->get(RenderCommand::class)); | ||
$exitCode = $commandTester->execute(['-nc' => true], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); | ||
$realOutput = $commandTester->getDisplay(); | ||
$expectedOutput = [ | ||
'[customer] :: default.customers', | ||
'Entity:', Customer::class, | ||
'Mapper:', Mapper::class, | ||
'Repository:', Repository::class, | ||
'Primary key:', 'id', | ||
'Fields', '(property -> db.field -> typecast)', 'id -> id -> int', 'name -> name', | ||
'Relations:', 'not defined', | ||
|
||
'[article] :: default.articles', | ||
'Entity:', Article::class, | ||
'Mapper:', Mapper::class, | ||
'Repository:', Repository::class, | ||
'Primary key:', 'id', | ||
'Fields', '(property -> db.field -> typecast)', 'id -> id -> int', 'title -> title', 'description -> description', | ||
'Relations:', 'not defined', | ||
]; | ||
|
||
$this->assertSame(Command::SUCCESS, $exitCode); | ||
$this->assertThat($expectedOutput, new SeeInOrder($realOutput)); | ||
} | ||
} |