Skip to content

Commit

Permalink
feature/PHPGL-10 merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej committed Dec 4, 2015
2 parents 7080878 + 8917ce6 commit c78be91
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ install:

script:
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/behat

after_script:
- vendor/bin/coveralls
7 changes: 7 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default:
autoload:
- %paths.base%/vendor/autoload.php
suites:
default:
contexts:
- tests\Clearcode\CommandBusConsole\Contexts\CLIContext
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"php": ">=5.5",
"symfony/framework-bundle": "~2.5",
"simple-bus/symfony-bridge": "^4.1",
"ramsey/uuid": "~3.0"
"ramsey/uuid": "~3.0",
"symfony/yaml": "~2.5"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "^0.6.1",
"matthiasnoback/symfony-console-form": "^1.1",
"symfony/finder": "~2.5",
"symfony/validator": "~2.5",
"symfony/class-loader": "~2.1",
"behat/behat": "^3.0",
"symfony/var-dumper": "~2.5",
"matthiasnoback/symfony-dependency-injection-test": "0.*"
},
Expand All @@ -33,8 +36,7 @@
"examples\\Clearcode\\CommandBusConsole\\": "examples"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "0.2.x-dev"
Expand Down
5 changes: 5 additions & 0 deletions features/handle_command.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Handle command

Scenario: Successfully handle command
When I run command "command-bus:handle SuccessfulCommand"
Then command should end successfully
3 changes: 1 addition & 2 deletions src/Bundle/Command/CommandBusConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CommandBusConsoleCommand extends ContainerAwareCommand
protected function configure()
{
$this
->setName('command-bus:console')
->setName('command-bus:handle')
->setDescription('CLI for command bus.')
->addArgument('commandName', InputArgument::REQUIRED)
->addArgument('arguments', InputArgument::IS_ARRAY);
Expand All @@ -35,7 +35,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
} catch (CommandConsoleException $e) {
return $this->handleException($output, $e);
}

try {
$this->getContainer()->get('command_bus')->handle($command);
} catch (\Exception $e) {
Expand Down
5 changes: 3 additions & 2 deletions src/CommandReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public static function fromClass($className)
public function parameters()
{
$commandReflection = new \ReflectionClass($this->commandClass);
$commandParameters = $commandReflection->getConstructor()->getParameters();

return $commandParameters;
return $commandParameters = $commandReflection->getConstructor() ?
$commandReflection->getConstructor()->getParameters() :
[];
}

/**
Expand Down
7 changes: 6 additions & 1 deletion tests/Bundle/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ services:
dummy_command:
class: tests\Clearcode\CommandBusConsole\Bundle\Mocks\DummyCommandHandler
tags:
- { name: command_handler, handles: tests\Clearcode\CommandBusConsole\Bundle\Mocks\DummyCommand }
- { name: command_handler, handles: tests\Clearcode\CommandBusConsole\Bundle\Mocks\DummyCommand }

successful_command_handler:
class: tests\Clearcode\CommandBusConsole\CommandBus\SuccessfulCommandHandler
tags:
- { name: command_handler, handles: tests\Clearcode\CommandBusConsole\CommandBus\SuccessfulCommand }
2 changes: 1 addition & 1 deletion tests/Bundle/CLITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class CLITestCase extends WebTestCase
/** {@inheritdoc} */
public static function getKernelClass()
{
include_once __DIR__ . '/App/TestKernel.php';
include_once __DIR__.'/App/TestKernel.php';

return TestKernel::class;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/CommandBus/SuccessfulCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace tests\Clearcode\CommandBusConsole\CommandBus;

final class SuccessfulCommand
{
}
10 changes: 10 additions & 0 deletions tests/CommandBus/SuccessfulCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace tests\Clearcode\CommandBusConsole\CommandBus;

final class SuccessfulCommandHandler
{
public function handle(SuccessfulCommand $successCommand)
{
}
}
46 changes: 46 additions & 0 deletions tests/Contexts/CLIContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace tests\Clearcode\CommandBusConsole\Contexts;

use Assert\Assertion;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Clearcode\CommandBusConsole\Bundle\Command\CommandBusConsoleCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\StreamOutput;
use tests\Clearcode\CommandBusConsole\Bundle\App\TestKernel;

class CLIContext implements Context, SnippetAcceptingContext
{
private $app;

private $status;

public function __construct()
{
$kernel = new TestKernel('test', false);
$this->app = new Application($kernel);
$this->app->setAutoExit(false);
$this->app->add(new CommandBusConsoleCommand());
}

/**
* @When I run command :command
*/
public function iRunCommand($command)
{
$input = new StringInput($command);
$output = new StreamOutput(fopen('php://memory', 'w'));

$this->status = $this->app->run($input, $output);
}

/**
* @Then command should end successfully
*/
public function commandShouldEndSuccessfully()
{
Assertion::same($this->status, 0);
}
}

0 comments on commit c78be91

Please sign in to comment.