function it_visit_token(MatcherInterface $matcher, TokenInterface $token, CollatorInterface $collator, MatcherInterface $matcher, MergingStrategyInterface $mergingStrategy, RuleInterface $rule) { $this->beConstructedWith($matcher, $mergingStrategy); $rules = new \ArrayIterator(array($rule->getWrappedObject())); $matcher->match(Argument::exact($token->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn($rules); $mergingStrategy->merge(Argument::exact($rules), Argument::exact($collator->getWrappedObject()))->shouldBeCalledTimes(1); $this->visit($token, $collator)->shouldReturn(VisitorInterface::STATE_SEEKING); }
function it_break_visiting_on_certain_status(VisitorInterface $visitor, TokenPoolInterface $tokenPool, TokenInterface $token, CollatorInterface $collector) { $tokenPool->getIterator()->shouldBeCalledTimes(1)->willReturn(new \ArrayIterator(array($token->getWrappedObject()))); $visitor->accept(Argument::exact($token->getWrappedObject()), Argument::exact($collector->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn(true); $visitor->visit(Argument::exact($token->getWrappedObject()), Argument::exact($collector->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn(VisitorInterface::STATE_FOUND); $this->add($visitor, -255)->shouldReturn(true); $this->visit($tokenPool, $collector)->shouldReturn($this); }
function it_detect_device(TokenPoolInterface $tokenPool, CollatorInterface $collator, VisitorManagerInterface $visitorManager) { $visitorManager->visit(Argument::exact($tokenPool->getWrappedObject()), Argument::exact($collator->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn(VisitorInterface::STATE_SEEKING); $collator->removeAll()->shouldBeCalledTimes(1); $collator->getAll()->shouldBeCalledTimes(1)->willReturn(array()); $this->beConstructedWith($visitorManager, $collator); $this->detect($tokenPool)->shouldReturnAnInstanceOf('DeviceDetectorIO\\DeviceDetector\\Device\\Device'); }
/** * {@inheritdoc} */ public function merge(\Iterator $rules, CollatorInterface $collator) { /** * @var RuleInterface $rule */ foreach ($this->getRulesGroupedByCategoryWithHigherPriority($rules) as $rule) { $collator->merge($rule->getCapabilities()); } }
function it_set_endpoint_capabilities(TokenInterface $token, CollatorInterface $collator) { $collator->get(Argument::exact(Capabilities::IS_CONSOLE))->shouldBeCalledTimes(1)->willReturn(null); $collator->set(Argument::exact(Capabilities::IS_CONSOLE), Argument::exact(false))->shouldBeCalledTimes(1); $collator->get(Argument::exact(Capabilities::IS_MOBILE))->shouldBeCalledTimes(1)->willReturn(null); $collator->set(Argument::exact(Capabilities::IS_DESKTOP), Argument::exact(true))->shouldBeCalledTimes(1); $collator->get(Argument::exact(Capabilities::IS_SMART_TV))->shouldBeCalledTimes(1)->willReturn(false); $collator->set(Argument::exact(Capabilities::IS_SMART_TV), Argument::exact(false))->shouldBeCalledTimes(1); $collator->get(Argument::exact(Capabilities::IS_BOT))->shouldBeCalledTimes(2)->willReturn(false); $collator->set(Argument::exact(Capabilities::IS_BOT), Argument::exact(false))->shouldBeCalledTimes(1); $collator->set(Argument::exact(Capabilities::IS_MOBILE), Argument::exact(false))->shouldBeCalledTimes(1); $this->visit($token, $collator)->shouldReturn(VisitorInterface::STATE_SEEKING); }
/** * @param CollatorInterface $collator * @param string $capability * @return bool */ private function hasEmptyCapability(CollatorInterface $collator, $capability) { $result = $collator->get($capability); return empty($result); }
/** * {@inheritdoc} */ public function detect(TokenPoolInterface $tokenPool) { $this->collator->removeAll(); $this->visitorManager->visit($tokenPool, $this->collator); return new Device($this->collator->getAll()); }