/**
  * Envia a notificação para dispositivos Android
  *
  * @param Device[] $devices
  *        	Dispositivos
  * @param Message $message
  *        	Notificação
  * @param NotificationResult $notificationResult
  *        	Resultado do envio da notificação
  * @param PushManager $pushManager
  *        	Gerenciador de push
  */
 public static function send($devices, $message, $notificationResult, $pushManager)
 {
     if (iterator_count($devices->getIterator()) > 0) {
         try {
             $gcmAdapter = new GcmAdapter(array('apiKey' => ANDROID_API_KEY));
             // envia as notificações
             $push = new Push($gcmAdapter, $devices, $message);
             $pushManager->add($push);
             $pushManager->push();
             // obtém a resposta do envio do envio
             $response = $gcmAdapter->getResponse();
             // dispositivo que não receberam as notificações e motivo
             $failureResults = $response->getResult(Response::RESULT_ERROR);
             $failureDevices = AndroidPushController::handleFailureResult($failureResults);
             // dispositivo que tiveram seus identificadores modificados
             $canonicalResults = $response->getResult(Response::RESULT_CANONICAL);
             AndroidPushController::handleCanonicalResult($canonicalResults);
             $notificationResult->addDevicesNotNotified($failureDevices);
         } catch (\Exception $e) {
             global $log;
             $log->Error($e);
             $notificationResult->setAndroidFailed(true);
             $notificationResult->setAndroidFailureReason($e->getMessage());
         }
     }
 }
Ejemplo n.º 2
0
 public function testGetOpenedClient()
 {
     $this->if($this->mockGenerator()->orphanize('__construct'))->and($this->mockClass('\\Sly\\NotificationPusher\\Adapter\\Gcm', '\\Mock'))->and($object = new \Mock\Gcm())->and($this->mockGenerator()->orphanize('__construct'))->and($this->mockGenerator()->orphanize('open'))->and($this->mockClass('\\ZendService\\Google\\Gcm\\Client', '\\Mock\\ZendService'))->and($serviceClient = new \Mock\ZendService\Client())->and($object->getMockController()->getParameters = array())->exception(function () use($object) {
         $object->getOpenedClient(new BaseServiceClient());
     })->isInstanceOf('\\ZendService\\Google\\Exception\\InvalidArgumentException')->message->contains('The api key must be a string and not empty')->when($object = new TestedModel(array('apiKey' => 'test')))->and($object->getOpenedClient($serviceClient));
 }