Ejemplo n.º 1
0
 /**
  * @param Pipeline $pipeline
  * @param string $storeName
  * @param array $storeConfiguration
  * @throws InvalidConfigurationException
  */
 public function buildStore($pipeline, $storeName, $storeConfiguration = [])
 {
     $triggeredByActions = is_array($storeConfiguration) && array_key_exists("triggered_by_actions", $storeConfiguration) ? $storeConfiguration["triggered_by_actions"] : [];
     $triggeredByStores = is_array($storeConfiguration) && array_key_exists("triggered_by_stores", $storeConfiguration) ? $storeConfiguration["triggered_by_stores"] : [];
     $triggeredEvent = is_array($storeConfiguration) && array_key_exists("triggered_event", $storeConfiguration) ? $storeConfiguration["triggered_event"] : null;
     $service = is_array($storeConfiguration) && array_key_exists("service", $storeConfiguration) ? $storeConfiguration["service"] : null;
     $store = $pipeline->hasStore($storeName) ? $pipeline->getStore($storeName) : new Store($storeName);
     $store->setService($service);
     foreach ($triggeredByActions as $triggeredByAction) {
         if (!$pipeline->hasAction($triggeredByAction)) {
             throw new InvalidConfigurationException("Store {$storeName} depends on an unknown action : {$triggeredByAction}");
         }
         $store->addTriggeredByAction($pipeline->getAction($triggeredByAction));
     }
     foreach ($triggeredByStores as $storeName) {
         $triggeredByStore = new Store($storeName);
         if ($pipeline->hasStore($storeName)) {
             $triggeredByStore = $pipeline->getStore($storeName);
         }
         $store->addTriggeredByStore($triggeredByStore);
     }
     // check that store is triggered by an action or another store.
     if ($store->isNeverTriggered()) {
         throw new InvalidConfigurationException("Store {$storeName} is never triggered");
     }
     // add triggered event
     if (isset($triggeredEvent)) {
         $event = $pipeline->hasOutgoingEvent($triggeredEvent) ? $pipeline->getOutgoingEvent($triggeredEvent) : new Event($triggeredEvent);
         $store->setTriggeredEvent($event);
         $pipeline->addOutgoingEvent($event);
     }
     $pipeline->addStore($store);
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function buildValidStore()
 {
     $pipeline = new Pipeline("wizbii_profile");
     $profileAnniversaryAction = new Action("profile_anniversary");
     $pipeline->addAction($profileAnniversaryAction);
     $profileFirstNameUpdatedAction = new Action("profile_first_name_updated");
     $pipeline->addAction($profileFirstNameUpdatedAction);
     $pipelineFactory = new PipelineFactory();
     $pipelineFactory->buildStore($pipeline, "profile_identity_card", ["service" => "wizbii.pipeline.storeprofile_identity_card", "triggered_by_actions" => ["profile_anniversary", "profile_first_name_updated"], "triggered_by_stores" => ["profile_network"], "triggered_event" => "profile_identity_card_updated"]);
     // check the number of created stores
     $this->assertThat(count($pipeline->getStores()), $this->equalTo(1));
     $store = $pipeline->getStore("profile_identity_card");
     // check the actions that are triggering this store
     $this->assertThat(count($store->getTriggeredByActions()), $this->equalTo(2));
     $this->assertThat($store->isTriggeredByAction($profileAnniversaryAction), $this->isTrue());
     $this->assertThat($store->isTriggeredByAction($profileFirstNameUpdatedAction), $this->isTrue());
     // check the stores that are triggering this store
     $this->assertThat(count($store->getTriggeredByStores()), $this->equalTo(1));
     $this->assertThat($store->isTriggeredByStore(new Store("profile_network")), $this->isTrue());
     // check the events that are triggered by this store
     $this->assertThat($store->hasTriggeredEvent(), $this->isTrue());
     $this->assertThat($store->getTriggeredEvent()->getName(), $this->equalTo("profile_identity_card_updated"));
 }
Ejemplo n.º 4
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();
 }