public function testServiceNotListening()
 {
     $this->logger->expects($this->once())->method('info');
     $this->logger->expects($this->once())->method('warning');
     $this->connection->expects($this->any())->method('isServiceListening')->will($this->returnValue(false));
     $listener = new PheanstalkLogListener();
     $listener->setLogger($this->logger);
     $listener->onCommand(new CommandEvent($this->pheanstalk, []), CommandEvent::PEEK_READY);
 }
 public function register(Container $app)
 {
     $app['pheanstalks.options.initializer'] = $app->protect(function () use($app) {
         static $initialized = false;
         if ($initialized) {
             return;
         }
         $initialized = true;
         if (!isset($app['pheanstalks.options'])) {
             $app['pheanstalks.options'] = ['default' => isset($app['pheanstalk.options']) ? $app['pheanstalk.options'] : []];
         }
         $app['pheanstalks.options'] = array_map(function ($options) use($app) {
             return array_replace($app['pheanstalk.default_options'], $options);
         }, $app['pheanstalks.options']);
         if (!isset($app['pheanstalks.default'])) {
             $app['pheanstalks.default'] = array_keys(array_slice($app['pheanstalks.options'], 0, 1))[0];
         }
     });
     $app['pheanstalk.listener.log'] = function () use($app) {
         $listener = new PheanstalkLogListener();
         if ($app['logger']) {
             $listener->setLogger($app['logger']);
         }
         return $listener;
     };
     $app['pheanstalk.proxy.factory'] = $app->protect(function ($name, PheanstalkInterface $pheanstalk) use($app) {
         $proxy = new PheanstalkProxy();
         $proxy->setName($name);
         $proxy->setPheanstalk($pheanstalk);
         $proxy->setDispatcher($app['dispatcher']);
         return $proxy;
     });
     $app['pheanstalks'] = function (Container $app) {
         $app['pheanstalks.options.initializer']();
         $locator = new PheanstalkLocator();
         foreach ($app['pheanstalks.options'] as $name => $options) {
             $pheanstalk = new Pheanstalk($options['server'], $options['port'], $options['timeout']);
             $locator->addPheanstalk($name, $app['pheanstalk.proxy.factory']($name, $pheanstalk), $app['pheanstalks.default'] === $name);
         }
         return $locator;
     };
     $app['pheanstalk.commands'] = $app->protect(function () use($app) {
         $locator = $app['pheanstalks'];
         return [new DeleteJobCommand($locator), new FlushTubeCommand($locator), new KickCommand($locator), new KickJobCommand($locator), new ListTubeCommand($locator), new NextReadyCommand($locator), new PauseTubeCommand($locator), new PeekCommand($locator), new PeekTubeCommand($locator), new PutCommand($locator), new StatsCommand($locator), new StatsJobCommand($locator), new StatsTubeCommand($locator)];
     });
     // shortcuts for the "first" pheanstalk
     $app['pheanstalk'] = function (Container $app) {
         $pheanstalks = $app['pheanstalks'];
         return $pheanstalks->getPheanstalk($app['pheanstalks.default']);
     };
     $app['pheanstalk.default_options'] = ['server' => '127.0.0.1', 'port' => PheanstalkInterface::DEFAULT_PORT, 'timeout' => PheanstalkInterface::DEFAULT_TTR];
     if (isset($app['console'])) {
         $app['console'] = $app->extend('console', function (ConsoleApplication $console, Container $app) {
             $commands = $app['pheanstalk.commands']();
             foreach ($commands as $command) {
                 $console->add($command);
             }
             return $console;
         });
     }
 }