public function testNewBackgroundTask()
 {
     $mock = $this->getMock('GearmanClient', array('doBackground', 'returnCode'));
     $mock->expects($this->any())->method('returnCode')->will($this->returnValue(GEARMAN_SUCCESS));
     $taskName = 'reverse';
     $data = "foobar";
     $mock->expects($this->any())->method('doBackground')->with($taskName, $data, null)->will($this->returnValue(''));
     GearmanComponent::$GearmanClient = $mock;
     $this->GearmanComponent->newBackgroundTask($taskName, $data);
 }
 /**
  * Constructs the Gearman Client component. Settings are fetched from array, Configure
  * or defaults to localhost. Throws Exception if the Gearmand (the server) is not responding
  * @throws GearmanException	if the gearman client can't connect to the gearman server, an exception is thrown
  * @param	ComponentCollection	$collection
  * @param	array				$settings	Settings to pass to the gearman client
  */
 public function __construct(ComponentCollection $collection, $settings = array())
 {
     if (!$settings) {
         $settings = Configure::read('Gearman');
     }
     if (!$settings) {
         $settings = array('servers' => array('127.0.0.1'));
     }
     if (!self::$GearmanClient) {
         self::$GearmanClient = new GearmanClient();
         self::$GearmanClient->addServers(implode(',', $settings['servers']));
     }
     parent::__construct($collection, $settings);
 }