public function setUp()
 {
     $this->dispatcher = new EventDispatcher('UTF-8');
     $listener = new RequestListener($this->dispatcher);
     $this->dispatcher->addListener(KernelEvents::REQUEST, [$listener, 'onKernelRequest']);
     $this->dispatcher->addListener(QPushEvents::Notification('ironmq-test'), [$this, 'IronMqOnNotificationReceived']);
     $this->dispatcher->addListener(QPushEvents::Notification('aws-test'), [$this, 'AwsOnNotificationReceived']);
     $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
 }
 /**
  * Handles Notifications sent from AWS SNS
  *
  * @param GetResponseEvent $event The Kernel Request's GetResponseEvent
  */
 private function handleSnsNotifications(GetResponseEvent $event)
 {
     $notification = json_decode((string) $event->getRequest()->getContent(), true);
     $type = $event->getRequest()->headers->get('x-amz-sns-message-type');
     $metadata = ['Type' => $notification['Type'], 'TopicArn' => $notification['TopicArn'], 'Timestamp' => $notification['Timestamp']];
     if ($type === 'Notification') {
         // We put the queue name in the Subject field
         $queue = $notification['Subject'];
         $metadata['Subject'] = $queue;
         $notification = new Notification($notification['MessageId'], $notification['Message'], $metadata);
         $this->dispatcher->dispatch(Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_MESSAGE, $notification));
         return "SNS Message Notification Received.";
     }
     // For subscription notifications, we need to parse the Queue from
     // the Topic ARN
     $arnParts = explode(':', $notification['TopicArn']);
     $last = end($arnParts);
     $queue = str_replace('qpush_', '', $last);
     // Get the token for the Subscription Confirmation
     $metadata['Token'] = $notification['Token'];
     $notification = new Notification($notification['MessageId'], $notification['Message'], $metadata);
     $this->dispatcher->dispatch(Events::Notification($queue), new NotificationEvent($queue, NotificationEvent::TYPE_SUBSCRIPTION, $notification));
     return "SNS Subscription Confirmation Received.";
 }
Example #3
0
 public function testNotificationEvent()
 {
     $event = Events::Notification('test');
     $this->assertEquals(sprintf('%s.%s', 'test', Events::ON_NOTIFICATION), $event);
 }