Skip to content

Commit

Permalink
Command name changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Nov 30, 2018
1 parent 91aa71b commit 0d77aa2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class OrdinaryCommand extends Command
protected function configure() : void
{
$this
->setName('command:ordinary')
->setName('command:greeting')
->setDescription('Prints "Hello {config.greeting} {name}')
->setDefinition([
new InputArgument('name', InputArgument::REQUIRED),
Expand Down Expand Up @@ -136,6 +136,6 @@ $cli->run();
### 6. Run your command on terminal

```bash
./bin/console command:ordinary Kedibey
./bin/console command:greeting Kedibey
```
Outputs: Hello Dear Kedibey
3 changes: 1 addition & 2 deletions example/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

require_once (__DIR__ . '/../../vendor/autoload.php');
require_once (__DIR__ . '/../../tests/resources/Command/OrdinaryCommand.php');

use Selami\Console\ApplicationFactory;
use Zend\ServiceManager\ServiceManager;
Expand All @@ -14,7 +13,7 @@ $container = new ServiceManager([
]);
$container->setService(
'commands', [
SelamiConsoleTest\Command\OrdinaryCommand::class
SelamiConsoleTest\Command\GreetingCommand::class
]
);
$container->setService('config', ['greeting' => 'Dear']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

class OrdinaryCommand extends Command
class GreetingCommand extends Command
{
/**
* @var PrintService
Expand All @@ -28,8 +28,8 @@ public function __construct(PrintService $printService, array $config, string $n
protected function configure() : void
{
$this
->setName('command:ordinary')
->setDescription('Prints "Hello {config.greeting} {name}')
->setName('command:greeting')
->setDescription('Prints "Hello {config.Greeting} {name}')
->setDefinition([
new InputArgument('name', InputArgument::REQUIRED),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

class OrdinaryCommandWithArrayDependency extends Command
class GreetingCommandWithArrayDependency extends Command
{
/**
* @var PrintService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

class OrdinaryCommandWithServiceDependency extends Command
class GreetingCommandWithServiceDependency extends Command
{
/**
* @var NonExistingPrintService
Expand Down
22 changes: 12 additions & 10 deletions tests/unit/ApplicationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function successfulConsoleApp() : void
$container->setService(
'commands',
[
SelamiConsoleTest\Command\OrdinaryCommand::class
SelamiConsoleTest\Command\GreetingCommand::class
]
);
$this->container = $container;
Expand All @@ -49,18 +49,19 @@ protected function failedConsoleApp() : void
$container->setService(
'config',
[
'cache' => '/tmp/uRt48sl'
'greeting' => 'Dear'
]
);
$container->setService(
'commands',
[
SelamiConsoleTest\Command\OrdinaryCommand::class,
SelamiConsoleTest\Command\OrdinaryCommandWithArrayDependency::class,
SelamiConsoleTest\Command\GreetingCommand::class,
SelamiConsoleTest\Command\GreetingCommandWithArrayDependency::class,
]
);
$this->container = $container;
}

protected function failedForNonExistingServiceConsoleApp() : void
{
$container = new ServiceManager([
Expand All @@ -77,8 +78,8 @@ protected function failedForNonExistingServiceConsoleApp() : void
$container->setService(
'commands',
[
SelamiConsoleTest\Command\OrdinaryCommand::class,
SelamiConsoleTest\Command\OrdinaryCommandWithServiceDependency::class,
SelamiConsoleTest\Command\GreetingCommand::class,
SelamiConsoleTest\Command\GreetingCommandWithServiceDependency::class,
]
);
$this->container = $container;
Expand All @@ -94,14 +95,15 @@ protected function _after()
public function shouldRunCommandSuccessfully() : void
{
$this->successfulConsoleApp();
$input = new ArrayInput(array('command '=> 'command:ordinary', 'name' => 'Kedibey'));
$cli = Console\ApplicationFactory::makeApplication($this->container, 'TestApp', '1.0.1');
$cli->setAutoExit(false);
$this->assertEquals('TestApp', $cli->getName());
$this->assertEquals('1.0.1', $cli->getVersion());
$input = new ArrayInput(['command'=> 'command:greeting', 'name' => 'Kedibey']);
$output = new BufferedOutput();
$cli->run($input, $output);
$return = $output->fetch();
var_dump($return);
$this->assertEquals('Hello Dear Kedibey' . PHP_EOL, $return);
}

Expand All @@ -112,7 +114,7 @@ public function shouldRunCommandSuccessfully() : void
public function shouldFailNonExistingArrayDependency() : void
{
$this->failedConsoleApp();
$input = new ArrayInput(array('command'=>'command:ordinary-with-array-dependency', 'name' => 'world'));
$input = new ArrayInput(array('command'=>'command:greeting-with-array-dependency', 'name' => 'world'));
$cli = Console\ApplicationFactory::makeApplication($this->container, 'TestApp', '1.0.1');
$cli->setAutoExit(false);
$this->assertEquals('TestApp', $cli->getName());
Expand All @@ -127,7 +129,7 @@ public function shouldFailNonExistingArrayDependency() : void
public function shouldFailNonExistingServiceDependency() : void
{
$this->failedForNonExistingServiceConsoleApp();
$input = new ArrayInput(array('command'=>'command:ordinary-with-service-dependency', 'name' => 'world'));
$input = new ArrayInput(array('command'=>'command:greeting-with-service-dependency', 'name' => 'world'));
$cli = Console\ApplicationFactory::makeApplication($this->container, 'TestApp', '1.0.1');
$cli->setAutoExit(false);
$this->assertEquals('TestApp', $cli->getName());
Expand All @@ -142,7 +144,7 @@ public function shouldFailNonExistingServiceDependency() : void
public function shouldFailNonExistingSCommandDependency() : void
{
$this->failedForNonExistingServiceConsoleApp();
$input = new ArrayInput(array('command'=>'command:ordinary-with-service-dependency', 'name' => 'world'));
$input = new ArrayInput(array('command'=>'command:greeting-with-service-dependency', 'name' => 'world'));
$cli = Console\ApplicationFactory::makeApplication($this->container, 'TestApp', '1.0.1');
$cli->setAutoExit(false);
$this->assertEquals('TestApp', $cli->getName());
Expand Down

0 comments on commit 0d77aa2

Please sign in to comment.