public function initialize()
 {
     parent::initialize();
     $this->_settings = Configure::read('Gearman') ?: array('servers' => array('127.0.0.1'));
     if (!self::$GearmanWorker) {
         $serversList = implode(',', $this->_settings['servers']);
         $this->log('Creating instance of GearmanWorker with servers: ' . $serversList, 'info', 'gearman');
         self::$GearmanWorker = new GearmanWorker();
         self::$GearmanWorker->addServers($serversList);
         self::$GearmanWorker->addOptions(GEARMAN_WORKER_GRAB_UNIQ);
         self::$GearmanWorker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
     }
 }
 public function testExecute()
 {
     $mock = $this->getMock('GearmanWorker', array('work', 'returnCode', 'wait', 'error'));
     $mock->expects($this->any())->method('work')->will($this->onConsecutiveCalls(false, false, true, true, true));
     $mock->expects($this->any())->method('returnCode')->will($this->onConsecutiveCalls(GEARMAN_IO_WAIT, GEARMAN_NO_JOBS, GEARMAN_NO_ACTIVE_FDS, GEARMAN_SUCCESS));
     $mock->expects($this->any())->method('wait')->will($this->onConsecutiveCalls(false, true, false, false));
     $this->setExpectedException('RuntimeException', 'Worker Error: ');
     GearmanShellTask::$GearmanWorker = $mock;
     $this->GearmanTask->execute();
 }