diff --git a/Command/ConsumeCommand.php b/Command/ConsumeCommand.php index 6b9a82a7..f30f8e23 100644 --- a/Command/ConsumeCommand.php +++ b/Command/ConsumeCommand.php @@ -25,14 +25,28 @@ class ConsumeCommand extends ContainerAwareCommand /** @var InputInterface */ protected $input; + /** @var EndpointFactory */ + protected $endpointFactory; + + /** + * ConsumeCommand constructor. + * + * @param EndpointFactory $endpointFactory + */ + public function __construct(EndpointFactory $endpointFactory) + { + parent::__construct(); + $this->endpointFactory = $endpointFactory; + } + /** - * @return \Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointInterface + * @return mixed|\Smartbox\Integration\FrameworkBundle\Core\Endpoints\Endpoint */ protected function getSourceEndpoint() { $uri = $this->getInput()->getArgument('uri'); - return $this->getContainer()->get('smartesb.endpoint_factory')->createEndpoint($uri, EndpointFactory::MODE_CONSUME); + return $this->endpointFactory->createEndpoint($uri, EndpointFactory::MODE_CONSUME); } /** diff --git a/Resources/config/services.yml b/Resources/config/services.yml index e3c3f1c0..89c737eb 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -25,6 +25,8 @@ parameters: smartesb.steps_provider.nosql.class: Smartbox\Integration\FrameworkBundle\Components\DB\NoSQL\NoSQLStepsProvider smartesb.steps_provider.csv.class: Smartbox\Integration\FrameworkBundle\Components\FileService\Csv\CsvConfigurableStepsProvider + smartesb.command.consumer.start.class: Smartbox\Integration\FrameworkBundle\Command\ConsumeCommand + services: smartesb.serialization.handler.mongodate: class: '%smartesb.serialization.handler.mongodate.class%' @@ -108,3 +110,10 @@ services: smartesb.handlers.async: class: '%smartesb.handlers.message_routing.class%' + + # COMMANDS + smartesb.command.consumer.start: + class: '%smartesb.command.consumer.start.class%' + arguments: ['@smartesb.endpoint_factory'] + tags: + - { name: console.command } diff --git a/Tests/Command/ConsumeCommandTest.php b/Tests/Command/ConsumeCommandTest.php index 8ff3053a..a6f96f2d 100644 --- a/Tests/Command/ConsumeCommandTest.php +++ b/Tests/Command/ConsumeCommandTest.php @@ -4,6 +4,7 @@ use Smartbox\Integration\FrameworkBundle\Command\ConsumeCommand; use Smartbox\Integration\FrameworkBundle\Components\Queues\QueueConsumer; +use Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointFactory; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; @@ -15,6 +16,9 @@ class ConsumeCommandTest extends KernelTestCase protected $mockConsumer; + /** @var EndpointFactory $endpointFactory */ + protected $endpointFactory; + public function setMockConsumer($expirationCount) { self::bootKernel(); @@ -31,6 +35,7 @@ public function setMockConsumer($expirationCount) ->willReturn(true); self::$kernel->getContainer()->set('smartesb.consumers.queue', $this->mockConsumer); + $this->endpointFactory = self::$kernel->getContainer()->get('smartesb.endpoint_factory'); } public function testExecuteWithKillAfter() @@ -38,7 +43,7 @@ public function testExecuteWithKillAfter() $this->setMockConsumer(self::NB_MESSAGES); $application = new Application(self::$kernel); - $application->add(new ConsumeCommand()); + $application->add(new ConsumeCommand($this->endpointFactory)); $command = $application->find('smartesb:consumer:start'); @@ -59,7 +64,7 @@ public function testExecuteWithoutKillAfter() $this->setMockConsumer(0); $application = new Application(self::$kernel); - $application->add(new ConsumeCommand()); + $application->add(new ConsumeCommand($this->endpointFactory)); $command = $application->find('smartesb:consumer:start'); $commandTester = new CommandTester($command);