Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Command/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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%'
Expand Down Expand Up @@ -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 }
9 changes: 7 additions & 2 deletions Tests/Command/ConsumeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,9 @@ class ConsumeCommandTest extends KernelTestCase

protected $mockConsumer;

/** @var EndpointFactory $endpointFactory */
protected $endpointFactory;

public function setMockConsumer($expirationCount)
{
self::bootKernel();
Expand All @@ -31,14 +35,15 @@ 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()
{
$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');

Expand All @@ -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);
Expand Down