/** * @test */ public function doesNotHaveProperty() { $action = new Action("profile_updated"); $this->assertThat($action->hasProperty("profile_slug"), $this->isFalse()); $this->assertThat($action->getProperty("profile_slug"), $this->isNull()); $this->assertThat($action->getProperty("profile_slug", "defaultValue"), $this->equalTo("defaultValue")); }
/** * @test */ public function doesNotMatchOnPropertyName() { $actionMatcher = new ActionMatcher(); $actionMatcher->addMatcherOnPropertyName("hello")->addMatcher(new Is("world")); $action = new Action("foo"); $action->addProperty("hello", "john"); $this->assertThat($actionMatcher->matches($action), $this->isFalse()); }
/** * @param Action $action * @return bool */ public function matches($action) { // validates on action name foreach ($this->matchersOnActionName as $matcher) { if (!$matcher->matches($action->getName())) { return false; } } // validates on properties foreach ($this->matchersOnPropertyName as $propertyName => $matcher) { if (!$matcher->matches($action->getProperty($propertyName))) { return false; } } return true; }
/** * @param Action $action * @return bool */ public function dispatch($action) { $this->logger->debug("[ActionDispatcher] Going to dispatch action " . $action->getName() . " whose content is : " . json_encode($action->getProperties())); $success = true; foreach ($this->pipelineProvider->getCurrentPipeline()->getStores() as $store) { if ($store->isTriggeredByAction($action)) { $this->logger->debug(" -> store " . $store->getName() . " is triggered by action " . $action->getName()); try { $this->runStore($store, $action); } catch (StoreNotRunnableException $e) { $this->logger->error("Can't dispatch action '" . $action->getName() . "'. Message was : " . $e->getMessage()); $success = false; } } } return $success; }
/** * Let store decide what to do when the dispatch process failed * @param Action $action * @return EventsGenerator * @throws StoreNotRunnableException */ public function onDispatchFailure($action) { throw new StoreNotRunnableException("Cant' dispatch action " . $action->__toString() . " on store " . $this->getName() . " : It does not match anything"); }