/** * Register browscap. * * @author Morten Rugaard <*****@*****.**> * * @return void */ protected function registerBrowscap() { $this->app->singleton(Browscap::class, function ($app) { $browscap = new Browscap(); // Cache for 90 days $browscap->setCache(new BrowscapCache(new CacheFile([CacheFile::DIR => storage_path('framework/browscap')])), 7776000); // Automatically check for updates $browscap->update(); return $browscap; }); }
/** * @expectedException \BrowscapPHP\Exception\FetcherException * @expectedExceptionMessage Could not fetch HTTP resource "http://browscap.org/stream?q=PHP_BrowscapINI": */ public function testUpdate() { if (class_exists('\\Browscap\\Browscap')) { self::markTestSkipped('if the \\Browscap\\Browscap class is available the browscap.ini file is not updated from a remote ' . 'location'); } $logger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false); $this->object->setLogger($logger); $loader = $this->getMock('\\BrowscapPHP\\Helper\\IniLoader', array('setRemoteFilename', 'setOptions', 'setLogger', 'load'), array(), '', false); $loader->expects(self::once())->method('setRemoteFilename')->will(self::returnSelf()); $loader->expects(self::once())->method('setOptions')->will(self::returnSelf()); $loader->expects(self::once())->method('setLogger')->will(self::returnSelf()); $loader->expects(self::once())->method('load')->will(self::returnValue(false)); $this->object->setLoader($loader); $this->object->setLoader($loader); $map = array(array('browscap.time', false, null, null), array('browscap.version', false, null, null)); $cache = $this->getMock('\\WurflCache\\Adapter\\Memory', array('getItem'), array(), '', false); $cache->expects(self::any())->method('getItem')->will(self::returnValueMap($map)); $this->object->setCache($cache); $this->object->update(); }
/** * */ public function testUpdateOk() { if (class_exists('\\Browscap\\Browscap')) { self::markTestSkipped('if the \\Browscap\\Browscap class is available the browscap.ini file is not updated from a remote ' . 'location'); } $logger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false); $this->object->setLogger($logger); $internalLoader = $this->getMock('\\FileLoader\\Loader', array('getUri'), array(), '', false); $internalLoader->expects(self::never())->method('getUri')->will(self::returnValue('http://browscap.org/stream?q=PHP_BrowscapINI')); $content = ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Browscap Version [GJK_Browscap_Version] Version=5031 Released=Mon, 30 Jun 2014 17:55:58 +0200 Format=ASP Type= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DefaultProperties [DefaultProperties] Comment=DefaultProperties Browser=DefaultProperties Version=0.0 MajorVer=0 MinorVer=0 Platform=unknown Platform_Version=unknown Alpha=false Beta=false Win16=false Win32=false Win64=false Frames=false IFrames=false Tables=false Cookies=false BackgroundSounds=false JavaScript=false VBScript=false JavaApplets=false ActiveXControls=false isMobileDevice=false isTablet=false isSyndicationReader=false Crawler=false CssVersion=0 AolVersion=0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ask [Ask] Parent=DefaultProperties Comment=Ask Browser=Ask Frames=1 IFrames=1 Tables=1 Crawler=1 Version=0.0 MajorVer=0 MinorVer=0 Platform=unknown Platform_Version=unknown Alpha= Beta= Win16= Win32= Win64= Cookies= BackgroundSounds= JavaScript= VBScript= JavaApplets= ActiveXControls= isMobileDevice= isTablet= isSyndicationReader= CssVersion=0 AolVersion=0 [Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)] Parent=Ask Browser=Teoma Comment=Ask Version=0.0 MajorVer=0 MinorVer=0 Platform=unknown Platform_Version=unknown Alpha= Beta= Win16= Win32= Win64= Frames=1 IFrames=1 Tables=1 Cookies= BackgroundSounds= JavaScript= VBScript= JavaApplets= ActiveXControls= isMobileDevice= isTablet= isSyndicationReader= Crawler=1 CssVersion=0 AolVersion=0 '; $loader = $this->getMock('\\BrowscapPHP\\Helper\\IniLoader', array('setRemoteFilename', 'setOptions', 'setLogger', 'load', 'getLoader'), array(), '', false); $loader->expects(self::once())->method('setRemoteFilename')->will(self::returnSelf()); $loader->expects(self::once())->method('setOptions')->will(self::returnSelf()); $loader->expects(self::once())->method('setLogger')->will(self::returnSelf()); $loader->expects(self::once())->method('load')->will(self::returnValue($content)); $loader->expects(self::never())->method('getLoader')->will(self::returnValue($internalLoader)); $this->object->setLoader($loader); $map = array(array('browscap.time', false, null, null), array('browscap.version', false, null, null)); $cache = $this->getMock('\\BrowscapPHP\\Cache\\BrowscapCache', array('getItem', 'setItem'), array(), '', false); $cache->expects(self::once())->method('getItem')->will(self::returnValueMap($map)); $cache->expects(self::exactly(4353))->method('setItem')->will(self::returnValue(false)); $this->object->setCache($cache); self::assertNull($this->object->update()); }