/** * Dummy test for verifying that TaskPublisher works with configured brokers. */ public function testPublish() { $client = self::createClient(); $publisher = $client->getContainer()->get('ongr_task_messenger.task_publisher.foo_publisher'); $task = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $task->setName('task_foo'); $task->setCommand('command_foo'); $publisher->publish($task); $redis = new Predis\Client(); $this->verifyMessage($redis->get('test'), ['taskType' => 'task_foo', 'commandName' => 'command_foo -e test']); }
/** * Test if publisher is added correctly. */ public function testTaskPublisherConstructor() { $task = new SyncTask(SyncTask::SYNC_TASK_BROADCAST); $task->setName('ongr:sync:download'); $task->setCommand('ongr:sync:download'); $amqpPublisher = $this->getAMQPPublisher(); $amqpPublisher->expects($this->once())->method('publish')->with($task); /** @var TaskPublisher $taskPublisher */ $taskPublisher = $this->getMockBuilder('ONGR\\TaskMessengerBundle\\Service\\TaskPublisher')->setConstructorArgs([$amqpPublisher])->setMethods(null)->getMock(); $taskPublisher->publish($task); }
/** * Test if AMQPPublisher works as expected. */ public function testPublish() { $container = $this->getContainer(); $publisher = $container->get('ongr_task_messenger.publisher.default.amqp'); $logger = new NullLogger(); $publisher->setLogger($logger); $task = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $task->setName('task_foo'); $task->setCommand('command_foo'); $publisher->publish($task); $this->channel->wait(); }
/** * Test if Redis works as expected. */ public function testLogging() { $container = $this->getContainer(); $publisher = $container->get('ongr_task_messenger.publisher.foo_publisher.custom'); $logger = new NullLogger(); $publisher->setLogger($logger); $task = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $task->setName('task_foo'); $task->setCommand('command_foo'); $publisher->publish($task); $redis = new Predis\Client(); $this->verifyMessage($redis->get('test')); }
/** * Test if BeanstalkdPublisher works as expected. */ public function testLogging() { $container = $this->getContainer(); $publisher = $container->get('ongr_task_messenger.publisher.default.beanstalkd'); $logger = new NullLogger(); $publisher->setLogger($logger); $task = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $task->setName('task_foo'); $task->setCommand('command_foo'); $publisher->publish($task); $pheanstalk = new Pheanstalk($container->getParameter('ongr_task_messenger.publisher.default.beanstalkd.host'), $container->getParameter('ongr_task_messenger.publisher.default.beanstalkd.port')); $job = $pheanstalk->watch('general')->reserve(); $jobData = json_decode($job->getData(), true); $this->assertEquals($jobData['task'], 'ongr.task.task_foo'); $this->assertEquals($jobData['args'][0], 'command_foo -e test'); }
/** * Test to check if logging is working as expected. */ public function testLogging() { $channelMock = $this->getMockBuilder('\\PhpAmqpLib\\Channel\\AMQPChannel')->disableOriginalConstructor()->getMock(); $amqpConnection = $this->getMockBuilder('PhpAmqpLib\\Connection\\AMQPConnection')->disableOriginalConstructor()->getMock(); $amqpConnection->expects($this->once())->method('channel')->willReturn($channelMock); $connectionFactory = $this->getMockBuilder('ONGR\\TaskMessengerBundle\\Publishers\\ConnectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $connectionFactory->expects($this->once())->method('create')->willReturn($amqpConnection); $environment = 'dummy-environment'; $publisher = new AMQPPublisher($connectionFactory, $environment); $task = new SyncTask(SyncTask::SYNC_TASK_BROADCAST); $task->setName('ongr:sync:download'); $task->setCommand('ongr:sync:download'); $publisher->setLogger($this->getLoggerMock('amqp publish', ['ongr:sync:download', 'fanout', ''])); $publisher->publish($task); }