diff --git a/bin/release b/bin/release index 593196e01..2d1874039 100755 --- a/bin/release +++ b/bin/release @@ -13,7 +13,7 @@ fi CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` -for REMOTE in origin psr-queue stomp amqp-ext fs redis dbal enqueue enqueue-bundle job-queue test +for REMOTE in origin psr-queue stomp amqp-ext fs redis dbal null enqueue enqueue-bundle job-queue test do TMP_DIR="/tmp/enqueue-repo" REMOTE_URL=`git remote get-url $REMOTE` diff --git a/bin/subtree-split b/bin/subtree-split index 51bc06926..dd972a54e 100755 --- a/bin/subtree-split +++ b/bin/subtree-split @@ -50,6 +50,7 @@ remote amqp-ext git@github.com:php-enqueue/amqp-ext.git remote fs git@github.com:php-enqueue/fs.git remote redis git@github.com:php-enqueue/redis.git remote dbal git@github.com:php-enqueue/dbal.git +remote null git@github.com:php-enqueue/null.git remote enqueue-bundle git@github.com:php-enqueue/enqueue-bundle.git remote job-queue git@github.com:php-enqueue/job-queue.git remote test git@github.com:php-enqueue/test.git @@ -61,6 +62,7 @@ split 'pkg/amqp-ext' amqp-ext split 'pkg/fs' fs split 'pkg/redis' redis split 'pkg/dbal' dbal +split 'pkg/null' null split 'pkg/enqueue-bundle' enqueue-bundle split 'pkg/job-queue' job-queue split 'pkg/test' test diff --git a/composer.json b/composer.json index 8f16ac430..53088983e 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "enqueue/amqp-ext": "*@dev", "enqueue/redis": "*@dev", "enqueue/fs": "*@dev", + "enqueue/null": "*@dev", "enqueue/dbal": "*@dev", "enqueue/enqueue-bundle": "*@dev", "enqueue/job-queue": "*@dev", @@ -64,6 +65,10 @@ "type": "path", "url": "pkg/fs" }, + { + "type": "path", + "url": "pkg/null" + }, { "type": "path", "url": "pkg/dbal" diff --git a/docs/transport/null.md b/docs/transport/null.md index 652adb484..0a30244ea 100644 --- a/docs/transport/null.md +++ b/docs/transport/null.md @@ -10,14 +10,14 @@ Useful in tests for example. ## Installation ```bash -$ composer require enqueue/enqueue +$ composer require enqueue/null ``` ## Create context ```php pkg/enqueue/Tests - + pkg/stomp/Tests - + pkg/amqp-ext/Tests @@ -41,6 +41,10 @@ pkg/dbal/Tests + + pkg/null/Tests + + pkg/enqueue-bundle/Tests diff --git a/pkg/amqp-ext/Client/AmqpDriver.php b/pkg/amqp-ext/Client/AmqpDriver.php index 520672e72..ec11765de 100644 --- a/pkg/amqp-ext/Client/AmqpDriver.php +++ b/pkg/amqp-ext/Client/AmqpDriver.php @@ -115,7 +115,9 @@ public function setupBroker(LoggerInterface $logger = null) */ public function createQueue($queueName) { - $queue = $this->context->createQueue($this->config->createTransportQueueName($queueName)); + $transportName = $this->queueMetaRegistry->getQueueMeta($queueName)->getTransportName(); + + $queue = $this->context->createQueue($transportName); $queue->addFlag(AMQP_DURABLE); return $queue; diff --git a/pkg/amqp-ext/Tests/AmqpContextTest.php b/pkg/amqp-ext/Tests/AmqpContextTest.php index c06384500..dd46f0770 100644 --- a/pkg/amqp-ext/Tests/AmqpContextTest.php +++ b/pkg/amqp-ext/Tests/AmqpContextTest.php @@ -12,8 +12,8 @@ use Enqueue\Psr\PsrContext; use Enqueue\Psr\InvalidDestinationException; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullQueue; -use Enqueue\Transport\Null\NullTopic; +use Enqueue\Null\NullQueue; +use Enqueue\Null\NullTopic; use PHPUnit\Framework\TestCase; class AmqpContextTest extends TestCase @@ -96,7 +96,7 @@ public function testShouldThrowIfNotAmqpTopicGivenOnDeleteTopicCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Transport\Null\NullTopic.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Null\NullTopic.'); $context->deleteTopic(new NullTopic('aName')); } @@ -105,7 +105,7 @@ public function testShouldThrowIfNotAmqpTopicGivenOnDeclareTopicCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Transport\Null\NullTopic.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Null\NullTopic.'); $context->declareTopic(new NullTopic('aName')); } @@ -128,7 +128,7 @@ public function testShouldThrowIfNotAmqpQueueGivenOnDeleteQueueCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Null\NullQueue.'); $context->deleteQueue(new NullQueue('aName')); } @@ -137,7 +137,7 @@ public function testShouldThrowIfNotAmqpQueueGivenOnDeclareQueueCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Null\NullQueue.'); $context->declareQueue(new NullQueue('aName')); } @@ -172,7 +172,7 @@ public function testShouldThrowIfNotAmqpQueueGivenOnCreateConsumerCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Null\NullQueue.'); $context->createConsumer(new NullQueue('aName')); } @@ -181,7 +181,7 @@ public function testShouldThrowIfNotAmqpTopicGivenOnCreateConsumerCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Transport\Null\NullTopic.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Null\NullTopic.'); $context->createConsumer(new NullTopic('aName')); } @@ -291,7 +291,7 @@ public function testShouldThrowIfSourceNotAmqpTopicOnBindCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Transport\Null\NullTopic.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpTopic but got Enqueue\Null\NullTopic.'); $context->bind(new NullTopic('aName'), new AmqpQueue('aName')); } @@ -300,7 +300,7 @@ public function testShouldThrowIfTargetNotAmqpQueueOnBindCall() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Null\NullQueue.'); $context->bind(new AmqpTopic('aName'), new NullQueue('aName')); } @@ -309,7 +309,7 @@ public function testShouldThrowIfGivenQueueNotAmqpQueueOnPurge() $context = new AmqpContext($this->createExtChannelMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpExt\AmqpQueue but got Enqueue\Null\NullQueue.'); $context->purge(new NullQueue('aName')); } @@ -326,6 +326,9 @@ private function createExtChannelMock() */ private function createExtConnectionMock() { - return $this->createMock(\AMQPConnection::class); + return $this->getMockBuilder(\AMQPConnection::class) + ->setMethods(['isPersistent', 'isConnected', 'pdisconnect', 'disconnect']) + ->getMock() + ; } } diff --git a/pkg/amqp-ext/Tests/Client/AmqpDriverTest.php b/pkg/amqp-ext/Tests/Client/AmqpDriverTest.php index 68aa2ceaa..dd8f9ee8b 100644 --- a/pkg/amqp-ext/Tests/Client/AmqpDriverTest.php +++ b/pkg/amqp-ext/Tests/Client/AmqpDriverTest.php @@ -28,44 +28,62 @@ public function testCouldBeConstructedWithRequiredArguments() { new AmqpDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); } public function testShouldReturnConfigObject() { - $config = new Config('', '', '', '', '', ''); + $config = $this->createDummyConfig(); - $driver = new AmqpDriver($this->createPsrContextMock(), $config, $this->createQueueMetaRegistryMock()); + $driver = new AmqpDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $this->assertSame($config, $driver->getConfig()); } public function testShouldCreateAndReturnQueueInstance() { - $expectedQueue = new AmqpQueue('queue-name'); + $expectedQueue = new AmqpQueue('aName'); $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) ; - $driver = new AmqpDriver($context, new Config('', '', '', '', '', ''), $this->createQueueMetaRegistryMock()); + $driver = new AmqpDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aFooQueue'); $this->assertSame($expectedQueue, $queue); - $this->assertSame('queue-name', $queue->getQueueName()); $this->assertSame([], $queue->getArguments()); $this->assertSame(2, $queue->getFlags()); $this->assertNull($queue->getConsumerTag()); $this->assertSame([], $queue->getBindArguments()); } + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new AmqpQueue('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new AmqpDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aBarQueue'); + + $this->assertSame($expectedQueue, $queue); + } + public function testShouldConvertTransportMessageToClientMessage() { $transportMessage = new AmqpMessage(); @@ -81,8 +99,8 @@ public function testShouldConvertTransportMessageToClientMessage() $driver = new AmqpDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $clientMessage = $driver->createClientMessage($transportMessage); @@ -116,8 +134,8 @@ public function testShouldThrowExceptionIfExpirationIsNotNumeric() $driver = new AmqpDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -148,8 +166,8 @@ public function testShouldConvertClientMessageToTransportMessage() $driver = new AmqpDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -205,8 +223,8 @@ public function testShouldSendMessageToRouter() $driver = new AmqpDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); @@ -219,8 +237,8 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() { $driver = new AmqpDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -259,13 +277,13 @@ public function testShouldSendMessageToProcessor() $driver = new AmqpDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -274,8 +292,8 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() { $driver = new AmqpDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -288,8 +306,8 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() { $driver = new AmqpDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -347,13 +365,13 @@ public function testShouldSetupBroker() ->with($this->identicalTo($processorQueue)) ; - $meta = new QueueMetaRegistry(new Config('', '', '', '', '', ''), [ + $meta = new QueueMetaRegistry($this->createDummyConfig(), [ 'default' => [], ], 'default'); $driver = new AmqpDriver( $context, - new Config('', '', '', '', '', ''), + $this->createDummyConfig(), $meta ); @@ -377,10 +395,23 @@ private function createPsrProducerMock() } /** - * @return \PHPUnit_Framework_MockObject_MockObject|QueueMetaRegistry + * @return QueueMetaRegistry + */ + private function createDummyQueueMetaRegistry() + { + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; + } + + /** + * @return Config */ - private function createQueueMetaRegistryMock() + private function createDummyConfig() { - return $this->createMock(QueueMetaRegistry::class); + return Config::create('aPrefix'); } } diff --git a/pkg/amqp-ext/Tests/Client/RabbitMqDriverTest.php b/pkg/amqp-ext/Tests/Client/RabbitMqDriverTest.php index bc2a47c18..bc387cabe 100644 --- a/pkg/amqp-ext/Tests/Client/RabbitMqDriverTest.php +++ b/pkg/amqp-ext/Tests/Client/RabbitMqDriverTest.php @@ -35,44 +35,62 @@ public function testCouldBeConstructedWithRequiredArguments() { new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); } public function testShouldReturnConfigObject() { - $config = new Config('', '', '', '', '', ''); + $config = Config::create(); - $driver = new RabbitMqDriver($this->createPsrContextMock(), $config, $this->createQueueMetaRegistryMock()); + $driver = new RabbitMqDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $this->assertSame($config, $driver->getConfig()); } public function testShouldCreateAndReturnQueueInstance() { - $expectedQueue = new AmqpQueue('queue-name'); + $expectedQueue = new AmqpQueue('aName'); $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) ; - $driver = new RabbitMqDriver($context, new Config('', '', '', '', '', ''), $this->createQueueMetaRegistryMock()); + $driver = new AmqpDriver($context, Config::create(), $this->createDummyQueueMetaRegistry()); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aFooQueue'); $this->assertSame($expectedQueue, $queue); - $this->assertSame('queue-name', $queue->getQueueName()); - $this->assertSame(['x-max-priority' => 4], $queue->getArguments()); + $this->assertSame([], $queue->getArguments()); $this->assertSame(2, $queue->getFlags()); $this->assertNull($queue->getConsumerTag()); $this->assertSame([], $queue->getBindArguments()); } + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new AmqpQueue('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new AmqpDriver($context, Config::create(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aBarQueue'); + + $this->assertSame($expectedQueue, $queue); + } + public function testShouldConvertTransportMessageToClientMessage() { $transportMessage = new AmqpMessage(); @@ -91,7 +109,7 @@ public function testShouldConvertTransportMessageToClientMessage() $driver = new RabbitMqDriver( $this->createPsrContextMock(), new Config('', '', '', '', '', '', ['delay_plugin_installed' => true]), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $clientMessage = $driver->createClientMessage($transportMessage); @@ -129,8 +147,8 @@ public function testShouldThrowExceptionIfXDelayIsNotNumeric() $driver = new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -146,8 +164,8 @@ public function testShouldThrowExceptionIfExpirationIsNotNumeric() $driver = new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -163,8 +181,8 @@ public function testShouldThrowExceptionIfCantConvertTransportPriorityToClientPr $driver = new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -187,8 +205,8 @@ public function testShouldThrowExceptionIfCantConvertClientPriorityToTransportPr $driver = new RabbitMqDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -222,7 +240,7 @@ public function testShouldConvertClientMessageToTransportMessage() $driver = new RabbitMqDriver( $context, new Config('', '', '', '', '', '', ['delay_plugin_installed' => true]), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -265,7 +283,7 @@ public function testThrowIfDelayNotSupportedOnConvertClientMessageToTransportMes $driver = new RabbitMqDriver( $context, new Config('', '', '', '', '', '', ['delay_plugin_installed' => false]), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -303,8 +321,8 @@ public function testShouldSendMessageToRouter() $driver = new RabbitMqDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); @@ -317,8 +335,8 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() { $driver = new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -357,13 +375,13 @@ public function testShouldSendMessageToProcessor() $driver = new RabbitMqDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -405,12 +423,12 @@ public function testShouldSendMessageToDelayExchangeIfDelaySet() $driver = new RabbitMqDriver( $context, new Config('', '', '', '', '', '', ['delay_plugin_installed' => true]), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $message->setDelay(10); $driver->sendToProcessor($message); @@ -420,8 +438,8 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() { $driver = new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -434,8 +452,8 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() { $driver = new RabbitMqDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + Config::create(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -489,7 +507,7 @@ public function testShouldSetupBrokerWhenDelayPluginNotInstalled() ->willReturn($processorQueue) ; - $config = new Config('', '', '', '', '', '', ['delay_plugin_installed' => false]); + $config = Config::create('', '', '', '', '', '', ['delay_plugin_installed' => false]); $meta = new QueueMetaRegistry($config, ['default' => []]); @@ -566,7 +584,7 @@ public function testShouldSetupBroker() ->with($this->identicalTo($delayTopic), $this->identicalTo($processorQueue)) ; - $config = new Config('', '', '', '', '', '', ['delay_plugin_installed' => true]); + $config = Config::create('', '', '', '', '', '', ['delay_plugin_installed' => true]); $meta = new QueueMetaRegistry($config, ['default' => []]); @@ -592,10 +610,14 @@ private function createPsrProducerMock() } /** - * @return \PHPUnit_Framework_MockObject_MockObject|QueueMetaRegistry + * @return QueueMetaRegistry */ - private function createQueueMetaRegistryMock() + private function createDummyQueueMetaRegistry() { - return $this->createMock(QueueMetaRegistry::class); + $registry = new QueueMetaRegistry(Config::create('aPrefix'), []); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; } } diff --git a/pkg/amqp-ext/composer.json b/pkg/amqp-ext/composer.json index fca86ae24..93b195650 100644 --- a/pkg/amqp-ext/composer.json +++ b/pkg/amqp-ext/composer.json @@ -20,6 +20,7 @@ "phpunit/phpunit": "~5.4.0", "enqueue/test": "^0.3", "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3", "empi89/php-amqp-stubs": "*@dev", "symfony/dependency-injection": "^2.8|^3", "symfony/config": "^2.8|^3" diff --git a/pkg/dbal/Client/DbalDriver.php b/pkg/dbal/Client/DbalDriver.php index d3d7dc6d2..d0a68aeec 100644 --- a/pkg/dbal/Client/DbalDriver.php +++ b/pkg/dbal/Client/DbalDriver.php @@ -5,6 +5,7 @@ use Enqueue\Client\DriverInterface; use Enqueue\Client\Message; use Enqueue\Client\MessagePriority; +use Enqueue\Client\Meta\QueueMetaRegistry; use Enqueue\Dbal\DbalContext; use Enqueue\Dbal\DbalMessage; use Enqueue\Psr\PsrMessage; @@ -23,14 +24,21 @@ class DbalDriver implements DriverInterface */ private $config; + /** + * @var QueueMetaRegistry + */ + private $queueMetaRegistry; + /** * @param DbalContext $context - * @param Config $config + * @param Config $config + * @param QueueMetaRegistry $queueMetaRegistry */ - public function __construct(DbalContext $context, Config $config) + public function __construct(DbalContext $context, Config $config, QueueMetaRegistry $queueMetaRegistry) { $this->context = $context; $this->config = $config; + $this->queueMetaRegistry = $queueMetaRegistry; } /** @@ -121,7 +129,9 @@ public function sendToProcessor(Message $message) */ public function createQueue($queueName) { - return $this->context->createQueue($this->config->createTransportQueueName($queueName)); + $transportName = $this->queueMetaRegistry->getQueueMeta($queueName)->getTransportName(); + + return $this->context->createQueue($transportName); } /** diff --git a/pkg/dbal/Symfony/DbalTransportFactory.php b/pkg/dbal/Symfony/DbalTransportFactory.php index 972743521..5e59b750b 100644 --- a/pkg/dbal/Symfony/DbalTransportFactory.php +++ b/pkg/dbal/Symfony/DbalTransportFactory.php @@ -103,6 +103,7 @@ public function createDriver(ContainerBuilder $container, array $config) $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), + new Reference('enqueue.client.meta.queue_meta_registry'), ]); $driverId = sprintf('enqueue.client.%s.driver', $this->getName()); diff --git a/pkg/dbal/Tests/Client/DbalDriverTest.php b/pkg/dbal/Tests/Client/DbalDriverTest.php index b6a2b25e5..6c8bdb1ec 100644 --- a/pkg/dbal/Tests/Client/DbalDriverTest.php +++ b/pkg/dbal/Tests/Client/DbalDriverTest.php @@ -6,6 +6,7 @@ use Enqueue\Client\DriverInterface; use Enqueue\Client\Message; use Enqueue\Client\MessagePriority; +use Enqueue\Client\Meta\QueueMetaRegistry; use Enqueue\Dbal\Client\DbalDriver; use Enqueue\Dbal\DbalContext; use Enqueue\Dbal\DbalDestination; @@ -26,37 +27,60 @@ public function testCouldBeConstructedWithRequiredArguments() { new DbalDriver( $this->createPsrContextMock(), - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); } public function testShouldReturnConfigObject() { - $config = Config::create(); + $config = $this->createDummyConfig(); - $driver = new DbalDriver($this->createPsrContextMock(), $config); + $driver = new DbalDriver( + $this->createPsrContextMock(), + $config, + $this->createDummyQueueMetaRegistry() + ); $this->assertSame($config, $driver->getConfig()); } public function testShouldCreateAndReturnQueueInstance() { - $expectedQueue = new DbalDestination('queue-name'); + $expectedQueue = new DbalDestination('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) + ; + + $driver = new DbalDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aFooQueue'); + + $this->assertSame($expectedQueue, $queue); + } + + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new DbalDestination('aName'); $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aBarQueue') + ->willReturn($expectedQueue) ; - $driver = new DbalDriver($context, Config::create()); + $driver = new DbalDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aBarQueue'); $this->assertSame($expectedQueue, $queue); - $this->assertSame('queue-name', $queue->getQueueName()); } public function testShouldConvertTransportMessageToClientMessage() @@ -72,7 +96,8 @@ public function testShouldConvertTransportMessageToClientMessage() $driver = new DbalDriver( $this->createPsrContextMock(), - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $clientMessage = $driver->createClientMessage($transportMessage); @@ -118,7 +143,8 @@ public function testShouldConvertClientMessageToTransportMessage() $driver = new DbalDriver( $context, - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -144,18 +170,6 @@ public function testShouldSendMessageToRouter() { $topic = new DbalDestination('queue-name'); $transportMessage = new DbalMessage(); - $config = $this->createConfigMock(); - - $config - ->expects($this->once()) - ->method('getRouterQueueName') - ->willReturn('topicName'); - - $config - ->expects($this->once()) - ->method('createTransportQueueName') - ->with('topicName') - ->willReturn('app.topicName'); $producer = $this->createPsrProducerMock(); $producer @@ -167,7 +181,7 @@ public function testShouldSendMessageToRouter() $context ->expects($this->once()) ->method('createQueue') - ->with('app.topicName') + ->with('aprefix.default') ->willReturn($topic) ; $context @@ -183,7 +197,8 @@ public function testShouldSendMessageToRouter() $driver = new DbalDriver( $context, - $config + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); @@ -196,7 +211,8 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() { $driver = new DbalDriver( $this->createPsrContextMock(), - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -235,12 +251,13 @@ public function testShouldSendMessageToProcessor() $driver = new DbalDriver( $context, - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -249,7 +266,8 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() { $driver = new DbalDriver( $this->createPsrContextMock(), - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -262,7 +280,8 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() { $driver = new DbalDriver( $this->createPsrContextMock(), - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -288,7 +307,8 @@ public function testShouldSetupBroker() $driver = new DbalDriver( $context, - Config::create() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $driver->setupBroker(); @@ -311,10 +331,23 @@ private function createPsrProducerMock() } /** - * @return \PHPUnit_Framework_MockObject_MockObject|Config + * @return QueueMetaRegistry + */ + private function createDummyQueueMetaRegistry() + { + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; + } + + /** + * @return Config */ - private function createConfigMock() + private function createDummyConfig() { - return $this->createMock(Config::class); + return Config::create('aPrefix'); } } diff --git a/pkg/dbal/Tests/Symfony/DbalTransportFactoryTest.php b/pkg/dbal/Tests/Symfony/DbalTransportFactoryTest.php index 365e9db83..979d11274 100644 --- a/pkg/dbal/Tests/Symfony/DbalTransportFactoryTest.php +++ b/pkg/dbal/Tests/Symfony/DbalTransportFactoryTest.php @@ -150,5 +150,8 @@ public function testShouldCreateDriver() $this->assertInstanceOf(Reference::class, $driver->getArgument(1)); $this->assertEquals('enqueue.client.config', (string) $driver->getArgument(1)); + + $this->assertInstanceOf(Reference::class, $driver->getArgument(2)); + $this->assertEquals('enqueue.client.meta.queue_meta_registry', (string) $driver->getArgument(2)); } } diff --git a/pkg/dbal/composer.json b/pkg/dbal/composer.json index ff4e62d5c..fc851303e 100644 --- a/pkg/dbal/composer.json +++ b/pkg/dbal/composer.json @@ -20,6 +20,7 @@ "phpunit/phpunit": "~5.4.0", "enqueue/test": "^0.3", "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3", "symfony/dependency-injection": "^2.8|^3", "symfony/config": "^2.8|^3" }, diff --git a/pkg/enqueue-bundle/DependencyInjection/Compiler/BuildQueueMetaRegistryPass.php b/pkg/enqueue-bundle/DependencyInjection/Compiler/BuildQueueMetaRegistryPass.php index af9ffea2f..4cc641f2e 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Compiler/BuildQueueMetaRegistryPass.php +++ b/pkg/enqueue-bundle/DependencyInjection/Compiler/BuildQueueMetaRegistryPass.php @@ -28,6 +28,10 @@ public function process(ContainerBuilder $container) foreach ($subscriptions as $subscription) { $configs[$subscription['queueName']]['processors'][] = $subscription['processorName']; + + if ($subscription['queueNameHardcoded']) { + $configs[$subscription['queueName']]['transportName'] = $subscription['queueName']; + } } } diff --git a/pkg/enqueue-bundle/DependencyInjection/Compiler/ExtractProcessorTagSubscriptionsTrait.php b/pkg/enqueue-bundle/DependencyInjection/Compiler/ExtractProcessorTagSubscriptionsTrait.php index cd15177d9..825c142a5 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Compiler/ExtractProcessorTagSubscriptionsTrait.php +++ b/pkg/enqueue-bundle/DependencyInjection/Compiler/ExtractProcessorTagSubscriptionsTrait.php @@ -38,6 +38,7 @@ protected function extractSubscriptions(ContainerBuilder $container, $processorS $subscriptionPrototype = [ 'topicName' => null, 'queueName' => null, + 'queueNameHardcoded' => false, 'processorName' => null, ]; @@ -48,6 +49,7 @@ protected function extractSubscriptions(ContainerBuilder $container, $processorS $data[] = [ 'topicName' => $params, 'queueName' => $defaultQueueName, + 'queueNameHardcoded' => false, 'processorName' => $processorServiceId, ]; } elseif (is_array($params)) { @@ -56,6 +58,7 @@ protected function extractSubscriptions(ContainerBuilder $container, $processorS $data[] = [ 'topicName' => $topicName, 'queueName' => $resolve($params['queueName']) ?: $defaultQueueName, + 'queueNameHardcoded' => $resolve($params['queueNameHardcoded']), 'processorName' => $resolve($params['processorName']) ?: $processorServiceId, ]; } else { @@ -76,6 +79,7 @@ protected function extractSubscriptions(ContainerBuilder $container, $processorS $data[] = [ 'topicName' => $resolve($tagAttribute['topicName']), 'queueName' => $resolve($tagAttribute['queueName']) ?: $defaultQueueName, + 'queueNameHardcoded' => $resolve($tagAttribute['queueNameHardcoded']), 'processorName' => $resolve($tagAttribute['processorName']) ?: $processorServiceId, ]; } diff --git a/pkg/enqueue-bundle/EnqueueBundle.php b/pkg/enqueue-bundle/EnqueueBundle.php index 531383e04..bdf738dde 100644 --- a/pkg/enqueue-bundle/EnqueueBundle.php +++ b/pkg/enqueue-bundle/EnqueueBundle.php @@ -21,7 +21,7 @@ use Enqueue\Stomp\Symfony\RabbitMqStompTransportFactory; use Enqueue\Stomp\Symfony\StompTransportFactory; use Enqueue\Symfony\DefaultTransportFactory; -use Enqueue\Symfony\NullTransportFactory; +use Enqueue\Null\Symfony\NullTransportFactory; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/pkg/enqueue-bundle/Tests/Functional/QueuesCommandTest.php b/pkg/enqueue-bundle/Tests/Functional/QueuesCommandTest.php index 76ff88a83..642d7058e 100644 --- a/pkg/enqueue-bundle/Tests/Functional/QueuesCommandTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/QueuesCommandTest.php @@ -17,7 +17,7 @@ public function testCouldBeGetFromContainerAsService() $this->assertInstanceOf(QueuesCommand::class, $command); } - public function testShouldDisplayRegisteredDestionations() + public function testShouldDisplayRegisteredQueues() { $command = $this->container->get('enqueue.client.meta.queues_command'); diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php index 5f3f64827..0ae61b208 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -5,7 +5,7 @@ use Enqueue\Bundle\DependencyInjection\Configuration; use Enqueue\Bundle\Tests\Unit\Mocks\FooTransportFactory; use Enqueue\Symfony\DefaultTransportFactory; -use Enqueue\Symfony\NullTransportFactory; +use Enqueue\Null\Symfony\NullTransportFactory; use Enqueue\Test\ClassExtensionTrait; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php index 5a1a46b47..f7d1c9352 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php @@ -8,9 +8,9 @@ use Enqueue\Client\Producer; use Enqueue\Client\TraceableProducer; use Enqueue\Symfony\DefaultTransportFactory; -use Enqueue\Symfony\NullTransportFactory; +use Enqueue\Null\Symfony\NullTransportFactory; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullContext; +use Enqueue\Null\NullContext; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; diff --git a/pkg/enqueue-bundle/Tests/Unit/EnqueueBundleTest.php b/pkg/enqueue-bundle/Tests/Unit/EnqueueBundleTest.php index 6a63fde9d..b4bd8d688 100644 --- a/pkg/enqueue-bundle/Tests/Unit/EnqueueBundleTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/EnqueueBundleTest.php @@ -17,7 +17,7 @@ use Enqueue\Stomp\Symfony\RabbitMqStompTransportFactory; use Enqueue\Stomp\Symfony\StompTransportFactory; use Enqueue\Symfony\DefaultTransportFactory; -use Enqueue\Symfony\NullTransportFactory; +use Enqueue\Null\Symfony\NullTransportFactory; use Enqueue\Test\ClassExtensionTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index a18cd1767..1e83a1e90 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -13,7 +13,8 @@ "require": { "php": ">=5.6", "symfony/framework-bundle": "^2.8|^3", - "enqueue/enqueue": "^0.3" + "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3" }, "require-dev": { "phpunit/phpunit": "~5.5", diff --git a/pkg/enqueue/Client/Config.php b/pkg/enqueue/Client/Config.php index 4018281b3..b08947252 100644 --- a/pkg/enqueue/Client/Config.php +++ b/pkg/enqueue/Client/Config.php @@ -134,6 +134,7 @@ public function getTransportOption($name, $default = null) * @param string|null $routerQueueName * @param string|null $defaultProcessorQueueName * @param string|null $routerProcessorName + * @param array $transportConfig * * @return static */ @@ -143,7 +144,8 @@ public static function create( $routerTopicName = null, $routerQueueName = null, $defaultProcessorQueueName = null, - $routerProcessorName = null + $routerProcessorName = null, + array $transportConfig = [] ) { return new static( $prefix ?: '', @@ -151,7 +153,8 @@ public static function create( $routerTopicName ?: 'router', $routerQueueName ?: 'default', $defaultProcessorQueueName ?: 'default', - $routerProcessorName ?: 'router' + $routerProcessorName ?: 'router', + $transportConfig ); } } diff --git a/pkg/enqueue/Client/Meta/QueueMetaRegistry.php b/pkg/enqueue/Client/Meta/QueueMetaRegistry.php index 71a2c0342..9d70c9a4a 100644 --- a/pkg/enqueue/Client/Meta/QueueMetaRegistry.php +++ b/pkg/enqueue/Client/Meta/QueueMetaRegistry.php @@ -73,12 +73,14 @@ public function getQueueMeta($queueName) )); } + + $transportName = $this->config->createTransportQueueName($queueName); $meta = array_replace([ 'processors' => [], 'transportName' => $transportName, - ], $this->meta[$queueName]); + ], array_filter($this->meta[$queueName])); return new QueueMeta($queueName, $meta['transportName'], $meta['processors']); } diff --git a/pkg/enqueue/Client/TopicSubscriberInterface.php b/pkg/enqueue/Client/TopicSubscriberInterface.php index 9d66d2cca..ac5b49d76 100644 --- a/pkg/enqueue/Client/TopicSubscriberInterface.php +++ b/pkg/enqueue/Client/TopicSubscriberInterface.php @@ -5,9 +5,21 @@ interface TopicSubscriberInterface { /** - * * ['topicName'] - * * ['topicName' => ['processorName' => 'processor', 'destinationName' => 'destination']] - * processorName, destinationName - optional. + * The result maybe either: + * + * ['aTopicName'] + * + * or + * + * ['aTopicName' => [ + * 'processorName' => 'processor', + * 'queueName' => 'a_client_queue_name', + * 'queueNameHardcoded' => true, + * ]] + * + * processorName, queueName and queueNameHardcoded are optional. + * + * Note: If you set queueNameHardcoded to true then the queueName is used as is and therefor the driver is not used to create a transport queue name. * * @return array */ diff --git a/pkg/enqueue/Consumption/QueueSubscriberInterface.php b/pkg/enqueue/Consumption/QueueSubscriberInterface.php new file mode 100644 index 000000000..e609b6d83 --- /dev/null +++ b/pkg/enqueue/Consumption/QueueSubscriberInterface.php @@ -0,0 +1,14 @@ +destinationRegistry = $queueRegistry; + $this->queueMetaRegistry = $queueRegistry; } /** @@ -51,15 +51,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $count = 0; $firstRow = true; - foreach ($this->destinationRegistry->getQueuesMeta() as $destination) { + foreach ($this->queueMetaRegistry->getQueuesMeta() as $queueMeta) { if (false == $firstRow) { $table->addRow(new TableSeparator()); } $table->addRow([ - $destination->getClientName(), - $destination->getTransportName(), - implode(PHP_EOL, $destination->getProcessors()), + $queueMeta->getClientName(), + $queueMeta->getClientName() == $queueMeta->getTransportName() ? '(same)' : $queueMeta->getTransportName(), + implode(PHP_EOL, $queueMeta->getProcessors()), ]); ++$count; diff --git a/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php b/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php index e3afb4cfc..b3081d319 100644 --- a/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php +++ b/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php @@ -8,8 +8,8 @@ use Enqueue\Consumption\Context; use Enqueue\Consumption\Result; use Enqueue\Psr\PsrContext; -use Enqueue\Transport\Null\NullMessage; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullMessage; +use Enqueue\Null\NullQueue; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; diff --git a/pkg/enqueue/Tests/Client/ConsumptionExtension/SetRouterPropertiesExtensionTest.php b/pkg/enqueue/Tests/Client/ConsumptionExtension/SetRouterPropertiesExtensionTest.php index 19a5d18a1..56d6c73ca 100644 --- a/pkg/enqueue/Tests/Client/ConsumptionExtension/SetRouterPropertiesExtensionTest.php +++ b/pkg/enqueue/Tests/Client/ConsumptionExtension/SetRouterPropertiesExtensionTest.php @@ -9,7 +9,7 @@ use Enqueue\Consumption\ExtensionInterface; use Enqueue\Psr\PsrContext; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class SetRouterPropertiesExtensionTest extends TestCase diff --git a/pkg/enqueue/Tests/Client/DelegateProcessorTest.php b/pkg/enqueue/Tests/Client/DelegateProcessorTest.php index 83c2dea89..9cfc88010 100644 --- a/pkg/enqueue/Tests/Client/DelegateProcessorTest.php +++ b/pkg/enqueue/Tests/Client/DelegateProcessorTest.php @@ -7,7 +7,7 @@ use Enqueue\Client\ProcessorRegistryInterface; use Enqueue\Psr\PsrContext; use Enqueue\Psr\PsrProcessor; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class DelegateProcessorTest extends TestCase diff --git a/pkg/enqueue/Tests/Client/Meta/QueueMetaRegistryTest.php b/pkg/enqueue/Tests/Client/Meta/QueueMetaRegistryTest.php index a759390fa..787290fe6 100644 --- a/pkg/enqueue/Tests/Client/Meta/QueueMetaRegistryTest.php +++ b/pkg/enqueue/Tests/Client/Meta/QueueMetaRegistryTest.php @@ -100,6 +100,17 @@ public function testShouldAllowGetQueueByNameWithCustomInfo() $this->assertSame(['theSubscriber'], $queue->getProcessors()); } + public function testShouldNotAllowToOverwriteDefaultTransportNameByEmptyValue() + { + $registry = new QueueMetaRegistry($this->createConfig(), [ + 'theClientQueueName' => ['transportName' => null, 'processors' => []], + ]); + + $queue = $registry->getQueueMeta('theClientQueueName'); + $this->assertInstanceOf(QueueMeta::class, $queue); + $this->assertSame('aprefix.anappname.theclientqueuename', $queue->getTransportName()); + } + public function testShouldAllowGetAllQueues() { $queues = [ diff --git a/pkg/enqueue/Tests/Client/Meta/QueueMetaTest.php b/pkg/enqueue/Tests/Client/Meta/QueueMetaTest.php index e98a163dc..fde6dc52f 100644 --- a/pkg/enqueue/Tests/Client/Meta/QueueMetaTest.php +++ b/pkg/enqueue/Tests/Client/Meta/QueueMetaTest.php @@ -9,31 +9,31 @@ class QueueMetaTest extends TestCase { public function testCouldBeConstructedWithExpectedArguments() { - $destination = new QueueMeta('aClientName', 'aTransportName'); + $meta = new QueueMeta('aClientName', 'aTransportName'); - $this->assertAttributeEquals('aClientName', 'clientName', $destination); - $this->assertAttributeEquals('aTransportName', 'transportName', $destination); - $this->assertAttributeEquals([], 'processors', $destination); + $this->assertAttributeEquals('aClientName', 'clientName', $meta); + $this->assertAttributeEquals('aTransportName', 'transportName', $meta); + $this->assertAttributeEquals([], 'processors', $meta); } public function testShouldAllowGetClientNameSetInConstructor() { - $destination = new QueueMeta('theClientName', 'aTransportName'); + $meta = new QueueMeta('theClientName', 'aTransportName'); - $this->assertSame('theClientName', $destination->getClientName()); + $this->assertSame('theClientName', $meta->getClientName()); } public function testShouldAllowGetTransportNameSetInConstructor() { - $destination = new QueueMeta('aClientName', 'theTransportName'); + $meta = new QueueMeta('aClientName', 'theTransportName'); - $this->assertSame('theTransportName', $destination->getTransportName()); + $this->assertSame('theTransportName', $meta->getTransportName()); } public function testShouldAllowGetSubscribersSetInConstructor() { - $destination = new QueueMeta('aClientName', 'aTransportName', ['aSubscriber']); + $meta = new QueueMeta('aClientName', 'aTransportName', ['aSubscriber']); - $this->assertSame(['aSubscriber'], $destination->getProcessors()); + $this->assertSame(['aSubscriber'], $meta->getProcessors()); } } diff --git a/pkg/enqueue/Tests/Client/ProducerTest.php b/pkg/enqueue/Tests/Client/ProducerTest.php index 107736593..9741810cc 100644 --- a/pkg/enqueue/Tests/Client/ProducerTest.php +++ b/pkg/enqueue/Tests/Client/ProducerTest.php @@ -9,7 +9,7 @@ use Enqueue\Client\Producer; use Enqueue\Client\ProducerInterface; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullQueue; use PHPUnit\Framework\TestCase; class ProducerTest extends TestCase diff --git a/pkg/enqueue/Tests/Client/RouterProcessorTest.php b/pkg/enqueue/Tests/Client/RouterProcessorTest.php index 20d0d547e..9d300d734 100644 --- a/pkg/enqueue/Tests/Client/RouterProcessorTest.php +++ b/pkg/enqueue/Tests/Client/RouterProcessorTest.php @@ -7,8 +7,8 @@ use Enqueue\Client\Message; use Enqueue\Client\RouterProcessor; use Enqueue\Consumption\Result; -use Enqueue\Transport\Null\NullContext; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullContext; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class RouterProcessorTest extends TestCase diff --git a/pkg/enqueue/Tests/Client/RpcClientTest.php b/pkg/enqueue/Tests/Client/RpcClientTest.php index 7fc9042f0..cc88da246 100644 --- a/pkg/enqueue/Tests/Client/RpcClientTest.php +++ b/pkg/enqueue/Tests/Client/RpcClientTest.php @@ -8,8 +8,8 @@ use Enqueue\Psr\PsrConsumer; use Enqueue\Psr\PsrContext; use Enqueue\Rpc\Promise; -use Enqueue\Transport\Null\NullContext; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullContext; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class RpcClientTest extends TestCase diff --git a/pkg/enqueue/Tests/Consumption/CallbackProcessorTest.php b/pkg/enqueue/Tests/Consumption/CallbackProcessorTest.php index 3a48b1e27..d56d98161 100644 --- a/pkg/enqueue/Tests/Consumption/CallbackProcessorTest.php +++ b/pkg/enqueue/Tests/Consumption/CallbackProcessorTest.php @@ -5,8 +5,8 @@ use Enqueue\Consumption\CallbackProcessor; use Enqueue\Psr\PsrProcessor; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullContext; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullContext; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class CallbackProcessorTest extends TestCase diff --git a/pkg/enqueue/Tests/Consumption/ContextTest.php b/pkg/enqueue/Tests/Consumption/ContextTest.php index 1773bbeb2..81e1ef3e7 100644 --- a/pkg/enqueue/Tests/Consumption/ContextTest.php +++ b/pkg/enqueue/Tests/Consumption/ContextTest.php @@ -9,7 +9,7 @@ use Enqueue\Psr\PsrMessage; use Enqueue\Psr\PsrProcessor; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullQueue; use Psr\Log\NullLogger; use PHPUnit\Framework\TestCase; diff --git a/pkg/enqueue/Tests/Consumption/Extension/LoggerExtensionTest.php b/pkg/enqueue/Tests/Consumption/Extension/LoggerExtensionTest.php index 9f2cf6ce9..945dc9cb2 100644 --- a/pkg/enqueue/Tests/Consumption/Extension/LoggerExtensionTest.php +++ b/pkg/enqueue/Tests/Consumption/Extension/LoggerExtensionTest.php @@ -9,7 +9,7 @@ use Enqueue\Psr\PsrConsumer; use Enqueue\Psr\PsrContext; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; diff --git a/pkg/enqueue/Tests/Consumption/Extension/ReplyExtensionTest.php b/pkg/enqueue/Tests/Consumption/Extension/ReplyExtensionTest.php index 4efaec3db..ec93032fe 100644 --- a/pkg/enqueue/Tests/Consumption/Extension/ReplyExtensionTest.php +++ b/pkg/enqueue/Tests/Consumption/Extension/ReplyExtensionTest.php @@ -9,8 +9,8 @@ use Enqueue\Psr\PsrContext; use Enqueue\Psr\PsrProducer; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullMessage; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullMessage; +use Enqueue\Null\NullQueue; use PHPUnit\Framework\TestCase; class ReplyExtensionTest extends TestCase diff --git a/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php b/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php index d72ae372b..1167c539e 100644 --- a/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php +++ b/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php @@ -15,7 +15,7 @@ use Enqueue\Psr\PsrProcessor; use Enqueue\Psr\PsrQueue; use Enqueue\Tests\Consumption\Mock\BreakCycleExtension; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullQueue; use Psr\Log\NullLogger; use PHPUnit\Framework\TestCase; diff --git a/pkg/enqueue/Tests/Consumption/ResultTest.php b/pkg/enqueue/Tests/Consumption/ResultTest.php index e26311813..19d43b564 100644 --- a/pkg/enqueue/Tests/Consumption/ResultTest.php +++ b/pkg/enqueue/Tests/Consumption/ResultTest.php @@ -3,7 +3,7 @@ namespace Enqueue\Tests\Consumption; use Enqueue\Consumption\Result; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class ResultTest extends TestCase diff --git a/pkg/enqueue/Tests/Functional/Client/RpcClientTest.php b/pkg/enqueue/Tests/Functional/Client/RpcClientTest.php index ee409a156..bf7d69e13 100644 --- a/pkg/enqueue/Tests/Functional/Client/RpcClientTest.php +++ b/pkg/enqueue/Tests/Functional/Client/RpcClientTest.php @@ -16,6 +16,9 @@ use Enqueue\Test\RabbitmqManagmentExtensionTrait; use PHPUnit\Framework\TestCase; +/** + * @group functional + */ class RpcClientTest extends TestCase { use RabbitmqAmqpExtension; diff --git a/pkg/enqueue/Tests/Functional/Client/SimpleClientTest.php b/pkg/enqueue/Tests/Functional/Client/SimpleClientTest.php index c62b5903b..f96ba9571 100644 --- a/pkg/enqueue/Tests/Functional/Client/SimpleClientTest.php +++ b/pkg/enqueue/Tests/Functional/Client/SimpleClientTest.php @@ -13,6 +13,9 @@ use Enqueue\Test\RabbitmqManagmentExtensionTrait; use PHPUnit\Framework\TestCase; +/** + * @group functional + */ class SimpleClientTest extends TestCase { use RabbitmqAmqpExtension; diff --git a/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php b/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php index 25cc5bf0e..9b4c49971 100644 --- a/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php +++ b/pkg/enqueue/Tests/Router/RouteRecipientListProcessorTest.php @@ -10,8 +10,8 @@ use Enqueue\Router\RecipientListRouterInterface; use Enqueue\Router\RouteRecipientListProcessor; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullMessage; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullMessage; +use Enqueue\Null\NullQueue; use PHPUnit\Framework\TestCase; class RouteRecipientListProcessorTest extends TestCase diff --git a/pkg/enqueue/Tests/Rpc/PromiseTest.php b/pkg/enqueue/Tests/Rpc/PromiseTest.php index 11b49a3a9..389c1786f 100644 --- a/pkg/enqueue/Tests/Rpc/PromiseTest.php +++ b/pkg/enqueue/Tests/Rpc/PromiseTest.php @@ -5,7 +5,7 @@ use Enqueue\Psr\PsrConsumer; use Enqueue\Rpc\Promise; use Enqueue\Rpc\TimeoutException; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use PHPUnit\Framework\TestCase; class PromiseTest extends TestCase diff --git a/pkg/enqueue/Tests/Rpc/RpcClientTest.php b/pkg/enqueue/Tests/Rpc/RpcClientTest.php index c64dc44dc..bec9c6dc0 100644 --- a/pkg/enqueue/Tests/Rpc/RpcClientTest.php +++ b/pkg/enqueue/Tests/Rpc/RpcClientTest.php @@ -7,9 +7,9 @@ use Enqueue\Psr\PsrProducer; use Enqueue\Rpc\Promise; use Enqueue\Rpc\RpcClient; -use Enqueue\Transport\Null\NullContext; -use Enqueue\Transport\Null\NullMessage; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullContext; +use Enqueue\Null\NullMessage; +use Enqueue\Null\NullQueue; use PHPUnit\Framework\TestCase; class RpcClientTest extends TestCase diff --git a/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php index 603f0c15e..87cfa88b6 100644 --- a/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php @@ -10,7 +10,7 @@ use Enqueue\Consumption\QueueConsumer; use Enqueue\Psr\PsrContext; use Enqueue\Symfony\Client\ConsumeMessagesCommand; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullQueue; use Symfony\Component\Console\Tester\CommandTester; use PHPUnit\Framework\TestCase; diff --git a/pkg/enqueue/Tests/Symfony/Client/Mock/SetupBrokerExtensionCommand.php b/pkg/enqueue/Tests/Symfony/Client/Mock/SetupBrokerExtensionCommand.php index 603fb090a..2f3d65ba8 100644 --- a/pkg/enqueue/Tests/Symfony/Client/Mock/SetupBrokerExtensionCommand.php +++ b/pkg/enqueue/Tests/Symfony/Client/Mock/SetupBrokerExtensionCommand.php @@ -3,9 +3,10 @@ namespace Enqueue\Tests\Symfony\Client\Mock; use Enqueue\Client\Config; -use Enqueue\Client\NullDriver; +use Enqueue\Client\Meta\QueueMetaRegistry; +use Enqueue\Null\Client\NullDriver; use Enqueue\Symfony\Client\SetupBrokerExtensionCommandTrait; -use Enqueue\Transport\Null\NullContext; +use Enqueue\Null\NullContext; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -30,6 +31,10 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $this->extension = $this->getSetupBrokerExtension($input, new NullDriver(new NullContext(), Config::create())); + $this->extension = $this->getSetupBrokerExtension($input, new NullDriver( + new NullContext(), + Config::create(), + new QueueMetaRegistry(Config::create(), []) + )); } } diff --git a/pkg/enqueue/composer.json b/pkg/enqueue/composer.json index c2dc4cb16..cfa0e9ca1 100644 --- a/pkg/enqueue/composer.json +++ b/pkg/enqueue/composer.json @@ -20,6 +20,7 @@ "symfony/console": "^2.8|^3", "symfony/dependency-injection": "^2.8|^3", "symfony/config": "^2.8|^3", + "enqueue/null": "^0.3", "enqueue/test": "^0.3" }, "suggest": { diff --git a/pkg/fs/Client/FsDriver.php b/pkg/fs/Client/FsDriver.php index 784389e55..9eecb6156 100644 --- a/pkg/fs/Client/FsDriver.php +++ b/pkg/fs/Client/FsDriver.php @@ -113,7 +113,9 @@ public function setupBroker(LoggerInterface $logger = null) */ public function createQueue($queueName) { - return $this->context->createQueue($this->config->createTransportQueueName($queueName)); + $transportName = $this->queueMetaRegistry->getQueueMeta($queueName)->getTransportName(); + + return $this->context->createQueue($transportName); } /** diff --git a/pkg/fs/README.md b/pkg/fs/README.md index 2b937a886..07ca4fd3c 100644 --- a/pkg/fs/README.md +++ b/pkg/fs/README.md @@ -1,5 +1,12 @@ # Enqueue Filesystem Transport +[![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby) +[![Build Status](https://travis-ci.org/php-enqueue/fs.png?branch=master)](https://travis-ci.org/php-enqueue/fs) +[![Total Downloads](https://poser.pugx.org/enqueue/fs/d/total.png)](https://packagist.org/packages/enqueue/fs) +[![Latest Stable Version](https://poser.pugx.org/enqueue/fs/version.png)](https://packagist.org/packages/enqueue/fs) + +This is an implementation of PSR queue specification. It allows you to send and consume message stored locally in files. + ## Resources * [Documentation](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md) diff --git a/pkg/fs/Tests/Client/FsDriverTest.php b/pkg/fs/Tests/Client/FsDriverTest.php index b07b3f1ff..c19d1efc6 100644 --- a/pkg/fs/Tests/Client/FsDriverTest.php +++ b/pkg/fs/Tests/Client/FsDriverTest.php @@ -28,16 +28,16 @@ public function testCouldBeConstructedWithRequiredArguments() { new FsDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); } public function testShouldReturnConfigObject() { - $config = new Config('', '', '', '', '', ''); + $config = $this->createDummyConfig(); - $driver = new FsDriver($this->createPsrContextMock(), $config, $this->createQueueMetaRegistryMock()); + $driver = new FsDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $this->assertSame($config, $driver->getConfig()); } @@ -50,16 +50,34 @@ public function testShouldCreateAndReturnQueueInstance() $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) ; - $driver = new FsDriver($context, new Config('', '', '', '', '', ''), $this->createQueueMetaRegistryMock()); + $driver = new FsDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aFooQueue'); + + $this->assertSame($expectedQueue, $queue); + } + + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new FsDestination(new TempFile(sys_get_temp_dir().'/queue-name')); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new FsDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aBarQueue'); $this->assertSame($expectedQueue, $queue); - $this->assertSame('queue-name', $queue->getQueueName()); } public function testShouldConvertTransportMessageToClientMessage() @@ -76,8 +94,8 @@ public function testShouldConvertTransportMessageToClientMessage() $driver = new FsDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $clientMessage = $driver->createClientMessage($transportMessage); @@ -128,8 +146,8 @@ public function testShouldConvertClientMessageToTransportMessage() $driver = new FsDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -157,18 +175,7 @@ public function testShouldSendMessageToRouter() { $topic = new FsDestination(TempFile::generate()); $transportMessage = new FsMessage(); - $config = $this->createConfigMock(); - - $config - ->expects($this->once()) - ->method('getRouterTopicName') - ->willReturn('topicName'); - - $config - ->expects($this->once()) - ->method('createTransportQueueName') - ->with('topicName') - ->willReturn('app.topicName'); + $config = $this->createDummyConfig(); $producer = $this->createPsrProducerMock(); $producer @@ -180,7 +187,7 @@ public function testShouldSendMessageToRouter() $context ->expects($this->once()) ->method('createTopic') - ->with('app.topicName') + ->with('aprefix.router') ->willReturn($topic) ; $context @@ -197,7 +204,7 @@ public function testShouldSendMessageToRouter() $driver = new FsDriver( $context, $config, - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $message = new Message(); @@ -210,8 +217,8 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() { $driver = new FsDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -250,13 +257,13 @@ public function testShouldSendMessageToProcessor() $driver = new FsDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -265,8 +272,8 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() { $driver = new FsDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -279,8 +286,8 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() { $driver = new FsDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock() + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -333,13 +340,13 @@ public function testShouldSetupBroker() ->with($this->identicalTo($processorQueue)) ; - $meta = new QueueMetaRegistry(new Config('', '', '', '', '', ''), [ + $meta = new QueueMetaRegistry($this->createDummyConfig(), [ 'default' => [], ], 'default'); $driver = new FsDriver( $context, - new Config('', '', '', '', '', ''), + $this->createDummyConfig(), $meta ); @@ -363,18 +370,23 @@ private function createPsrProducerMock() } /** - * @return \PHPUnit_Framework_MockObject_MockObject|QueueMetaRegistry + * @return QueueMetaRegistry */ - private function createQueueMetaRegistryMock() + private function createDummyQueueMetaRegistry() { - return $this->createMock(QueueMetaRegistry::class); + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; } /** - * @return \PHPUnit_Framework_MockObject_MockObject|Config + * @return Config */ - private function createConfigMock() + private function createDummyConfig() { - return $this->createMock(Config::class); + return Config::create('aPrefix'); } } diff --git a/pkg/fs/Tests/FsContextTest.php b/pkg/fs/Tests/FsContextTest.php index 7c22ebc93..8a348c821 100644 --- a/pkg/fs/Tests/FsContextTest.php +++ b/pkg/fs/Tests/FsContextTest.php @@ -10,7 +10,7 @@ use Enqueue\Psr\InvalidDestinationException; use Enqueue\Psr\PsrContext; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullQueue; use Makasim\File\TempFile; class FsContextTest extends \PHPUnit\Framework\TestCase @@ -114,7 +114,7 @@ public function testShouldThrowIfNotFsDestinationGivenOnCreateConsumer() $context = new FsContext(sys_get_temp_dir(), 1, 0666); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\Fs\FsDestination but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\Fs\FsDestination but got Enqueue\Null\NullQueue.'); $consumer = $context->createConsumer(new NullQueue('aQueue')); $this->assertInstanceOf(FsConsumer::class, $consumer); diff --git a/pkg/fs/Tests/FsProducerTest.php b/pkg/fs/Tests/FsProducerTest.php index 36fe6a6db..28e807448 100644 --- a/pkg/fs/Tests/FsProducerTest.php +++ b/pkg/fs/Tests/FsProducerTest.php @@ -10,8 +10,8 @@ use Enqueue\Psr\InvalidMessageException; use Enqueue\Psr\PsrProducer; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullMessage; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullMessage; +use Enqueue\Null\NullQueue; use Makasim\File\TempFile; class FsProducerTest extends \PHPUnit\Framework\TestCase @@ -33,7 +33,7 @@ public function testThrowIfDestinationNotFsOnSend() $producer = new FsProducer($this->createContextMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\Fs\FsDestination but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\Fs\FsDestination but got Enqueue\Null\NullQueue.'); $producer->send(new NullQueue('aQueue'), new FsMessage()); } @@ -42,7 +42,7 @@ public function testThrowIfMessageNotFsOnSend() $producer = new FsProducer($this->createContextMock()); $this->expectException(InvalidMessageException::class); - $this->expectExceptionMessage('The message must be an instance of Enqueue\Fs\FsMessage but it is Enqueue\Transport\Null\NullMessage.'); + $this->expectExceptionMessage('The message must be an instance of Enqueue\Fs\FsMessage but it is Enqueue\Null\NullMessage.'); $producer->send(new FsDestination(TempFile::generate()), new NullMessage()); } diff --git a/pkg/fs/composer.json b/pkg/fs/composer.json index 236592ee6..0a0189b5f 100644 --- a/pkg/fs/composer.json +++ b/pkg/fs/composer.json @@ -20,6 +20,7 @@ "require-dev": { "phpunit/phpunit": "~5.5", "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3", "enqueue/test": "^0.3", "symfony/dependency-injection": "^2.8|^3", "symfony/config": "^2.8|^3" diff --git a/pkg/job-queue/Tests/CalculateRootJobStatusProcessorTest.php b/pkg/job-queue/Tests/CalculateRootJobStatusProcessorTest.php index de653b072..63f0956c4 100644 --- a/pkg/job-queue/Tests/CalculateRootJobStatusProcessorTest.php +++ b/pkg/job-queue/Tests/CalculateRootJobStatusProcessorTest.php @@ -10,7 +10,7 @@ use Enqueue\JobQueue\JobStorage; use Enqueue\JobQueue\Topics; use Enqueue\Psr\PsrContext; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use Psr\Log\LoggerInterface; class CalculateRootJobStatusProcessorTest extends \PHPUnit\Framework\TestCase diff --git a/pkg/job-queue/Tests/DependentJobProcessorTest.php b/pkg/job-queue/Tests/DependentJobProcessorTest.php index 1728fef54..fc2b0b80d 100644 --- a/pkg/job-queue/Tests/DependentJobProcessorTest.php +++ b/pkg/job-queue/Tests/DependentJobProcessorTest.php @@ -10,7 +10,7 @@ use Enqueue\JobQueue\JobStorage; use Enqueue\JobQueue\Topics; use Enqueue\Psr\PsrContext; -use Enqueue\Transport\Null\NullMessage; +use Enqueue\Null\NullMessage; use Psr\Log\LoggerInterface; class DependentJobProcessorTest extends \PHPUnit\Framework\TestCase diff --git a/pkg/job-queue/composer.json b/pkg/job-queue/composer.json index 017c64087..a1d371e86 100644 --- a/pkg/job-queue/composer.json +++ b/pkg/job-queue/composer.json @@ -14,6 +14,7 @@ "php": ">=5.6", "symfony/framework-bundle": "^2.8|^3", "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3", "doctrine/orm": "~2.4" }, "require-dev": { diff --git a/pkg/null/.gitignore b/pkg/null/.gitignore new file mode 100644 index 000000000..a770439e5 --- /dev/null +++ b/pkg/null/.gitignore @@ -0,0 +1,6 @@ +*~ +/composer.lock +/composer.phar +/phpunit.xml +/vendor/ +/.idea/ diff --git a/pkg/null/.travis.yml b/pkg/null/.travis.yml new file mode 100644 index 000000000..42374ddc7 --- /dev/null +++ b/pkg/null/.travis.yml @@ -0,0 +1,21 @@ +sudo: false + +git: + depth: 1 + +language: php + +php: + - '5.6' + - '7.0' + +cache: + directories: + - $HOME/.composer/cache + +install: + - composer self-update + - composer install --prefer-source + +script: + - vendor/bin/phpunit --exclude-group=functional diff --git a/pkg/enqueue/Client/NullDriver.php b/pkg/null/Client/NullDriver.php similarity index 85% rename from pkg/enqueue/Client/NullDriver.php rename to pkg/null/Client/NullDriver.php index 5fa2bcf41..39a0de549 100644 --- a/pkg/enqueue/Client/NullDriver.php +++ b/pkg/null/Client/NullDriver.php @@ -1,10 +1,14 @@ context = $context; $this->config = $config; + $this->queueMetaRegistry = $queueMetaRegistry; } /** @@ -95,7 +106,9 @@ public function createClientMessage(PsrMessage $message) */ public function createQueue($queueName) { - return $this->context->createQueue($queueName); + $transportName = $this->queueMetaRegistry->getQueueMeta($queueName)->getTransportName(); + + return $this->context->createQueue($transportName); } /** diff --git a/pkg/null/LICENSE b/pkg/null/LICENSE new file mode 100644 index 000000000..d9fa0fd46 --- /dev/null +++ b/pkg/null/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2013 Oro, Inc +Copyright (c) 2017 Kotliar Maksym + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/pkg/enqueue/Transport/Null/NullConnectionFactory.php b/pkg/null/NullConnectionFactory.php similarity index 87% rename from pkg/enqueue/Transport/Null/NullConnectionFactory.php rename to pkg/null/NullConnectionFactory.php index 69767cfbb..d69f7c3a9 100644 --- a/pkg/enqueue/Transport/Null/NullConnectionFactory.php +++ b/pkg/null/NullConnectionFactory.php @@ -1,6 +1,6 @@ setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), + new Reference('enqueue.client.meta.queue_meta_registry'), ]); $driverId = sprintf('enqueue.client.%s.driver', $this->getName()); diff --git a/pkg/enqueue/Tests/Client/NullDriverTest.php b/pkg/null/Tests/Client/NullDriverTest.php similarity index 68% rename from pkg/enqueue/Tests/Client/NullDriverTest.php rename to pkg/null/Tests/Client/NullDriverTest.php index d81298fc1..c233b1a2b 100644 --- a/pkg/enqueue/Tests/Client/NullDriverTest.php +++ b/pkg/null/Tests/Client/NullDriverTest.php @@ -1,28 +1,67 @@ createDummyQueueMetaRegistry()); + } + + public function testShouldCreateAndReturnQueueInstance() + { + $expectedQueue = new NullQueue('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) + ; + + $driver = new NullDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aFooQueue'); + + $this->assertSame($expectedQueue, $queue); + } + + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new NullQueue('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new NullDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aBarQueue'); + + $this->assertSame($expectedQueue, $queue); } public function testShouldSendMessageToRouter() { - $config = new Config('', '', '', '', '', ''); + $config = Config::create(); $topic = new NullTopic('topic'); $transportMessage = new NullMessage(); @@ -34,7 +73,7 @@ public function testShouldSendMessageToRouter() ->with(self::identicalTo($topic), self::identicalTo($transportMessage)) ; - $context = $this->createContextMock(); + $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createTopic') @@ -51,14 +90,14 @@ public function testShouldSendMessageToRouter() ->willReturn($producer) ; - $driver = new NullDriver($context, $config); + $driver = new NullDriver($context, $config, $this->createDummyQueueMetaRegistry()); $driver->sendToRouter(new Message()); } public function testShouldSendMessageToProcessor() { - $config = new Config('', '', '', '', '', ''); + $config = Config::create(); $queue = new NullQueue(''); $transportMessage = new NullMessage(); @@ -70,7 +109,7 @@ public function testShouldSendMessageToProcessor() ->with(self::identicalTo($queue), self::identicalTo($transportMessage)) ; - $context = $this->createContextMock(); + $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createQueue') @@ -87,14 +126,14 @@ public function testShouldSendMessageToProcessor() ->willReturn($producer) ; - $driver = new NullDriver($context, $config); + $driver = new NullDriver($context, $config, $this->createDummyQueueMetaRegistry()); $driver->sendToProcessor(new Message()); } public function testShouldConvertClientMessageToTransportMessage() { - $config = new Config('', '', '', '', '', ''); + $config = Config::create(); $clientMessage = new Message(); $clientMessage->setBody('theBody'); @@ -111,14 +150,14 @@ public function testShouldConvertClientMessageToTransportMessage() $transportMessage = new NullMessage(); - $context = $this->createContextMock(); + $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createMessage') ->willReturn($transportMessage) ; - $driver = new NullDriver($context, $config); + $driver = new NullDriver($context, $config, $this->createDummyQueueMetaRegistry()); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -146,7 +185,7 @@ public function testShouldConvertClientMessageToTransportMessage() public function testShouldConvertTransportMessageToClientMessage() { - $config = new Config('', '', '', '', '', ''); + $config = Config::create(); $transportMessage = new NullMessage(); $transportMessage->setBody('theBody'); @@ -161,7 +200,7 @@ public function testShouldConvertTransportMessageToClientMessage() $transportMessage->setReplyTo('theReplyTo'); $transportMessage->setCorrelationId('theCorrelationId'); - $driver = new NullDriver($this->createContextMock(), $config); + $driver = new NullDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $clientMessage = $driver->createClientMessage($transportMessage); @@ -191,9 +230,9 @@ public function testShouldConvertTransportMessageToClientMessage() public function testShouldReturnConfigInstance() { - $config = new Config('', '', '', '', '', ''); + $config = Config::create(); - $driver = new NullDriver($this->createContextMock(), $config); + $driver = new NullDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $result = $driver->getConfig(); self::assertSame($config, $result); @@ -202,7 +241,7 @@ public function testShouldReturnConfigInstance() /** * @return \PHPUnit_Framework_MockObject_MockObject|NullContext */ - private function createContextMock() + private function createPsrContextMock() { return $this->createMock(NullContext::class); } @@ -214,4 +253,25 @@ private function createMessageProducer() { return $this->createMock(NullProducer::class); } + + /** + * @return QueueMetaRegistry + */ + private function createDummyQueueMetaRegistry() + { + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; + } + + /** + * @return Config + */ + private function createDummyConfig() + { + return Config::create('aPrefix'); + } } diff --git a/pkg/enqueue/Tests/Transport/Null/NullConnectionFactoryTest.php b/pkg/null/Tests/NullConnectionFactoryTest.php similarity index 84% rename from pkg/enqueue/Tests/Transport/Null/NullConnectionFactoryTest.php rename to pkg/null/Tests/NullConnectionFactoryTest.php index 088812016..90013225c 100644 --- a/pkg/enqueue/Tests/Transport/Null/NullConnectionFactoryTest.php +++ b/pkg/null/Tests/NullConnectionFactoryTest.php @@ -1,11 +1,11 @@ assertEquals('enqueue.client.null.driver', $driverId); $this->assertTrue($container->hasDefinition($driverId)); - $context = $container->getDefinition($driverId); - $this->assertEquals(NullDriver::class, $context->getClass()); - $this->assertNull($context->getFactory()); + $driver = $container->getDefinition($driverId); + $this->assertEquals(NullDriver::class, $driver->getClass()); + $this->assertNull($driver->getFactory()); + + $this->assertInstanceOf(Reference::class, $driver->getArgument(0)); + $this->assertEquals('enqueue.transport.null.context', (string) $driver->getArgument(0)); + + $this->assertInstanceOf(Reference::class, $driver->getArgument(1)); + $this->assertEquals('enqueue.client.config', (string) $driver->getArgument(1)); + + $this->assertInstanceOf(Reference::class, $driver->getArgument(2)); + $this->assertEquals('enqueue.client.meta.queue_meta_registry', (string) $driver->getArgument(2)); } } diff --git a/pkg/null/composer.json b/pkg/null/composer.json new file mode 100644 index 000000000..0a5e3edaf --- /dev/null +++ b/pkg/null/composer.json @@ -0,0 +1,37 @@ +{ + "name": "enqueue/null", + "type": "library", + "description": "Enqueue Null transport", + "keywords": ["messaging", "queue", "testing"], + "license": "MIT", + "repositories": [ + { + "type": "vcs", + "url": "git@github.com:php-enqueue/test.git" + } + ], + "require": { + "php": ">=5.6", + "enqueue/psr-queue": "^0.3", + "psr/log": "^1" + }, + "require-dev": { + "phpunit/phpunit": "~5.5", + "enqueue/enqueue": "^0.3", + "enqueue/test": "^0.3", + "symfony/dependency-injection": "^2.8|^3", + "symfony/config": "^2.8|^3" + }, + "autoload": { + "psr-4": { "Enqueue\\Null\\": "" }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "0.3.x-dev" + } + } +} diff --git a/pkg/null/phpunit.xml.dist b/pkg/null/phpunit.xml.dist new file mode 100644 index 000000000..2fd4e20c3 --- /dev/null +++ b/pkg/null/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + + ./Tests + + + + + + . + + ./vendor + ./Resources + ./Tests + + + + diff --git a/pkg/redis/Client/RedisDriver.php b/pkg/redis/Client/RedisDriver.php index 57ae0f2c5..846562651 100644 --- a/pkg/redis/Client/RedisDriver.php +++ b/pkg/redis/Client/RedisDriver.php @@ -12,7 +12,6 @@ use Enqueue\Redis\RedisDestination; use Enqueue\Redis\RedisMessage; use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; class RedisDriver implements DriverInterface { @@ -91,7 +90,9 @@ public function setupBroker(LoggerInterface $logger = null) */ public function createQueue($queueName) { - return $this->context->createQueue($this->config->createTransportQueueName($queueName)); + $transportName = $this->queueMetaRegistry->getQueueMeta($queueName)->getTransportName(); + + return $this->context->createQueue($transportName); } /** diff --git a/pkg/redis/Tests/Client/RedisDriverTest.php b/pkg/redis/Tests/Client/RedisDriverTest.php index 3a8e8c938..a95b8511e 100644 --- a/pkg/redis/Tests/Client/RedisDriverTest.php +++ b/pkg/redis/Tests/Client/RedisDriverTest.php @@ -29,7 +29,7 @@ public function testCouldBeConstructedWithRequiredArguments() new RedisDriver( $this->createPsrContextMock(), Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); } @@ -37,29 +37,47 @@ public function testShouldReturnConfigObject() { $config = Config::create();; - $driver = new RedisDriver($this->createPsrContextMock(), $config, $this->createQueueMetaRegistryMock()); + $driver = new RedisDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $this->assertSame($config, $driver->getConfig()); } public function testShouldCreateAndReturnQueueInstance() { - $expectedQueue = new RedisDestination('aQueueName'); + $expectedQueue = new RedisDestination('aName'); $context = $this->createPsrContextMock(); $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) ; - $driver = new RedisDriver($context, Config::create(), $this->createQueueMetaRegistryMock()); + $driver = new RedisDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aFooQueue'); + + $this->assertSame($expectedQueue, $queue); + } + + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new RedisDestination('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new RedisDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aBarQueue'); $this->assertSame($expectedQueue, $queue); - $this->assertSame('aQueueName', $queue->getQueueName()); } public function testShouldConvertTransportMessageToClientMessage() @@ -79,7 +97,7 @@ public function testShouldConvertTransportMessageToClientMessage() $driver = new RedisDriver( $this->createPsrContextMock(), Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $clientMessage = $driver->createClientMessage($transportMessage); @@ -131,7 +149,7 @@ public function testShouldConvertClientMessageToTransportMessage() $driver = new RedisDriver( $context, Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -159,18 +177,7 @@ public function testShouldSendMessageToRouterQueue() { $topic = new RedisDestination('aDestinationName'); $transportMessage = new RedisMessage(); - $config = $this->createConfigMock(); - - $config - ->expects($this->once()) - ->method('getRouterQueueName') - ->willReturn('queueName'); - - $config - ->expects($this->once()) - ->method('createTransportQueueName') - ->with('queueName') - ->willReturn('app.queueName'); + $config = $this->createDummyConfig(); $producer = $this->createPsrProducerMock(); $producer @@ -182,7 +189,7 @@ public function testShouldSendMessageToRouterQueue() $context ->expects($this->once()) ->method('createQueue') - ->with('app.queueName') + ->with('aprefix.default') ->willReturn($topic) ; $context @@ -199,7 +206,7 @@ public function testShouldSendMessageToRouterQueue() $driver = new RedisDriver( $context, $config, - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $message = new Message(); @@ -213,7 +220,7 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() $driver = new RedisDriver( $this->createPsrContextMock(), Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -253,12 +260,12 @@ public function testShouldSendMessageToProcessor() $driver = new RedisDriver( $context, Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -268,7 +275,7 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() $driver = new RedisDriver( $this->createPsrContextMock(), Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -282,7 +289,7 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() $driver = new RedisDriver( $this->createPsrContextMock(), Config::create(), - $this->createQueueMetaRegistryMock() + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -337,18 +344,23 @@ private function createPsrProducerMock() } /** - * @return \PHPUnit_Framework_MockObject_MockObject|QueueMetaRegistry + * @return QueueMetaRegistry */ - private function createQueueMetaRegistryMock() + private function createDummyQueueMetaRegistry() { - return $this->createMock(QueueMetaRegistry::class); + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; } /** - * @return \PHPUnit_Framework_MockObject_MockObject|Config + * @return Config */ - private function createConfigMock() + private function createDummyConfig() { - return $this->createMock(Config::class); + return Config::create('aPrefix'); } } diff --git a/pkg/redis/Tests/RedisContextTest.php b/pkg/redis/Tests/RedisContextTest.php index dd6d02d90..febc49d18 100644 --- a/pkg/redis/Tests/RedisContextTest.php +++ b/pkg/redis/Tests/RedisContextTest.php @@ -11,8 +11,8 @@ use Enqueue\Psr\InvalidDestinationException; use Enqueue\Psr\PsrContext; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullQueue; -use Enqueue\Transport\Null\NullTopic; +use Enqueue\Null\NullQueue; +use Enqueue\Null\NullTopic; use PHPUnit\Framework\TestCase; class RedisContextTest extends \PHPUnit\Framework\TestCase @@ -112,7 +112,7 @@ public function testShouldThrowIfNotRedisDestinationGivenOnCreateConsumer() $context = new RedisContext($this->createRedisMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\Redis\RedisDestination but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\Redis\RedisDestination but got Enqueue\Null\NullQueue.'); $consumer = $context->createConsumer(new NullQueue('aQueue')); $this->assertInstanceOf(RedisConsumer::class, $consumer); diff --git a/pkg/redis/Tests/RedisProducerTest.php b/pkg/redis/Tests/RedisProducerTest.php index 454d25e42..c629dd36d 100644 --- a/pkg/redis/Tests/RedisProducerTest.php +++ b/pkg/redis/Tests/RedisProducerTest.php @@ -10,8 +10,8 @@ use Enqueue\Redis\RedisMessage; use Enqueue\Redis\RedisProducer; use Enqueue\Test\ClassExtensionTrait; -use Enqueue\Transport\Null\NullMessage; -use Enqueue\Transport\Null\NullQueue; +use Enqueue\Null\NullMessage; +use Enqueue\Null\NullQueue; use PHPUnit\Framework\TestCase; class RedisProducerTest extends TestCase @@ -33,7 +33,7 @@ public function testThrowIfDestinationNotRedisDestinationOnSend() $producer = new RedisProducer($this->createRedisMock()); $this->expectException(InvalidDestinationException::class); - $this->expectExceptionMessage('The destination must be an instance of Enqueue\Redis\RedisDestination but got Enqueue\Transport\Null\NullQueue.'); + $this->expectExceptionMessage('The destination must be an instance of Enqueue\Redis\RedisDestination but got Enqueue\Null\NullQueue.'); $producer->send(new NullQueue('aQueue'), new RedisMessage()); } @@ -42,7 +42,7 @@ public function testThrowIfMessageNotRedisMessageOnSend() $producer = new RedisProducer($this->createRedisMock()); $this->expectException(InvalidMessageException::class); - $this->expectExceptionMessage('The message must be an instance of Enqueue\Redis\RedisMessage but it is Enqueue\Transport\Null\NullMessage.'); + $this->expectExceptionMessage('The message must be an instance of Enqueue\Redis\RedisMessage but it is Enqueue\Null\NullMessage.'); $producer->send(new RedisDestination('aQueue'), new NullMessage()); } diff --git a/pkg/redis/composer.json b/pkg/redis/composer.json index 43cacc176..a0c8e2032 100644 --- a/pkg/redis/composer.json +++ b/pkg/redis/composer.json @@ -20,6 +20,7 @@ "predis/predis": "^1.1", "enqueue/test": "^0.3", "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3", "symfony/dependency-injection": "^2.8|^3", "symfony/config": "^2.8|^3" }, diff --git a/pkg/stomp/Client/RabbitMqStompDriver.php b/pkg/stomp/Client/RabbitMqStompDriver.php index 82f2dbcb1..fdfcfb21f 100644 --- a/pkg/stomp/Client/RabbitMqStompDriver.php +++ b/pkg/stomp/Client/RabbitMqStompDriver.php @@ -48,7 +48,7 @@ class RabbitMqStompDriver extends StompDriver */ public function __construct(StompContext $context, Config $config, QueueMetaRegistry $queueMetaRegistry, ManagementClient $management) { - parent::__construct($context, $config); + parent::__construct($context, $config, $queueMetaRegistry); $this->context = $context; $this->config = $config; diff --git a/pkg/stomp/Client/StompDriver.php b/pkg/stomp/Client/StompDriver.php index e868b83cb..4cfe5d05d 100644 --- a/pkg/stomp/Client/StompDriver.php +++ b/pkg/stomp/Client/StompDriver.php @@ -5,6 +5,7 @@ use Enqueue\Client\Config; use Enqueue\Client\DriverInterface; use Enqueue\Client\Message; +use Enqueue\Client\Meta\QueueMetaRegistry; use Enqueue\Psr\PsrMessage; use Enqueue\Stomp\StompContext; use Enqueue\Stomp\StompDestination; @@ -24,14 +25,21 @@ class StompDriver implements DriverInterface */ private $config; + /** + * @var QueueMetaRegistry + */ + private $queueMetaRegistry; + /** * @param StompContext $context - * @param Config $config + * @param Config $config + * @param QueueMetaRegistry $queueMetaRegistry */ - public function __construct(StompContext $context, Config $config) + public function __construct(StompContext $context, Config $config, QueueMetaRegistry $queueMetaRegistry) { $this->context = $context; $this->config = $config; + $this->queueMetaRegistry = $queueMetaRegistry; } /** @@ -149,7 +157,9 @@ public function createClientMessage(PsrMessage $message) */ public function createQueue($queueName) { - $queue = $this->context->createQueue($this->config->createTransportQueueName($queueName)); + $transportName = $this->queueMetaRegistry->getQueueMeta($queueName)->getTransportName(); + + $queue = $this->context->createQueue($transportName); $queue->setDurable(true); $queue->setAutoDelete(false); $queue->setExclusive(false); diff --git a/pkg/stomp/Tests/Client/RabbitMqStompDriverTest.php b/pkg/stomp/Tests/Client/RabbitMqStompDriverTest.php index 8675dd890..724132516 100644 --- a/pkg/stomp/Tests/Client/RabbitMqStompDriverTest.php +++ b/pkg/stomp/Tests/Client/RabbitMqStompDriverTest.php @@ -30,20 +30,20 @@ public function testCouldBeConstructedWithRequiredArguments() { new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); } public function testShouldReturnConfigObject() { - $config = new Config('', '', '', '', '', ''); + $config = $this->createDummyConfig(); $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), $config, - $this->createQueueMetaRegistryMock(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -52,24 +52,24 @@ public function testShouldReturnConfigObject() public function testShouldCreateAndReturnQueueInstance() { - $expectedQueue = new StompDestination(); + $expectedQueue = new StompDestination('aName'); - $session = $this->createPsrContextMock(); - $session + $context = $this->createPsrContextMock(); + $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) ; $driver = new RabbitMqStompDriver( - $session, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $context, + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aFooQueue'); $expectedHeaders = [ 'durable' => true, @@ -85,6 +85,30 @@ public function testShouldCreateAndReturnQueueInstance() $this->assertSame($expectedHeaders, $queue->getHeaders()); } + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new StompDestination('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new RabbitMqStompDriver( + $context, + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), + $this->createManagementClientMock() + ); + + $queue = $driver->createQueue('aBarQueue'); + + $this->assertSame($expectedQueue, $queue); + } + public function testShouldConvertTransportMessageToClientMessage() { $transportMessage = new StompMessage(); @@ -102,8 +126,8 @@ public function testShouldConvertTransportMessageToClientMessage() $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -130,8 +154,8 @@ public function testShouldThrowExceptionIfXDelayIsNotNumeric() $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -148,8 +172,8 @@ public function testShouldThrowExceptionIfExpirationIsNotNumeric() $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -166,8 +190,8 @@ public function testShouldThrowExceptionIfCantConvertTransportPriorityToClientPr $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -193,8 +217,8 @@ public function testShouldThrowExceptionIfCantConvertClientPriorityToTransportPr $driver = new RabbitMqStompDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -229,7 +253,7 @@ public function testShouldConvertClientMessageToTransportMessage() $driver = new RabbitMqStompDriver( $context, new Config('', '', '', '', '', '', ['delay_plugin_installed' => true]), - $this->createQueueMetaRegistryMock(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -271,7 +295,7 @@ public function testShouldThrowExceptionIfDelayIsSetButDelayPluginInstalledOptio $driver = new RabbitMqStompDriver( $context, new Config('', '', '', '', '', '', ['delay_plugin_installed' => false]), - $this->createQueueMetaRegistryMock(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -311,8 +335,8 @@ public function testShouldSendMessageToRouter() $driver = new RabbitMqStompDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -326,8 +350,8 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() { $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -352,6 +376,7 @@ public function testShouldSendMessageToProcessor() $context ->expects($this->once()) ->method('createQueue') + ->with('aprefix.afooqueue') ->willReturn($queue) ; $context @@ -367,14 +392,14 @@ public function testShouldSendMessageToProcessor() $driver = new RabbitMqStompDriver( $context, - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -416,13 +441,13 @@ public function testShouldSendMessageToDelayExchangeIfDelaySet() $driver = new RabbitMqStompDriver( $context, new Config('', '', '', '', '', '', ['delay_plugin_installed' => true]), - $this->createQueueMetaRegistryMock(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $message->setDelay(10); $driver->sendToProcessor($message); @@ -432,8 +457,8 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() { $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -447,8 +472,8 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() { $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', ''), - $this->createQueueMetaRegistryMock(), + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -466,7 +491,7 @@ public function testShouldNotSetupBrokerIfManagementPluginInstalledOptionIsNotEn $driver = new RabbitMqStompDriver( $this->createPsrContextMock(), new Config('', '', '', '', '', '', ['management_plugin_installed' => false]), - $this->createQueueMetaRegistryMock(), + $this->createDummyQueueMetaRegistry(), $this->createManagementClientMock() ); @@ -482,12 +507,7 @@ public function testShouldNotSetupBrokerIfManagementPluginInstalledOptionIsNotEn public function testShouldSetupBroker() { - $metaRegistry = $this->createQueueMetaRegistryMock(); - $metaRegistry - ->expects($this->once()) - ->method('getQueuesMeta') - ->willReturn([new QueueMeta('processorQueue', '')]) - ; + $metaRegistry = $this->createDummyQueueMetaRegistry(); $managementClient = $this->createManagementClientMock(); $managementClient @@ -518,7 +538,7 @@ public function testShouldSetupBroker() $managementClient ->expects($this->at(3)) ->method('declareQueue') - ->with('prefix.app.processorqueue', [ + ->with('prefix.app.default', [ 'durable' => true, 'auto_delete' => false, 'arguments' => [ @@ -553,7 +573,7 @@ public function testShouldSetupBroker() $logger ->expects($this->at(3)) ->method('debug') - ->with('[RabbitMqStompDriver] Declare processor queue: prefix.app.processorqueue') + ->with('[RabbitMqStompDriver] Declare processor queue: prefix.app.default') ; $driver->setupBroker($logger); @@ -561,18 +581,13 @@ public function testShouldSetupBroker() public function testSetupBrokerShouldCreateDelayExchangeIfEnabled() { - $metaRegistry = $this->createQueueMetaRegistryMock(); - $metaRegistry - ->expects($this->exactly(2)) - ->method('getQueuesMeta') - ->willReturn([new QueueMeta('processorQueue', '')]) - ; + $metaRegistry = $this->createDummyQueueMetaRegistry(); $managementClient = $this->createManagementClientMock(); $managementClient - ->expects($this->at(4)) + ->expects($this->at(6)) ->method('declareExchange') - ->with('prefix.app.processorqueue.delayed', [ + ->with('prefix.app.default.delayed', [ 'type' => 'x-delayed-message', 'durable' => true, 'auto_delete' => false, @@ -582,9 +597,9 @@ public function testSetupBrokerShouldCreateDelayExchangeIfEnabled() ]) ; $managementClient - ->expects($this->at(5)) + ->expects($this->at(7)) ->method('bind') - ->with('prefix.app.processorqueue.delayed', 'prefix.app.processorqueue', 'prefix.app.processorqueue') + ->with('prefix.app.default.delayed', 'prefix.app.default', 'prefix.app.default') ; $driver = new RabbitMqStompDriver( @@ -596,14 +611,14 @@ public function testSetupBrokerShouldCreateDelayExchangeIfEnabled() $logger = $this->createLoggerMock(); $logger - ->expects($this->at(4)) + ->expects($this->at(6)) ->method('debug') - ->with('[RabbitMqStompDriver] Declare delay exchange: prefix.app.processorqueue.delayed') + ->with('[RabbitMqStompDriver] Declare delay exchange: prefix.app.default.delayed') ; $logger - ->expects($this->at(5)) + ->expects($this->at(7)) ->method('debug') - ->with('[RabbitMqStompDriver] Bind processor queue to delay exchange: prefix.app.processorqueue -> prefix.app.processorqueue.delayed') + ->with('[RabbitMqStompDriver] Bind processor queue to delay exchange: prefix.app.default -> prefix.app.default.delayed') ; $driver->setupBroker($logger); @@ -625,14 +640,6 @@ private function createPsrProducerMock() return $this->createMock(StompProducer::class); } - /** - * @return \PHPUnit_Framework_MockObject_MockObject|QueueMetaRegistry - */ - private function createQueueMetaRegistryMock() - { - return $this->createMock(QueueMetaRegistry::class); - } - /** * @return \PHPUnit_Framework_MockObject_MockObject|ManagementClient */ @@ -648,4 +655,25 @@ private function createLoggerMock() { return $this->createMock(LoggerInterface::class); } + + /** + * @return QueueMetaRegistry + */ + private function createDummyQueueMetaRegistry() + { + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; + } + + /** + * @return Config + */ + private function createDummyConfig() + { + return Config::create('aPrefix'); + } } diff --git a/pkg/stomp/Tests/Client/StompDriverTest.php b/pkg/stomp/Tests/Client/StompDriverTest.php index 45ed57895..0e74d9953 100644 --- a/pkg/stomp/Tests/Client/StompDriverTest.php +++ b/pkg/stomp/Tests/Client/StompDriverTest.php @@ -5,6 +5,7 @@ use Enqueue\Client\Config; use Enqueue\Client\DriverInterface; use Enqueue\Client\Message; +use Enqueue\Client\Meta\QueueMetaRegistry; use Enqueue\Stomp\Client\StompDriver; use Enqueue\Stomp\StompContext; use Enqueue\Stomp\StompDestination; @@ -24,33 +25,33 @@ public function testShouldImplementsDriverInterface() public function testCouldBeConstructedWithRequiredArguments() { - new StompDriver($this->createPsrContextMock(), new Config('', '', '', '', '', '')); + new StompDriver($this->createPsrContextMock(), $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); } public function testShouldReturnConfigObject() { - $config = new Config('', '', '', '', '', ''); + $config = $this->createDummyConfig(); - $driver = new StompDriver($this->createPsrContextMock(), $config); + $driver = new StompDriver($this->createPsrContextMock(), $config, $this->createDummyQueueMetaRegistry()); $this->assertSame($config, $driver->getConfig()); } public function testShouldCreateAndReturnQueueInstance() { - $expectedQueue = new StompDestination(); + $expectedQueue = new StompDestination('aName'); - $session = $this->createPsrContextMock(); - $session + $context = $this->createPsrContextMock(); + $context ->expects($this->once()) ->method('createQueue') - ->with('name') - ->will($this->returnValue($expectedQueue)) + ->with('aprefix.afooqueue') + ->willReturn($expectedQueue) ; - $driver = new StompDriver($session, new Config('', '', '', '', '', '')); + $driver = new StompDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); - $queue = $driver->createQueue('name'); + $queue = $driver->createQueue('aFooQueue'); $this->assertSame($expectedQueue, $queue); $this->assertTrue($queue->isDurable()); @@ -63,6 +64,25 @@ public function testShouldCreateAndReturnQueueInstance() ], $queue->getHeaders()); } + public function testShouldCreateAndReturnQueueInstanceWithHardcodedTransportName() + { + $expectedQueue = new StompDestination('aName'); + + $context = $this->createPsrContextMock(); + $context + ->expects($this->once()) + ->method('createQueue') + ->with('aBarQueue') + ->willReturn($expectedQueue) + ; + + $driver = new StompDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); + + $queue = $driver->createQueue('aBarQueue'); + + $this->assertSame($expectedQueue, $queue); + } + public function testShouldConvertTransportMessageToClientMessage() { $transportMessage = new StompMessage(); @@ -75,7 +95,7 @@ public function testShouldConvertTransportMessageToClientMessage() $transportMessage->setReplyTo('theReplyTo'); $transportMessage->setCorrelationId('theCorrelationId'); - $driver = new StompDriver($this->createPsrContextMock(), new Config('', '', '', '', '', '')); + $driver = new StompDriver($this->createPsrContextMock(), $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); $clientMessage = $driver->createClientMessage($transportMessage); @@ -109,7 +129,7 @@ public function testShouldConvertClientMessageToTransportMessage() ->willReturn(new StompMessage()) ; - $driver = new StompDriver($context, new Config('', '', '', '', '', '')); + $driver = new StompDriver($context, $this->createDummyConfig(), $this->createDummyQueueMetaRegistry()); $transportMessage = $driver->createTransportMessage($clientMessage); @@ -161,7 +181,8 @@ public function testShouldSendMessageToRouter() $driver = new StompDriver( $context, - new Config('', '', '', '', '', '') + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); @@ -174,7 +195,8 @@ public function testShouldThrowExceptionIfTopicParameterIsNotSet() { $driver = new StompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', '') + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -213,12 +235,13 @@ public function testShouldSendMessageToProcessor() $driver = new StompDriver( $context, - new Config('', '', '', '', '', '') + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $message = new Message(); $message->setProperty(Config::PARAMETER_PROCESSOR_NAME, 'processor'); - $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'queue'); + $message->setProperty(Config::PARAMETER_PROCESSOR_QUEUE_NAME, 'aFooQueue'); $driver->sendToProcessor($message); } @@ -227,7 +250,8 @@ public function testShouldThrowExceptionIfProcessorNameParameterIsNotSet() { $driver = new StompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', '') + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -240,7 +264,8 @@ public function testShouldThrowExceptionIfProcessorQueueNameParameterIsNotSet() { $driver = new StompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', '') + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $this->expectException(\LogicException::class); @@ -256,7 +281,8 @@ public function testSetupBrokerShouldOnlyLogMessageThatStompDoesNotSupprtBrokerS { $driver = new StompDriver( $this->createPsrContextMock(), - new Config('', '', '', '', '', '') + $this->createDummyConfig(), + $this->createDummyQueueMetaRegistry() ); $logger = $this->createLoggerMock(); @@ -292,4 +318,25 @@ private function createLoggerMock() { return $this->createMock(LoggerInterface::class); } + + /** + * @return QueueMetaRegistry + */ + private function createDummyQueueMetaRegistry() + { + $registry = new QueueMetaRegistry($this->createDummyConfig(), []); + $registry->add('default'); + $registry->add('aFooQueue'); + $registry->add('aBarQueue', 'aBarQueue'); + + return $registry; + } + + /** + * @return Config + */ + private function createDummyConfig() + { + return Config::create('aPrefix'); + } } diff --git a/pkg/stomp/composer.json b/pkg/stomp/composer.json index 0d9c977ca..a72a70388 100644 --- a/pkg/stomp/composer.json +++ b/pkg/stomp/composer.json @@ -22,6 +22,7 @@ "phpunit/phpunit": "~5.4.0", "enqueue/test": "^0.3", "enqueue/enqueue": "^0.3", + "enqueue/null": "^0.3", "symfony/dependency-injection": "^2.8|^3", "symfony/config": "^2.8|^3" },