/** * @group unit */ public function testFailIsValid() { $isValid = CallbackStrategy::isValid(new \stdClass()); $this->assertFalse($isValid); $isValid = CallbackStrategy::isValid('array_pop_pop_pop_pop_pop_pop'); $this->assertFalse($isValid); }
/** * @param mixed|Closure|String|StrategyInterface $strategyName * @return \Elastica\Connection\Strategy\StrategyInterface * @throws \Elastica\Exception\InvalidException */ public static function create($strategyName) { $strategy = null; if ($strategyName instanceof StrategyInterface) { $strategy = $strategyName; } else { if (CallbackStrategy::isValid($strategyName)) { $strategy = new CallbackStrategy($strategyName); /* } else if (is_string($strategyName) && class_exists($strategyName)) { $strategy = new $strategyName(); */ } else { if (is_string($strategyName)) { $pathToStrategy = '\\Elastica\\Connection\\Strategy\\' . $strategyName; if (class_exists($pathToStrategy)) { $strategy = new $pathToStrategy(); } } } } if (!$strategy instanceof StrategyInterface) { throw new InvalidException('Can\'t load strategy class'); } return $strategy; }
/** * @param mixed|callable|string|StrategyInterface $strategyName * * @throws \Elastica\Exception\InvalidException * * @return \Elastica\Connection\Strategy\StrategyInterface */ public static function create($strategyName) { if ($strategyName instanceof StrategyInterface) { return $strategyName; } if (CallbackStrategy::isValid($strategyName)) { return new CallbackStrategy($strategyName); } if (is_string($strategyName)) { $requiredInterface = '\\Elastica\\Connection\\Strategy\\StrategyInterface'; $predefinedStrategy = '\\Elastica\\Connection\\Strategy\\' . $strategyName; if (class_exists($predefinedStrategy) && class_implements($predefinedStrategy, $requiredInterface)) { return new $predefinedStrategy(); } if (class_exists($strategyName) && class_implements($strategyName, $requiredInterface)) { return new $strategyName(); } } throw new InvalidException('Can\'t create strategy instance by given argument'); }
public function testFailIsValid() { $callback = new \stdClass(); $isValid = CallbackStrategy::isValid($callback); $this->assertFalse($isValid); }