/**
  * {@inheritdoc}
  */
 public function process()
 {
     $subscriptions = $this->repository->findScheduled();
     $this->dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_BATCH_START, new GenericEvent($subscriptions));
     foreach ($subscriptions as $subscription) {
         try {
             $this->dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_INITIALIZE, new SubscriptionEvent($subscription));
             $this->processSubscription($subscription);
         } catch (\Exception $e) {
             $this->dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_ERROR, new SubscriptionEvent($subscription, array('exception' => $e)));
             continue;
         }
         $this->dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_SUCCESS, new SubscriptionEvent($subscription));
         $this->manager->flush();
         $this->dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_COMPLETED, new SubscriptionEvent($subscription));
     }
     $this->dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_BATCH_END, new GenericEvent($subscriptions));
 }
 public function it_should_persist_entity(SubscriptionRepositoryInterface $repository, ObjectManager $manager, SubscriptionInterface $subscription)
 {
     $repository->findScheduled()->willReturn(array($subscription));
     $manager->flush()->shouldBeCalled();
     $this->process();
 }