Skip to content

Commit

Permalink
add container tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jun 11, 2016
1 parent 62521cf commit 1a904e9
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Container/AmqpDelayedMessageProducerFactory.php
Expand Up @@ -82,7 +82,7 @@ public function __invoke(ContainerInterface $container) : AmqpDelayedMessageProd
return new AmqpDelayedMessageProducer(
$container->get($options['producer']),
$container->get($options['message_converter']),
$container->get($options['app_id'])
$options['app_id']
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Container/AmqpMessageProducerFactory.php
Expand Up @@ -82,7 +82,7 @@ public function __invoke(ContainerInterface $container) : AmqpMessageProducer
return new AmqpMessageProducer(
$container->get($options['producer']),
$container->get($options['message_converter']),
$container->get($options['app_id'])
$options['app_id']
);
}

Expand Down
68 changes: 68 additions & 0 deletions tests/Container/AmqpCommandConsumerCallbackFactoryTest.php
@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the prooph/humus-amqp-producer.
* (c) 2016 prooph software GmbH <contact@prooph.de>
* (c) 2016 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types=1);

namespace ProophTest\ServiceBus\Message\HumusAmqp\Container;

use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Prooph\Common\Messaging\MessageFactory;
use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\Message\HumusAmqp\AmqpCommandConsumerCallback;
use Prooph\ServiceBus\Message\HumusAmqp\Container\AmqpCommandConsumerCallbackFactory;

/**
* Class AmqpCommandConsumerCallbackFactoryTest
* @package ProophTest\ServiceBus\Message\HumusAmqp\Container
*/
class AmqpCommandConsumerCallbackFactoryTest extends TestCase
{
/**
* @test
*/
public function it_creates_amqp_command_consumer_callback()
{
$commandBus = $this->prophesize(CommandBus::class);
$messageFactory = $this->prophesize(MessageFactory::class);

$container = $this->prophesize(ContainerInterface::class);
$container->get('config')->willReturn([
'prooph' => [
'humus-amqp-producer' => [
'command_consumer_callback' => [
'test-command-consumer-callback' => [
'command_bus' => 'test-command-bus',
'message_factory' => 'test-message-factory'
]
]
]
]
])->shouldBeCalled();
$container->get('test-command-bus')->willReturn($commandBus->reveal())->shouldBeCalled();
$container->get('test-message-factory')->willReturn($messageFactory->reveal())->shouldBeCalled();

$name = 'test-command-consumer-callback';
$amqpCommandConsumerCallback = AmqpCommandConsumerCallbackFactory::$name($container->reveal());
$this->assertInstanceOf(AmqpCommandConsumerCallback::class, $amqpCommandConsumerCallback);
}

/**
* @test
*/
public function it_throws_exception_when_no_container_passed_to_call_static()
{
$this->expectException(\Prooph\ServiceBus\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The first argument must be of type ' . ContainerInterface::class);

$name = 'test-command-consumer-callback';
AmqpCommandConsumerCallbackFactory::$name('invalid_container');
}
}
69 changes: 69 additions & 0 deletions tests/Container/AmqpDelayedMessageProducerFactoryTest.php
@@ -0,0 +1,69 @@
<?php
/*
* This file is part of the prooph/humus-amqpDelayed-producer.
* (c) 2016 prooph software GmbH <contact@prooph.de>
* (c) 2016 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types=1);

namespace ProophTest\ServiceBus\Message\HumusAmqpDelayed\Container;

use Humus\Amqp\Producer;
use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Prooph\Common\Messaging\MessageConverter;
use Prooph\ServiceBus\Message\HumusAmqp\AmqpDelayedMessageProducer;
use Prooph\ServiceBus\Message\HumusAmqp\Container\AmqpDelayedMessageProducerFactory;

/**
* Class AmqpDelayedMessageProducerFactoryTest
* @package ProophTest\ServiceBus\Message\HumusAmqpDelayed\Container
*/
class AmqpDelayedMessageProducerFactoryTest extends TestCase
{
/**
* @test
*/
public function it_creates_amqpDelayed_message_producer()
{
$producer = $this->prophesize(Producer::class);
$messageConverter = $this->prophesize(MessageConverter::class);

$container = $this->prophesize(ContainerInterface::class);
$container->get('config')->willReturn([
'prooph' => [
'humus-amqp-producer' => [
'delayed_message_producer' => [
'test-delayed-message-producer' => [
'producer' => 'test-producer',
'message_converter' => 'test-message-converter',
'app_id' => 'test-app'
]
]
]
]
])->shouldBeCalled();
$container->get('test-producer')->willReturn($producer->reveal())->shouldBeCalled();
$container->get('test-message-converter')->willReturn($messageConverter->reveal())->shouldBeCalled();

$name = 'test-delayed-message-producer';
$amqpDelayedMessageProducer = AmqpDelayedMessageProducerFactory::$name($container->reveal());
$this->assertInstanceOf(AmqpDelayedMessageProducer::class, $amqpDelayedMessageProducer);
}

/**
* @test
*/
public function it_throws_exception_when_no_container_passed_to_call_static()
{
$this->expectException(\Prooph\ServiceBus\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The first argument must be of type ' . ContainerInterface::class);

$name = 'test-delayed-message-producer';
AmqpDelayedMessageProducerFactory::$name('invalid_container');
}
}
68 changes: 68 additions & 0 deletions tests/Container/AmqpEventConsumerCallbackFactoryTest.php
@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the prooph/humus-amqp-producer.
* (c) 2016 prooph software GmbH <contact@prooph.de>
* (c) 2016 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types=1);

namespace ProophTest\ServiceBus\Message\HumusAmqp\Container;

use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Prooph\Common\Messaging\MessageFactory;
use Prooph\ServiceBus\EventBus;
use Prooph\ServiceBus\Message\HumusAmqp\AmqpEventConsumerCallback;
use Prooph\ServiceBus\Message\HumusAmqp\Container\AmqpEventConsumerCallbackFactory;

/**
* Class AmqpEventConsumerCallbackFactoryTest
* @package ProophTest\ServiceBus\Message\HumusAmqp\Container
*/
class AmqpEventConsumerCallbackFactoryTest extends TestCase
{
/**
* @test
*/
public function it_creates_amqp_event_consumer_callback()
{
$eventBus = $this->prophesize(EventBus::class);
$messageFactory = $this->prophesize(MessageFactory::class);

$container = $this->prophesize(ContainerInterface::class);
$container->get('config')->willReturn([
'prooph' => [
'humus-amqp-producer' => [
'event_consumer_callback' => [
'test-event-consumer-callback' => [
'event_bus' => 'test-event-bus',
'message_factory' => 'test-message-factory'
]
]
]
]
])->shouldBeCalled();
$container->get('test-event-bus')->willReturn($eventBus->reveal())->shouldBeCalled();
$container->get('test-message-factory')->willReturn($messageFactory->reveal())->shouldBeCalled();

$name = 'test-event-consumer-callback';
$amqpEventConsumerCallback = AmqpEventConsumerCallbackFactory::$name($container->reveal());
$this->assertInstanceOf(AmqpEventConsumerCallback::class, $amqpEventConsumerCallback);
}

/**
* @test
*/
public function it_throws_exception_when_no_container_passed_to_call_static()
{
$this->expectException(\Prooph\ServiceBus\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The first argument must be of type ' . ContainerInterface::class);

$name = 'test-event-consumer-callback';
AmqpEventConsumerCallbackFactory::$name('invalid_container');
}
}
69 changes: 69 additions & 0 deletions tests/Container/AmqpMessageProducerFactoryTest.php
@@ -0,0 +1,69 @@
<?php
/*
* This file is part of the prooph/humus-amqp-producer.
* (c) 2016 prooph software GmbH <contact@prooph.de>
* (c) 2016 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types=1);

namespace ProophTest\ServiceBus\Message\HumusAmqp\Container;

use Humus\Amqp\Producer;
use Interop\Container\ContainerInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Prooph\Common\Messaging\MessageConverter;
use Prooph\ServiceBus\Message\HumusAmqp\AmqpMessageProducer;
use Prooph\ServiceBus\Message\HumusAmqp\Container\AmqpMessageProducerFactory;

/**
* Class AmqpMessageProducerFactoryTest
* @package ProophTest\ServiceBus\Message\HumusAmqp\Container
*/
class AmqpMessageProducerFactoryTest extends TestCase
{
/**
* @test
*/
public function it_creates_amqp_message_producer()
{
$producer = $this->prophesize(Producer::class);
$messageConverter = $this->prophesize(MessageConverter::class);

$container = $this->prophesize(ContainerInterface::class);
$container->get('config')->willReturn([
'prooph' => [
'humus-amqp-producer' => [
'message_producer' => [
'test-message-producer' => [
'producer' => 'test-producer',
'message_converter' => 'test-message-converter',
'app_id' => 'test-app'
]
]
]
]
])->shouldBeCalled();
$container->get('test-producer')->willReturn($producer->reveal())->shouldBeCalled();
$container->get('test-message-converter')->willReturn($messageConverter->reveal())->shouldBeCalled();

$name = 'test-message-producer';
$amqpMessageProducer = AmqpMessageProducerFactory::$name($container->reveal());
$this->assertInstanceOf(AmqpMessageProducer::class, $amqpMessageProducer);
}

/**
* @test
*/
public function it_throws_exception_when_no_container_passed_to_call_static()
{
$this->expectException(\Prooph\ServiceBus\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The first argument must be of type ' . ContainerInterface::class);

$name = 'test-message-producer';
AmqpMessageProducerFactory::$name('invalid_container');
}
}

0 comments on commit 1a904e9

Please sign in to comment.