Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function detect(TokenPoolInterface $tokenPool)
 {
     $fingerprint = $this->fingerprintGenerator->generate($tokenPool);
     $device = $this->deviceCache->get($fingerprint);
     if (false !== $device) {
         return $device;
     }
     $device = new CacheDevice(parent::detect($tokenPool), $fingerprint);
     $this->deviceCache->add($device);
     return $device;
 }
 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');
 }