-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1003 from spiral/feature/prototype-list
[spiral/prototype] Introducing new `prototype:list` console command for listing prototype dependencies
- Loading branch information
Showing
7 changed files
with
192 additions
and
53 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
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Prototype\Command; | ||
|
||
final class UsageCommand extends AbstractCommand | ||
{ | ||
public const NAME = 'prototype:usage'; | ||
public const DESCRIPTION = 'List all prototyped classes'; | ||
|
||
/** | ||
* List all prototype classes. | ||
*/ | ||
public function perform(): int | ||
{ | ||
$prototyped = $this->locator->getTargetClasses(); | ||
if ($prototyped === []) { | ||
$this->writeln('<comment>No prototyped classes found.</comment>'); | ||
|
||
return self::SUCCESS; | ||
} | ||
|
||
$grid = $this->table(['Class:', 'Property:', 'Target:']); | ||
|
||
foreach ($prototyped as $class) { | ||
$proto = $this->getPrototypeProperties($class, $prototyped); | ||
|
||
$grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]); | ||
} | ||
|
||
$grid->render(); | ||
|
||
return self::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
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Tests\Prototype\Commands; | ||
|
||
use Spiral\Console\Console; | ||
use Spiral\Tests\Prototype\Fixtures\TestApp; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
|
||
class UsageCommandTest extends AbstractCommandsTestCase | ||
{ | ||
public function testCommandRegistered(): void | ||
{ | ||
$out = new BufferedOutput(); | ||
$this->app->get(Console::class)->run('list', new ArrayInput([]), $out); | ||
|
||
$result = $out->fetch(); | ||
|
||
$this->assertStringContainsString('prototype:usage', $result); | ||
} | ||
|
||
public function testPrototypes(): void | ||
{ | ||
$inp = new ArrayInput([]); | ||
$out = new BufferedOutput(); | ||
$this->app->get(Console::class)->run('prototype:usage', $inp, $out); | ||
|
||
$result = $out->fetch(); | ||
|
||
$this->assertStringContainsString('testClass', $result); | ||
$this->assertStringContainsString('undefined', $result); | ||
} | ||
|
||
public function testPrototypesBound(): void | ||
{ | ||
$this->app->bindApp(); | ||
|
||
$inp = new ArrayInput([]); | ||
$out = new BufferedOutput(); | ||
$this->app->get(Console::class)->run('prototype:usage', $inp, $out); | ||
|
||
$result = $out->fetch(); | ||
|
||
$this->assertStringContainsString('testClass', $result); | ||
$this->assertStringNotContainsString('undefined', $result); | ||
$this->assertStringNotContainsString('Undefined class', $result); | ||
$this->assertStringContainsString(TestApp::class, $result); | ||
} | ||
|
||
public function testPrototypesBoundWithoutResolve(): void | ||
{ | ||
$this->app->bindWithoutResolver(); | ||
|
||
$inp = new ArrayInput([]); | ||
$out = new BufferedOutput(); | ||
$this->app->get(Console::class)->run('prototype:usage', $inp, $out); | ||
|
||
$result = $out->fetch(); | ||
|
||
$this->assertStringContainsString('testClass', $result); | ||
$this->assertStringContainsString('Can\'t resolve', $result); | ||
$this->assertStringContainsString(TestApp::class, $result); | ||
} | ||
} |