public function register(Application $app)
 {
     $app->register(new InjectorServiceProvider(['G\\Gearman\\Client' => 'gearmanClient', 'G\\Gearman\\Tasks' => 'gearmanTasks']));
     $app['gearmanClient'] = function () use($app) {
         $client = new Client($this->client);
         $client->onSuccess(function ($response) {
             return $response;
         });
         return $client;
     };
     $app['gearmanTasks'] = function () use($app) {
         return new Tasks($this->client);
     };
 }
Esempio n. 2
0
 public function test_simple_client()
 {
     foreach ($this->actions as $action) {
         $callCount = 0;
         $gearmanClient = $this->getMock('GearmanClient');
         $gearmanClient->expects($this->any())->method('returnCode')->willReturn(0);
         $gearmanClient->expects($this->exactly(1))->method($action)->willReturnCallback(function ($name, $workload, $unique) {
             $this->assertEquals(json_encode('HELLO'), $workload);
             $this->assertEquals('uid', $unique);
             $this->assertEquals('hello', $name);
             $job = $this->getMock('\\GearmanJob');
             $job->expects($this->any())->method('workload')->willReturn(json_encode("myWorkload"));
             return "RETURN";
         });
         $client = new Client($gearmanClient);
         $client->onSuccess(function ($response) use(&$callCount) {
             $callCount++;
             $this->assertEquals('RETURN', $response);
         });
         $client->{$action}('hello', "HELLO", 'uid');
         $this->assertEquals(1, $callCount);
     }
 }