예제 #1
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Create connection
     $certificate = new Certificate($input->getArgument('certificate-file'), $input->getArgument('pass-phrase'));
     $connection = new Connection($certificate, (bool) $input->getOption('sandbox'));
     // Create payload factory
     $payloadFactory = new PayloadFactory();
     // Create notification system
     $notification = new Notification();
     $notification->setPayloadFactory($payloadFactory);
     $notification->setConnection($connection);
     // Create message
     $message = new Message();
     $message->setDeviceToken($input->getArgument('device-token'));
     $apsData = $message->getApsData();
     $apsData->setBody($input->getArgument('message'));
     $apsData->setSound($input->getOption('sound'));
     $apsData->setBadge($input->getOption('badge'));
     // Send message
     try {
         $notification->send($message);
         $output->writeln('<info>Success send push.</info>');
     } catch (\Exception $e) {
         $output->writeln('<error>Error send push notification with message: ' . $e->getMessage() . '.</error>');
     }
 }
예제 #2
0
 /**
  * Test call complete event
  */
 public function testSendMessageEventComplete()
 {
     if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) {
         $this->markTestSkipped('Not found package "symfony/event-dispatcher".');
     }
     $message = self::createMessage('Foo');
     $this->connection->expects($this->any())->method('is')->will($this->returnValue(true));
     $this->connection->expects($this->once())->method('isReadyRead')->will($this->returnValue(false));
     $this->connection->expects($this->once())->method('write')->will($this->returnCallback(function ($a) {
         return mb_strlen($a);
     }));
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcher', array('dispatch'));
     $eventDispatcher->expects($this->once())->method('dispatch')->with(NotificationEvents::SEND_MESSAGE_COMPLETE, $this->isInstanceOf('Apple\\ApnPush\\Notification\\Events\\SendMessageCompleteEvent'));
     $notification = new Notification();
     $notification->setPayloadFactory(new PayloadFactory());
     $notification->setConnection($this->connection);
     $notification->setEventDispatcher($eventDispatcher);
     $notification->send($message);
 }