Example #1
0
 /**
  * @test
  */
 public function doesNotDependOnStore()
 {
     $store = new Store("identity_card");
     $aSecondStore = new Store("profile_network");
     $aThirdStore = new Store("profile_friends");
     $store->addTriggeredByStore($aSecondStore);
     // aSecondStore => store but aThirdStore is not wired
     $this->assertThat($store->dependsOnStore($aThirdStore), $this->isFalse());
 }
Example #2
0
 /**
  * @test
  */
 public function storeIsNotRunnable()
 {
     // init container
     $container = new Container();
     $this->actionDispatcher->container = $container;
     // init pipeline
     $action = new Action("profile_created");
     $store = new Store("profile_network");
     $store->setService("pipeline.store.profile.dashboard");
     $store->addTriggeredByAction($action);
     $pipeline = new Pipeline();
     $pipeline->addStore($store);
     $this->actionDispatcher->pipelineProvider->setPipeline($pipeline);
     // dispatch action
     $returnedValue = $this->actionDispatcher->dispatch($action);
     $this->assertThat($returnedValue, $this->isFalse());
 }
Example #3
0
 /**
  * @test
  * @expectedException \Wizbii\PipelineBundle\Exception\CircularPipelineException
  */
 public function circularReferencesThrowsException()
 {
     $pipeline = new Pipeline("wizbii_profile");
     $profileIdentityCardStore = new Store("profile_identity_card");
     $profileNetworkStore = new Store("profile_network");
     $profileThanxStore = new Store("profile_thanx");
     $profileIdentityCardStore->addTriggeredByStore($profileNetworkStore);
     $profileNetworkStore->addTriggeredByStore($profileThanxStore);
     $profileThanxStore->addTriggeredByStore($profileIdentityCardStore);
     $pipeline->addStore($profileIdentityCardStore);
     $pipeline->addStore($profileNetworkStore);
     $pipeline->addStore($profileThanxStore);
     $pipeline->checkForCircularReferences();
 }
Example #4
0
 /**
  * @param Store $store
  */
 public function addStore($store)
 {
     $this->stores[$store->getName()] = $store;
 }
Example #5
0
 /**
  * @param Store $store
  * @param Action $action
  * @throws StoreNotRunnableException
  */
 protected function runStore($store, $action)
 {
     $this->logger->debug("    -> going to run store " . $store->getName());
     $runner = $this->container->get($store->getService(), ContainerInterface::NULL_ON_INVALID_REFERENCE);
     if (!isset($runner)) {
         throw new StoreNotRunnableException("Store " . $store->getName() . " is not runnable : service with name '" . $store->getService() . "' does not exist'");
     }
     if (!$runner instanceof RunnableStore) {
         throw new StoreNotRunnableException("Service '" . $store->getService() . '\' does not implement \\Wizbii\\PipelineBundle\\Runnable\\Store interface');
     }
     try {
         $start = microtime(true);
         $eventsGenerator = $runner->run($action);
         $stop = microtime(true);
         $this->logger->info("[" . getmypid() . "]" . " Service " . $store->getService() . " tooked " . ($stop - $start) . " to process " . $action->getName());
         if ($store->hasTriggeredEvent() && isset($eventsGenerator)) {
             foreach ($eventsGenerator->produce() as $dataBag) {
                 $this->eventDispatcher->dispatch($store->getTriggeredEvent()->getName(), $dataBag->all());
             }
         }
     } catch (\Exception $e) {
         $this->logger->warning("Store " . $store->getName() . " has thrown an exception. Message was : " . $e->getMessage() . ". It occurs at " . $e->getFile() . ":" . $e->getLine());
     }
     // run next stores
     foreach ($this->pipelineProvider->getCurrentPipeline()->getStores() as $anotherStore) {
         if ($anotherStore->isTriggeredByStore($store)) {
             $this->runStore($anotherStore, $action);
         }
     }
 }