/** * {@inheritdoc} */ public function getDevice($userAgent) { $userAgentTokenizedToken = new UserAgentTokenizedToken(new UserAgentToken($userAgent), new UserAgentTokenizer()); $this->tokenPool->removeAll(); $this->tokenPool->add($userAgentTokenizedToken); return $this->deviceDetector->detect($this->tokenPool); }
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 generate(TokenPoolInterface $tokenPool) { if (!$tokenPool->count()) { throw new \LogicException("Generate fingerprint on empty token pool it's not possible."); } $hashContext = hash_init($this->algorithm); /** @var $token TokenInterface */ foreach ($tokenPool as $token) { hash_update($hashContext, serialize($token)); } return hash_final($hashContext); }
function it_detect_device_from_cache(VisitorManagerInterface $visitorManager, TokenPoolInterface $tokenPool, FingerprintGeneratorInterface $fingerprintGenerator, CollatorInterface $collator, DeviceCacheInterface $deviceCache) { $this->beConstructedWith($visitorManager, $collator); $visitorManager->visit(Argument::exact($tokenPool->getWrappedObject()), Argument::exact($collator->getWrappedObject()))->shouldNotBeCalled(1); $fingerprint = sha1(time()); $fingerprintGenerator->generate(Argument::exact($tokenPool->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn($fingerprint); $this->setFingerprintGenerator($fingerprintGenerator); $deviceCache->get(Argument::exact($fingerprint))->shouldBeCalledTimes(1)->willReturn(new CacheDevice(new Device(array()), $fingerprint)); $deviceCache->add(Argument::any())->shouldNotBeCalled(); $this->setDeviceCache($deviceCache); $collator->removeAll()->shouldNotBeCalled(0); $collator->getAll()->shouldNotBeCalled(0); $this->detect($tokenPool)->shouldReturnAnInstanceOf('DeviceDetectorIO\\DeviceDetector\\Device\\CacheDevice'); }