/** * @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")); }
/** * Add actions inside Pipeline based on the configuration provided by Symfony Configuration * @param Pipeline $pipeline * @param string $actionName * @param array $actionConfiguration */ public function buildAction($pipeline, $actionName, $actionConfiguration = []) { $triggeredByEvents = is_array($actionConfiguration) && array_key_exists("triggered_by_events", $actionConfiguration) ? $actionConfiguration["triggered_by_events"] : []; if (empty($triggeredByEvents)) { // default behavior : auto-wiring action to the same event name $triggeredByEvents = [$actionName]; } // create the action and the action creator $action = new Action($actionName); $actionCreator = new ActionCreator($action); foreach ($triggeredByEvents as $triggeredByEvent) { $event = $pipeline->hasIncomingEvent($triggeredByEvent) ? $pipeline->getIncomingEvent($triggeredByEvent) : new Event($triggeredByEvent); $actionCreator->addTriggeredByEvent($event); $pipeline->addIncomingEvent($event); } $pipeline->addAction($action); $pipeline->addActionCreator($actionCreator); }
/** * @test */ public function doesNotHaveAction() { $pipeline = new Pipeline("wizbii_profile"); $pipeline->addAction(new Action("first_name_updated")); $this->assertThat($pipeline->hasAction("new_friend"), $this->isFalse()); }