Skip to content

Commit

Permalink
update to latest deps (#85)
Browse files Browse the repository at this point in the history
* update to latest deps

* switch zsxsoft UA

* wurfl update to 1.7

* fixing wurfl tests

* improve version

* change deps
  • Loading branch information
ThaDafinser committed Apr 26, 2016
1 parent 6fa8fc6 commit 9617f86
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 309 deletions.
1 change: 0 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ $config->finder($finder);
$config->level(Symfony\CS\FixerInterface::PSR2_LEVEL);
$config->fixers([
//symfony
'concat_without_spaces',
'double_arrow_multiline_whitespaces',
'duplicate_semicolon',
'empty_return',
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ But they require (always) a working internet connection.
Here is a comparison matrix, with many analyzed UserAgent strings, to help you device which provider fits your needs.
Every provider has it's strengh and weakness, so it will depend on your need, which one you should use.

[Go to the matrix](https://github.com/ThaDafinser/UserAgentParserMatrix)
[Go to the comparison](http://thadafinser.github.io/UserAgentParserComparison/)

### Overview

Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"UserAgent",
"UserAgentParser",

"Sniffing",
"Parser",
"Detection",

Expand Down Expand Up @@ -106,17 +107,15 @@
"browscap/browscap-php": "dev-master",
"donatj/phpuseragentparser": "^0.5.0",
"jenssegers/agent": "^2.3",
"mobiledetect/mobiledetectlib": ">2.7.5,<3",
"mobiledetect/mobiledetectlib": "^2.7.5",
"piwik/device-detector": "^3.6",
"sinergi/browser-detector": "^6.0",
"ua-parser/uap-php": ">=3.4.3,<4.0",
"whichbrowser/parser": ">=2.0.10,<3.0",
"ua-parser/uap-php": "^3.4.3",
"whichbrowser/parser": "^2.0.10",
"woothee/woothee": "^1.2",

"mimmi20/wurfl": "^1.6.4",
"mimmi20/wurfl-storage": "^1.0.3",
"mimmi20/wurfl-virtual-capability": "^1.6.4",
"mimmi20/wurfl": "^1.7.1.1",

"zsxsoft/php-useragent": ">=1.1,<1.2"
"zsxsoft/php-useragent": ">=1.2,<1.4"
}
}
8 changes: 4 additions & 4 deletions src/Model/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function setComplete($complete)
{
// check if the version has only 0 -> so no real result
// maybe move this out to the Providers itself?
$left = preg_replace('/[0.]/', '', $complete);
$left = preg_replace('/[0._]/', '', $complete);
if ($left === '') {
$complete = null;
}
Expand Down Expand Up @@ -240,9 +240,9 @@ private function getCompleteParts($complete)
];

// only digits
preg_match("/\d+(?:\.*\d*)*/", $complete, $result);
preg_match("/\d+(?:[._]*\d*)*/", $complete, $result);
if (count($result) > 0) {
$parts = explode('.', $result[0]);
$parts = preg_split("/[._]/", $result[0]);

if (isset($parts[0]) && $parts[0] != '') {
$versionParts['major'] = (int) $parts[0];
Expand All @@ -256,7 +256,7 @@ private function getCompleteParts($complete)
}

// grab alias
$result = preg_split("/\d+(?:\.*\d*)*/", $complete);
$result = preg_split("/\d+(?:[._]*\d*)*/", $complete);
foreach ($result as $row) {
$row = trim($row);

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Provider/Http/DeviceAtlasComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testRealResultDevice()
'minor' => 0,
'patch' => null,

'alias' => '_',
'alias' => null,

'complete' => '5_0',
],
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/Provider/JenssegersAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ public function testRealResultDevice()
'name' => 'iOS',
'version' => [
'major' => 5,
'minor' => null,
'minor' => 0,
'patch' => null,

'alias' => '_',
'alias' => null,

'complete' => '5_0',
],
Expand Down
71 changes: 53 additions & 18 deletions tests/integration/Provider/WurflTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
namespace UserAgentParserTest\Integration\Provider;

use UserAgentParser\Provider\Wurfl;
use Wurfl\Handlers;
use Wurfl\Handlers\Chain\UserAgentHandlerChain;
use Wurfl\Handlers\Normalizer\Generic;
use Wurfl\Handlers\Normalizer\UserAgentNormalizer;

/**
*
*
* @author Martin Keckeis <[email protected]>
* @license MIT
*
*
* @coversNothing
*/
class WurflTest extends AbstractProviderTestCase
Expand All @@ -29,7 +32,39 @@ private function getWurfl()
// cache
$cacheStorage = \Wurfl\Storage\Factory::create($wurflConfig->cache);

return new \Wurfl\Manager($wurflConfig, $persistenceStorage, $cacheStorage);
// chain
$genericNormalizers = new UserAgentNormalizer([
new Generic\UCWEB(),
new Generic\UPLink(),
new Generic\SerialNumbers(),
new Generic\LocaleRemover(),
new Generic\CFNetwork(),
new Generic\BlackBerry(),
new Generic\Android(),
new Generic\TransferEncoding(),
]);

$userAgentHandlerChain = new UserAgentHandlerChain();
$userAgentHandlerChain->addUserAgentHandler(new Handlers\XboxHandler($genericNormalizers));
$userAgentHandlerChain->addUserAgentHandler(new Handlers\BotCrawlerTranscoderHandler($genericNormalizers));
// $userAgentHandlerChain->addUserAgentHandler(new Handlers\CatchAllMozillaHandler($genericNormalizers));
$userAgentHandlerChain->addUserAgentHandler(new Handlers\CatchAllRisHandler($genericNormalizers));

$userAgentHandlerChain->setLogger($wurflConfig->getLogger());
foreach ($userAgentHandlerChain->getHandlers() as $handler) {
/* @var $handler \Wurfl\Handlers\AbstractHandler */
$handler->setLogger($wurflConfig->getLogger())
->setPersistenceProvider($persistenceStorage);
}

$manager = new \Wurfl\Manager($wurflConfig, $persistenceStorage, $cacheStorage);

$reflection = new \ReflectionClass($manager);
$property = $reflection->getProperty('userAgentHandlerChain');
$property->setAccessible(true);
$property->setValue($manager, $userAgentHandlerChain);

return $manager;
}

public function testMethodParse()
Expand Down Expand Up @@ -59,7 +94,7 @@ public function testMethodsResult()
$parser = $provider->getParser();

/* @var $result \Wurfl\CustomDevice */
$result = $parser->getDeviceForUserAgent('A real user agent...');
$result = $parser->getDeviceForUserAgent('A real user agent...maybe we need the complete file?');

$this->assertInstanceOf('Wurfl\CustomDevice', $result);

Expand Down Expand Up @@ -155,13 +190,13 @@ public function testRealResultBot()
$this->assertArrayHasKey('all', $rawResult);

$virtual = $rawResult['virtual'];
$this->assertGreaterThan(21, $virtual);
$this->assertCount(22, $virtual);
$this->assertArrayHasKey('is_robot', $virtual);
$this->assertArrayHasKey('is_smartphone', $virtual);
$this->assertArrayHasKey('complete_device_name', $virtual);

$all = $rawResult['all'];
$this->assertCount(530, $all);
$this->assertCount(511, $all);
$this->assertArrayHasKey('is_wireless_device', $all);
$this->assertArrayHasKey('table_support', $all);
$this->assertArrayHasKey('resolution_width', $all);
Expand All @@ -171,18 +206,18 @@ public function testRealResultDevice()
{
$provider = new Wurfl($this->getWurfl());

$result = $provider->parse('Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538a Safari/419.3');
$result = $provider->parse('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)');
$this->assertEquals([
'browser' => [
'name' => 'Mobile Safari',
'name' => 'IE',
'version' => [
'major' => 3,
'major' => 9,
'minor' => 0,
'patch' => null,

'alias' => null,

'complete' => '3.0',
'complete' => '9.0',
],
],
'renderingEngine' => [
Expand All @@ -198,24 +233,24 @@ public function testRealResultDevice()
],
],
'operatingSystem' => [
'name' => 'iOS',
'name' => 'Windows',
'version' => [
'major' => null,
'major' => 7,
'minor' => null,
'patch' => null,

'alias' => null,

'complete' => null,
'complete' => '7',
],
],
'device' => [
'model' => 'iPhone',
'brand' => 'Apple',
'type' => 'Feature Phone',
'model' => 'Xbox 360',
'brand' => 'Microsoft',
'type' => 'Smart-TV',

'isMobile' => true,
'isTouch' => true,
'isMobile' => null,
'isTouch' => null,
],
'bot' => [
'isBot' => null,
Expand Down
74 changes: 37 additions & 37 deletions tests/integration/Provider/ZsxsoftTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ public function testRealResultDevice()
{
$provider = new Zsxsoft();

$result = $provider->parse('Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3');
$result = $provider->parse('Mozilla/5.0 (Linux; Android 5.0.1; Nexus 7 Build/LRX22C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.59 Safari/537.36 OPR/26.0.1656.87080');
$this->assertEquals([
'browser' => [
'name' => 'Safari',
'name' => 'Opera',
'version' => [
'major' => 5,
'minor' => 1,
'patch' => null,
'major' => 26,
'minor' => 0,
'patch' => 1656,

'alias' => null,

'complete' => '5.1',
'complete' => '26.0.1656.87080',
],
],
'renderingEngine' => [
Expand All @@ -54,20 +54,20 @@ public function testRealResultDevice()
],
],
'operatingSystem' => [
'name' => 'Mac OS X',
'name' => 'Android',
'version' => [
'major' => null,
'minor' => null,
'patch' => null,
'major' => 5,
'minor' => 0,
'patch' => 1,

'alias' => null,

'complete' => null,
'complete' => '5.0.1',
],
],
'device' => [
'model' => 'iPhone iOS 5.0',
'brand' => 'Apple',
'model' => 'Nexus 7',
'brand' => 'Google',
'type' => null,

'isMobile' => null,
Expand All @@ -86,43 +86,43 @@ public function testRealResultDevice()
$rawResult = $result->getProviderResultRaw();
$this->assertEquals([
'browser' => [
'link' => 'http://www.apple.com/safari/',
'title' => 'Safari 5.1',
'name' => 'Safari',
'version' => '5.1',
'code' => 'safari',
'image' => 'img/16/browser/safari.png',
'link' => 'http://www.opera.com/',
'title' => 'Opera 26.0.1656.87080',
'name' => 'Opera',
'version' => '26.0.1656.87080',
'code' => 'opera-1',
'image' => 'img/16/browser/opera-1.png',
],
'os' => [
'link' => 'http://www.apple.com/macosx/',
'name' => 'Mac OS X',
'version' => '',
'code' => 'mac-3',
'link' => 'http://www.android.com/',
'name' => 'Android',
'version' => '5.0.1',
'code' => 'android',
'x64' => false,
'title' => 'Mac OS X',
'title' => 'Android 5.0.1',
'type' => 'os',
'dir' => 'os',
'image' => 'img/16/os/mac-3.png',
'image' => 'img/16/os/android.png',
],
'device' => [
'link' => 'http://www.apple.com/iphone',
'title' => 'Apple iPhone iOS 5.0',
'model' => 'iPhone iOS 5.0',
'brand' => 'Apple',
'code' => 'iphone',
'link' => 'https://www.google.com/nexus/',
'title' => 'Google Nexus 7',
'model' => 'Nexus 7',
'brand' => 'Google',
'code' => 'google-nexusone',
'dir' => 'device',
'type' => 'device',
'image' => 'img/16/device/iphone.png',
'image' => 'img/16/device/google-nexusone.png',
],
'platform' => [
'link' => 'http://www.apple.com/iphone',
'title' => 'Apple iPhone iOS 5.0',
'model' => 'iPhone iOS 5.0',
'brand' => 'Apple',
'code' => 'iphone',
'link' => 'https://www.google.com/nexus/',
'title' => 'Google Nexus 7',
'model' => 'Nexus 7',
'brand' => 'Google',
'code' => 'google-nexusone',
'dir' => 'device',
'type' => 'device',
'image' => 'img/16/device/iphone.png',
'image' => 'img/16/device/google-nexusone.png',
],
], $rawResult);
}
Expand Down
Loading

0 comments on commit 9617f86

Please sign in to comment.