From b592e2392c5959dca7aeaf781066a327c66d0330 Mon Sep 17 00:00:00 2001 From: duxthefux Date: Sun, 25 Oct 2020 09:16:21 +0100 Subject: [PATCH 01/10] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 71faf4b..ee605ea 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "thadafinser/user-agent-parser", + "name": "ready2order/user-agent-parser", "description": "UserAgent parsing done right http://useragent.mkf.solutions/", "keywords": [ From c7bdbabaa85df261f63ec09821a2520ea2006921 Mon Sep 17 00:00:00 2001 From: Christopher Fuchs Date: Sun, 25 Oct 2020 09:24:27 +0100 Subject: [PATCH 02/10] Added support for composer 2.0 * Removed thadafinser/package-info and use composer-runtime-api --- composer.json | 2 +- src/Provider/AbstractProvider.php | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index ee605ea..3c193f2 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,7 @@ "require": { "php": "~5.6|~7.0", "guzzlehttp/guzzle": "^6.1", - "thadafinser/package-info": "^1.0" + "composer-runtime-api": "^2.0" }, "conflict": { diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index 8c95564..bd56f3f 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -1,9 +1,8 @@ getPackageName()); - - return $package->getVersion(); - } catch (PackageNotInstalledException $ex) { + return InstalledVersions::getVersion($this->getPackageName()); + } catch (\OutOfBoundsException $ex) { return; } } @@ -138,13 +135,7 @@ public function getVersion() */ public function getUpdateDate() { - try { - $package = new Package($this->getPackageName()); - - return $package->getVersionReleaseDate(); - } catch (PackageNotInstalledException $ex) { - return; - } + return; } /** @@ -163,7 +154,7 @@ public function getDetectionCapabilities() */ protected function checkIfInstalled() { - if (! Package::isInstalled($this->getPackageName())) { + if (! InstalledVersions::isInstalled($this->getPackageName())) { throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider'); } } From 8072210af5d0a638a208f39129cfc0fa1532edf2 Mon Sep 17 00:00:00 2001 From: Christopher Fuchs Date: Thu, 7 Jan 2021 10:58:26 +0100 Subject: [PATCH 03/10] Upgraded dependencies to work with PHP 8 --- composer.json | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 3c193f2..bddc26e 100644 --- a/composer.json +++ b/composer.json @@ -69,13 +69,13 @@ }, "require": { - "php": "~5.6|~7.0", + "php": "^7.4|^8.0", "guzzlehttp/guzzle": "^6.1", "composer-runtime-api": "^2.0" }, "conflict": { - "browscap/browscap-php": "<3,>=4", + "browscap/browscap-php": "^5.0", "donatj/phpuseragentparser": "<0.5,>=1", "jenssegers/agent": "<2.3,>=3", "mobiledetect/mobiledetectlib": "<2.7.5,>=3", @@ -104,10 +104,9 @@ }, "require-dev": { - "phpunit/phpunit": "^5.6.8", - "friendsofphp/php-cs-fixer": "^1.11", - - "browscap/browscap-php": "^3.0", + "phpunit/phpunit": "^9.5", + "friendsofphp/php-cs-fixer": "^2.17.3", + "browscap/browscap-php": "^4.0", "donatj/phpuseragentparser": "^0.5.0", "endorphin-studio/browser-detector": "^3.0", "handsetdetection/php-apikit": "^4.1.10", From 328fd0971a4a542d38f19f512fb55e512d54d67e Mon Sep 17 00:00:00 2001 From: Christopher Fuchs Date: Thu, 7 Jan 2021 10:58:36 +0100 Subject: [PATCH 04/10] Updated php-cs-fixer config --- .php_cs | 80 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/.php_cs b/.php_cs index ffbbfa9..0e745ae 100644 --- a/.php_cs +++ b/.php_cs @@ -1,51 +1,49 @@ in([ __DIR__ . '/src', __DIR__ . '/tests/integration', __DIR__ . '/tests/unit' ]); -$config = Symfony\CS\Config\Config::create(); -$config->setUsingCache(true); -$config->setUsingLinter(false); -$config->finder($finder); -$config->level(Symfony\CS\FixerInterface::PSR2_LEVEL); -$config->fixers([ - //symfony - 'double_arrow_multiline_whitespaces', - 'duplicate_semicolon', - 'empty_return', - 'extra_empty_lines', - 'include', - 'join_function', - 'multiline_array_trailing_comma', - 'namespace_no_leading_whitespace', - 'new_with_braces', - 'no_blank_lines_after_class_opening', - 'object_operator', - 'operators_spaces', - 'phpdoc_indent', - 'phpdoc_params', - 'remove_leading_slash_use', - 'remove_lines_between_uses', - 'return', - 'single_array_no_trailing_comma', - 'spaces_before_semicolon', - 'spaces_cast', - 'standardize_not_equal', - 'ternary_spaces', - 'unused_use', - 'whitespacy_lines', - - //contrib - 'align_double_arrow', - 'align_equals', - 'concat_with_spaces', - 'multiline_spaces_before_semicolon', - 'ordered_use', - 'short_array_syntax', -]); +$config = PhpCsFixer\Config::create() +->setUsingCache(true) +->setRiskyAllowed(true) +->setFinder($finder) +->setRules([ + '@PSR1' => true, + '@PSR2' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + '@PhpCsFixer' => true, + 'align_multiline_comment' => true, + 'array_syntax' => ['syntax' => 'short'], + 'declare_strict_types' => false, + 'return_assignment' => false, + 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], + 'dir_constant' => true, + 'elseif' => false, + 'ereg_to_preg' => true, + 'is_null' => true, + 'list_syntax' => ['syntax' => 'short'], + 'mb_str_functions' => true, + 'phpdoc_order' => true, + 'concat_space' => ['spacing' => 'one'], + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false, + ], + 'fully_qualified_strict_types' => true, + 'global_namespace_import' => [ + 'import_classes' => true, + ], + 'phpdoc_to_comment' => false, + 'method_argument_space' => ['on_multiline' => 'ignore'], + 'php_unit_ordered_covers' => false, + 'no_superfluous_elseif' => false, +] +); return $config; From 902dc41c6e953c20ab399f4eb5b2ad3bba38dc34 Mon Sep 17 00:00:00 2001 From: Christopher Fuchs Date: Thu, 7 Jan 2021 10:58:50 +0100 Subject: [PATCH 05/10] Linted files --- src/Exception/ExceptionInterface.php | 3 +- src/Exception/InvalidArgumentException.php | 3 +- src/Exception/InvalidCredentialsException.php | 7 +- src/Exception/LimitationExceededException.php | 7 +- src/Exception/NoResultFoundException.php | 5 +- src/Exception/PackageNotLoadedException.php | 7 +- src/Exception/RequestException.php | 7 +- src/Model/Bot.php | 22 +- src/Model/Browser.php | 10 +- src/Model/Device.php | 39 +-- src/Model/OperatingSystem.php | 10 +- src/Model/RenderingEngine.php | 10 +- src/Model/UserAgent.php | 55 ++-- src/Model/Version.php | 48 ++-- src/Provider/AbstractBrowscap.php | 112 +++----- src/Provider/AbstractProvider.php | 81 +++--- src/Provider/BrowscapFull.php | 25 +- src/Provider/BrowscapLite.php | 25 +- src/Provider/BrowscapPhp.php | 25 +- src/Provider/Chain.php | 10 +- src/Provider/DonatjUAParser.php | 86 +++--- src/Provider/Endorphin.php | 135 ++++------ src/Provider/HandsetDetection.php | 137 ++++------ src/Provider/Http/AbstractHttpProvider.php | 14 +- src/Provider/Http/DeviceAtlasCom.php | 102 +++---- src/Provider/Http/FiftyOneDegreesCom.php | 142 ++++------ src/Provider/Http/NeutrinoApiCom.php | 161 +++++------ src/Provider/Http/UdgerCom.php | 143 ++++------ src/Provider/Http/UserAgentApiCom.php | 136 ++++------ src/Provider/Http/WhatIsMyBrowserCom.php | 161 ++++------- src/Provider/JenssegersAgent.php | 167 +++++------- src/Provider/PiwikDeviceDetector.php | 168 +++++------- src/Provider/SinergiBrowserDetector.php | 145 +++++----- src/Provider/UAParser.php | 132 ++++------ src/Provider/WhichBrowser.php | 132 ++++------ src/Provider/Woothee.php | 124 ++++----- src/Provider/Zsxsoft.php | 123 ++++----- .../Provider/AbstractBrowscapTestCase.php | 6 +- .../Provider/AbstractProviderTestCase.php | 3 +- .../integration/Provider/BrowscapFullTest.php | 62 ++--- .../integration/Provider/BrowscapLiteTest.php | 19 +- .../integration/Provider/BrowscapPhpTest.php | 33 +-- tests/integration/Provider/ChainTest.php | 10 +- .../Provider/DonatjUAParserTest.php | 27 +- tests/integration/Provider/EndorphinTest.php | 36 +-- .../Provider/HandsetDetectionTest.php | 68 ++--- .../Http/AbstractHttpProviderTestCase.php | 16 +- .../Provider/Http/DeviceAtlasComTest.php | 29 +- .../Provider/Http/FiftyOneDegreesComTest.php | 41 +-- .../Provider/Http/NeutrinoApiComTest.php | 51 ++-- .../Provider/Http/UdgerComTest.php | 7 +- .../Provider/Http/UserAgentApiComTest.php | 49 ++-- .../Provider/Http/WhatIsMyBrowserComTest.php | 45 ++-- .../Provider/JenssegersAgentTest.php | 43 ++- .../Provider/PiwikDeviceDetectorTest.php | 90 ++++--- .../Provider/SinergiBrowserDetectorTest.php | 56 ++-- tests/integration/Provider/UAParserTest.php | 78 +++--- .../integration/Provider/WhichBrowserTest.php | 82 +++--- tests/integration/Provider/WootheeTest.php | 64 +++-- tests/integration/Provider/ZsxsoftTest.php | 65 +++-- tests/unit/Model/BotTest.php | 15 +- tests/unit/Model/BrowserTest.php | 11 +- tests/unit/Model/DeviceTest.php | 23 +- tests/unit/Model/OperatingSystemTest.php | 11 +- tests/unit/Model/RenderingEngineTest.php | 11 +- tests/unit/Model/UserAgentTest.php | 29 +- tests/unit/Model/VersionTest.php | 9 +- tests/unit/Provider/AbstractBrowscapTest.php | 249 +++++++++--------- tests/unit/Provider/AbstractProviderTest.php | 64 ++--- .../Provider/AbstractProviderTestCase.php | 10 +- tests/unit/Provider/BrowscapFullTest.php | 72 ++--- tests/unit/Provider/BrowscapLiteTest.php | 72 ++--- tests/unit/Provider/BrowscapPhpTest.php | 71 ++--- tests/unit/Provider/ChainTest.php | 46 ++-- tests/unit/Provider/DonatjUAParserTest.php | 46 ++-- tests/unit/Provider/EndorphinTest.php | 126 ++++----- tests/unit/Provider/HandsetDetectionTest.php | 117 ++++---- .../Http/AbstractHttpProviderTest.php | 26 +- .../unit/Provider/Http/DeviceAtlasComTest.php | 88 +++---- .../Provider/Http/FiftyOneDegreesComTest.php | 105 ++++---- .../unit/Provider/Http/NeutrinoApiComTest.php | 134 +++++----- tests/unit/Provider/Http/UdgerComTest.php | 108 ++++---- .../Provider/Http/UserAgentApiComTest.php | 100 ++++--- .../Provider/Http/WhatIsMyBrowserComTest.php | 221 ++++++++-------- tests/unit/Provider/JenssegersAgentTest.php | 115 ++++---- .../unit/Provider/PiwikDeviceDetectorTest.php | 174 ++++++------ .../RequiredProviderTestInterface.php | 3 +- .../Provider/SinergiBrowserDetectorTest.php | 191 +++++++------- tests/unit/Provider/UAParserTest.php | 180 ++++++------- tests/unit/Provider/WhichBrowserTest.php | 161 ++++++----- tests/unit/Provider/WootheeTest.php | 143 +++++----- tests/unit/Provider/ZsxsoftTest.php | 143 +++++----- 92 files changed, 2948 insertions(+), 3625 deletions(-) diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 588fc92..edf2ffa 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,8 +1,9 @@ * @license MIT diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 3323e0b..6d6b9fe 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -1,8 +1,9 @@ * @license MIT diff --git a/src/Exception/InvalidCredentialsException.php b/src/Exception/InvalidCredentialsException.php index c567d47..b4c7f5b 100644 --- a/src/Exception/InvalidCredentialsException.php +++ b/src/Exception/InvalidCredentialsException.php @@ -1,12 +1,15 @@ * @license MIT */ -class InvalidCredentialsException extends \Exception implements ExceptionInterface +class InvalidCredentialsException extends Exception implements ExceptionInterface { } diff --git a/src/Exception/LimitationExceededException.php b/src/Exception/LimitationExceededException.php index 78aef01..8eae423 100644 --- a/src/Exception/LimitationExceededException.php +++ b/src/Exception/LimitationExceededException.php @@ -1,12 +1,15 @@ * @license MIT */ -class LimitationExceededException extends \Exception implements ExceptionInterface +class LimitationExceededException extends Exception implements ExceptionInterface { } diff --git a/src/Exception/NoResultFoundException.php b/src/Exception/NoResultFoundException.php index 44e366c..c14ac3d 100644 --- a/src/Exception/NoResultFoundException.php +++ b/src/Exception/NoResultFoundException.php @@ -1,12 +1,15 @@ * @license MIT */ -class NoResultFoundException extends \Exception implements ExceptionInterface +class NoResultFoundException extends Exception implements ExceptionInterface { } diff --git a/src/Exception/PackageNotLoadedException.php b/src/Exception/PackageNotLoadedException.php index 854da5a..ea2becc 100644 --- a/src/Exception/PackageNotLoadedException.php +++ b/src/Exception/PackageNotLoadedException.php @@ -1,12 +1,15 @@ * @license MIT */ -class PackageNotLoadedException extends \Exception implements ExceptionInterface +class PackageNotLoadedException extends Exception implements ExceptionInterface { } diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index efb97bf..24a7d5f 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -1,12 +1,15 @@ * @license MIT */ -class RequestException extends \Exception implements ExceptionInterface +class RequestException extends Exception implements ExceptionInterface { } diff --git a/src/Model/Bot.php b/src/Model/Bot.php index c6119f7..211b903 100644 --- a/src/Model/Bot.php +++ b/src/Model/Bot.php @@ -1,8 +1,9 @@ * @license MIT @@ -10,26 +11,22 @@ class Bot { /** - * - * @var boolean + * @var bool */ private $isBot; /** - * * @var string */ private $name; /** - * * @var string */ private $type; /** - * - * @param boolean $mode + * @param bool $mode */ public function setIsBot($mode) { @@ -37,8 +34,7 @@ public function setIsBot($mode) } /** - * - * @return boolean + * @return bool */ public function getIsBot() { @@ -46,7 +42,6 @@ public function getIsBot() } /** - * * @param string $name */ public function setName($name) @@ -55,7 +50,6 @@ public function setName($name) } /** - * * @return string */ public function getName() @@ -64,7 +58,6 @@ public function getName() } /** - * * @param string $type */ public function setType($type) @@ -81,15 +74,14 @@ public function getType() } /** - * * @return array */ public function toArray() { return [ 'isBot' => $this->getIsBot(), - 'name' => $this->getName(), - 'type' => $this->getType(), + 'name' => $this->getName(), + 'type' => $this->getType(), ]; } } diff --git a/src/Model/Browser.php b/src/Model/Browser.php index a10fe35..8902515 100644 --- a/src/Model/Browser.php +++ b/src/Model/Browser.php @@ -1,8 +1,9 @@ * @license MIT @@ -25,7 +26,6 @@ public function __construct() } /** - * * @param string $name */ public function setName($name) @@ -34,7 +34,6 @@ public function setName($name) } /** - * * @return string */ public function getName() @@ -42,9 +41,6 @@ public function getName() return $this->name; } - /** - * @param Version $version - */ public function setVersion(Version $version) { $this->version = $version; @@ -64,7 +60,7 @@ public function getVersion() public function toArray() { return [ - 'name' => $this->getName(), + 'name' => $this->getName(), 'version' => $this->getVersion()->toArray(), ]; } diff --git a/src/Model/Device.php b/src/Model/Device.php index 3fd10ee..6ec662a 100644 --- a/src/Model/Device.php +++ b/src/Model/Device.php @@ -1,8 +1,9 @@ * @license MIT @@ -10,37 +11,31 @@ class Device { /** - * * @var string */ private $model; /** - * * @var string */ private $brand; /** - * * @var string */ private $type; /** - * - * @var boolean + * @var bool */ private $isMobile; /** - * - * @var boolean + * @var bool */ private $isTouch; /** - * * @param string $model */ public function setModel($model) @@ -49,7 +44,6 @@ public function setModel($model) } /** - * * @return string */ public function getModel() @@ -58,7 +52,6 @@ public function getModel() } /** - * * @param string $brand */ public function setBrand($brand) @@ -67,7 +60,6 @@ public function setBrand($brand) } /** - * * @return string */ public function getBrand() @@ -76,7 +68,6 @@ public function getBrand() } /** - * * @param string $type */ public function setType($type) @@ -85,7 +76,6 @@ public function setType($type) } /** - * * @return string */ public function getType() @@ -94,8 +84,7 @@ public function getType() } /** - * - * @param boolean $isMobile + * @param bool $isMobile */ public function setIsMobile($isMobile) { @@ -103,8 +92,7 @@ public function setIsMobile($isMobile) } /** - * - * @return boolean + * @return bool */ public function getIsMobile() { @@ -112,8 +100,7 @@ public function getIsMobile() } /** - * - * @param boolean $isTouch + * @param bool $isTouch */ public function setIsTouch($isTouch) { @@ -121,8 +108,7 @@ public function setIsTouch($isTouch) } /** - * - * @return boolean + * @return bool */ public function getIsTouch() { @@ -130,17 +116,16 @@ public function getIsTouch() } /** - * * @return array */ public function toArray() { return [ - 'model' => $this->getModel(), - 'brand' => $this->getBrand(), - 'type' => $this->getType(), + 'model' => $this->getModel(), + 'brand' => $this->getBrand(), + 'type' => $this->getType(), 'isMobile' => $this->getIsMobile(), - 'isTouch' => $this->getIsTouch(), + 'isTouch' => $this->getIsTouch(), ]; } } diff --git a/src/Model/OperatingSystem.php b/src/Model/OperatingSystem.php index b4d3901..dacb6e6 100644 --- a/src/Model/OperatingSystem.php +++ b/src/Model/OperatingSystem.php @@ -1,8 +1,9 @@ * @license MIT @@ -25,7 +26,6 @@ public function __construct() } /** - * * @param string $name */ public function setName($name) @@ -34,7 +34,6 @@ public function setName($name) } /** - * * @return string */ public function getName() @@ -42,9 +41,6 @@ public function getName() return $this->name; } - /** - * @param Version $version - */ public function setVersion(Version $version) { $this->version = $version; @@ -64,7 +60,7 @@ public function getVersion() public function toArray() { return [ - 'name' => $this->getName(), + 'name' => $this->getName(), 'version' => $this->getVersion()->toArray(), ]; } diff --git a/src/Model/RenderingEngine.php b/src/Model/RenderingEngine.php index a132a29..48f637d 100644 --- a/src/Model/RenderingEngine.php +++ b/src/Model/RenderingEngine.php @@ -1,8 +1,9 @@ * @license MIT @@ -25,7 +26,6 @@ public function __construct() } /** - * * @param string $name */ public function setName($name) @@ -34,7 +34,6 @@ public function setName($name) } /** - * * @return string */ public function getName() @@ -42,9 +41,6 @@ public function getName() return $this->name; } - /** - * @param Version $version - */ public function setVersion(Version $version) { $this->version = $version; @@ -64,7 +60,7 @@ public function getVersion() public function toArray() { return [ - 'name' => $this->getName(), + 'name' => $this->getName(), 'version' => $this->getVersion()->toArray(), ]; } diff --git a/src/Model/UserAgent.php b/src/Model/UserAgent.php index e7f6e2c..a362d48 100644 --- a/src/Model/UserAgent.php +++ b/src/Model/UserAgent.php @@ -1,8 +1,9 @@ * @license MIT @@ -10,14 +11,14 @@ class UserAgent { /** - * Provider name + * Provider name. * * @var string */ private $providerName; /** - * Provider version + * Provider version. * * @var string */ @@ -54,23 +55,23 @@ class UserAgent private $providerResultRaw; /** - * - * @param string $provider + * @param string $provider + * @param null|mixed $providerName + * @param null|mixed $providerVersion */ public function __construct($providerName = null, $providerVersion = null) { - $this->providerName = $providerName; + $this->providerName = $providerName; $this->providerVersion = $providerVersion; - $this->browser = new Browser(); + $this->browser = new Browser(); $this->renderingEngine = new RenderingEngine(); $this->operatingSystem = new OperatingSystem(); - $this->device = new Device(); - $this->bot = new Bot(); + $this->device = new Device(); + $this->bot = new Bot(); } /** - * * @return string */ public function getProviderName() @@ -79,7 +80,6 @@ public function getProviderName() } /** - * * @return string */ public function getProviderVersion() @@ -87,9 +87,6 @@ public function getProviderVersion() return $this->providerVersion; } - /** - * @param Browser $browser - */ public function setBrowser(Browser $browser) { $this->browser = $browser; @@ -103,9 +100,6 @@ public function getBrowser() return $this->browser; } - /** - * @param RenderingEngine $renderingEngine - */ public function setRenderingEngine(RenderingEngine $renderingEngine) { $this->renderingEngine = $renderingEngine; @@ -119,9 +113,6 @@ public function getRenderingEngine() return $this->renderingEngine; } - /** - * @param OperatingSystem $operatingSystem - */ public function setOperatingSystem(OperatingSystem $operatingSystem) { $this->operatingSystem = $operatingSystem; @@ -135,9 +126,6 @@ public function getOperatingSystem() return $this->operatingSystem; } - /** - * @param Device $device - */ public function setDevice(Device $device) { $this->device = $device; @@ -151,9 +139,6 @@ public function getDevice() return $this->device; } - /** - * @param Bot $bot - */ public function setBot(Bot $bot) { $this->bot = $bot; @@ -168,8 +153,7 @@ public function getBot() } /** - * - * @return boolean + * @return bool */ public function isBot() { @@ -181,8 +165,7 @@ public function isBot() } /** - * - * @return boolean + * @return bool */ public function isMobile() { @@ -210,16 +193,18 @@ public function getProviderResultRaw() } /** + * @param mixed $includeResultRaw + * * @return array */ public function toArray($includeResultRaw = false) { $data = [ - 'browser' => $this->getBrowser()->toArray(), - 'renderingEngine' => $this->getRenderingEngine()->toArray(), - 'operatingSystem' => $this->getOperatingSystem()->toArray(), - 'device' => $this->getDevice()->toArray(), - 'bot' => $this->getBot()->toArray(), + 'browser' => $this->getBrowser()->toArray(), + 'renderingEngine' => $this->getRenderingEngine()->toArray(), + 'operatingSystem' => $this->getOperatingSystem()->toArray(), + 'device' => $this->getDevice()->toArray(), + 'bot' => $this->getBot()->toArray(), ]; // should be only used for debug diff --git a/src/Model/Version.php b/src/Model/Version.php index f12a1e7..5b4c927 100644 --- a/src/Model/Version.php +++ b/src/Model/Version.php @@ -1,8 +1,9 @@ * @license MIT @@ -10,31 +11,26 @@ class Version { /** - * - * @var integer + * @var int */ private $major; /** - * - * @var integer + * @var int */ private $minor; /** - * - * @var integer + * @var int */ private $patch; /** - * * @var string */ private $alias; /** - * * @var string */ private $complete; @@ -52,8 +48,7 @@ class Version ]; /** - * - * @param integer $major + * @param int $major */ public function setMajor($major) { @@ -67,8 +62,7 @@ public function setMajor($major) } /** - * - * @return integer + * @return int */ public function getMajor() { @@ -76,8 +70,7 @@ public function getMajor() } /** - * - * @param integer $minor + * @param int $minor */ public function setMinor($minor) { @@ -91,8 +84,7 @@ public function setMinor($minor) } /** - * - * @return integer + * @return int */ public function getMinor() { @@ -100,8 +92,7 @@ public function getMinor() } /** - * - * @param integer $patch + * @param int $patch */ public function setPatch($patch) { @@ -115,8 +106,7 @@ public function setPatch($patch) } /** - * - * @return integer + * @return int */ public function getPatch() { @@ -124,7 +114,6 @@ public function getPatch() } /** - * * @param string $alias */ public function setAlias($alias) @@ -135,7 +124,6 @@ public function setAlias($alias) } /** - * * @return string */ public function getAlias() @@ -163,7 +151,6 @@ public function setComplete($complete) } /** - * * @return string */ public function getComplete() @@ -172,7 +159,6 @@ public function getComplete() } /** - * * @return array */ public function toArray() @@ -189,7 +175,6 @@ public function toArray() } /** - * * @return string */ private function hydrateComplete() @@ -226,6 +211,7 @@ private function hydrateFromComplete($complete) } /** + * @param mixed $complete * * @return array */ @@ -240,9 +226,9 @@ private function getCompleteParts($complete) ]; // only digits - preg_match("/\d+(?:[._]*\d*)*/", $complete, $result); - if (count($result) > 0) { - $parts = preg_split("/[._]/", $result[0]); + preg_match('/\\d+(?:[._]*\\d*)*/', $complete, $result); + if (\count($result) > 0) { + $parts = preg_split('/[._]/', $result[0]); if (isset($parts[0]) && $parts[0] != '') { $versionParts['major'] = (int) $parts[0]; @@ -256,7 +242,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); @@ -265,7 +251,7 @@ private function getCompleteParts($complete) } // do not use beta and other things - if (in_array($row, self::$notAllowedAlias)) { + if (\in_array($row, self::$notAllowedAlias)) { continue; } diff --git a/src/Provider/AbstractBrowscap.php b/src/Provider/AbstractBrowscap.php index 6977c4d..fd36d6d 100644 --- a/src/Provider/AbstractBrowscap.php +++ b/src/Provider/AbstractBrowscap.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/browscap/browscap-php */ abstract class AbstractBrowscap extends AbstractProvider { /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/browscap/browscap-php'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'browscap/browscap-php'; protected $defaultValues = [ - 'general' => [ '/^unknown$/i', ], @@ -59,7 +60,6 @@ abstract class AbstractBrowscap extends AbstractProvider ]; /** - * * @var Browscap */ private $parser; @@ -94,7 +94,6 @@ public function getUpdateDate() } /** - * * @return Browscap */ public function getParser() @@ -102,10 +101,39 @@ public function getParser() return $this->parser; } + public function parse($userAgent, array $headers = []) + { + $parser = $this->getParser(); + + // @var $resultRaw \stdClass + $resultRaw = $parser->getBrowser($userAgent); + + // No result found? + if ($this->hasResult($resultRaw) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection (does only work with full_php_browscap.ini) + if ($this->isBot($resultRaw) === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; + } + /** - * - * @param stdClass $resultRaw - * * @return bool */ private function hasResult(stdClass $resultRaw) @@ -118,9 +146,7 @@ private function hasResult(stdClass $resultRaw) } /** - * - * @param stdClass $resultRaw - * @return boolean + * @return bool */ private function isBot(stdClass $resultRaw) { @@ -131,11 +157,6 @@ private function isBot(stdClass $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param stdClass $resultRaw - */ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) { $bot->setIsBot(true); @@ -151,11 +172,6 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) } } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->browser)) { @@ -167,11 +183,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\RenderingEngine $engine - * @param stdClass $resultRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) { if (isset($resultRaw->renderingengine_name)) { @@ -183,11 +194,6 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass } } - /** - * - * @param Model\OperatingSystem $os - * @param stdClass $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { if (isset($resultRaw->platform)) { @@ -200,9 +206,7 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $res } /** - * * @param Model\UserAgent $device - * @param stdClass $resultRaw */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { @@ -226,44 +230,4 @@ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) $device->setIsTouch(true); } } - - public function parse($userAgent, array $headers = []) - { - $parser = $this->getParser(); - - /* @var $resultRaw \stdClass */ - $resultRaw = $parser->getBrowser($userAgent); - - /* - * No result found? - */ - if ($this->hasResult($resultRaw) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection (does only work with full_php_browscap.ini) - */ - if ($this->isBot($resultRaw) === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index bd56f3f..dfdffff 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -1,14 +1,16 @@ * @license MIT @@ -16,21 +18,21 @@ abstract class AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage; /** - * Composer package name + * Composer package name. * * @var string */ @@ -38,43 +40,43 @@ abstract class AbstractProvider /** * Per default the provider cannot detect anything - * Activate them in $detectionCapabilities + * Activate them in $detectionCapabilities. * * @var array */ protected $allDetectionCapabilities = [ 'browser' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; /** - * Set this in each Provider implementation + * Set this in each Provider implementation. * * @var array */ @@ -85,7 +87,7 @@ abstract class AbstractProvider ]; /** - * Return the name of the provider + * Return the name of the provider. * * @return string */ @@ -95,7 +97,7 @@ public function getName() } /** - * Get the homepage + * Get the homepage. * * @return string */ @@ -105,7 +107,7 @@ public function getHomepage() } /** - * Get the package name + * Get the package name. * * @return string null */ @@ -115,7 +117,7 @@ public function getPackageName() } /** - * Return the version of the provider + * Return the version of the provider. * * @return string null */ @@ -123,23 +125,22 @@ public function getVersion() { try { return InstalledVersions::getVersion($this->getPackageName()); - } catch (\OutOfBoundsException $ex) { + } catch (OutOfBoundsException $ex) { return; } } /** - * Get the last change date of the provider + * Get the last change date of the provider. * * @return DateTime null */ public function getUpdateDate() { - return; } /** - * What kind of capabilities this provider can detect + * What kind of capabilities this provider can detect. * * @return array */ @@ -149,22 +150,32 @@ public function getDetectionCapabilities() } /** + * Parse the given user agent and return a result if possible. + * + * @param string $userAgent * + * @throws Exception\NoResultFoundException + * + * @return Model\UserAgent + */ + abstract public function parse($userAgent, array $headers = []); + + /** * @throws PackageNotLoadedException */ protected function checkIfInstalled() { - if (! InstalledVersions::isInstalled($this->getPackageName())) { + if (!InstalledVersions::isInstalled($this->getPackageName())) { throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider'); } } /** + * @param mixed $value + * @param string $group + * @param string $part * - * @param mixed $value - * @param string $group - * @param string $part - * @return boolean + * @return bool */ protected function isRealResult($value, $group = null, $part = null) { @@ -195,19 +206,5 @@ protected function getRealResult($value, $group = null, $part = null) if ($this->isRealResult($value, $group, $part) === true) { return $value; } - - return; } - - /** - * Parse the given user agent and return a result if possible - * - * @param string $userAgent - * @param array $headers - * - * @throws Exception\NoResultFoundException - * - * @return Model\UserAgent - */ - abstract public function parse($userAgent, array $headers = []); } diff --git a/src/Provider/BrowscapFull.php b/src/Provider/BrowscapFull.php index bc3bd48..6ef6a5d 100644 --- a/src/Provider/BrowscapFull.php +++ b/src/Provider/BrowscapFull.php @@ -1,53 +1,54 @@ * @license MIT + * * @see https://github.com/browscap/browscap-php */ class BrowscapFull extends AbstractBrowscap { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'BrowscapFull'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ]; diff --git a/src/Provider/BrowscapLite.php b/src/Provider/BrowscapLite.php index fdbc5e3..ff2d11a 100644 --- a/src/Provider/BrowscapLite.php +++ b/src/Provider/BrowscapLite.php @@ -1,53 +1,54 @@ * @license MIT + * * @see https://github.com/browscap/browscap-php */ class BrowscapLite extends AbstractBrowscap { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'BrowscapLite'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; diff --git a/src/Provider/BrowscapPhp.php b/src/Provider/BrowscapPhp.php index 85ab33f..023609b 100644 --- a/src/Provider/BrowscapPhp.php +++ b/src/Provider/BrowscapPhp.php @@ -1,51 +1,52 @@ * @license MIT + * * @see https://github.com/browscap/browscap-php */ class BrowscapPhp extends AbstractBrowscap { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'BrowscapPhp'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; } diff --git a/src/Provider/Chain.php b/src/Provider/Chain.php index 9030f73..ef433af 100644 --- a/src/Provider/Chain.php +++ b/src/Provider/Chain.php @@ -1,10 +1,11 @@ * @license MIT @@ -12,20 +13,18 @@ class Chain extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'Chain'; /** - * * @var AbstractProvider[] */ private $providers = []; /** - * * @param AbstractProvider[] $providers */ public function __construct(array $providers = []) @@ -34,7 +33,6 @@ public function __construct(array $providers = []) } /** - * * @return AbstractProvider[] */ public function getProviders() @@ -45,7 +43,7 @@ public function getProviders() public function parse($userAgent, array $headers = []) { foreach ($this->getProviders() as $provider) { - /* @var $provider \UserAgentParser\Provider\AbstractProvider */ + // @var $provider \UserAgentParser\Provider\AbstractProvider try { return $provider->parse($userAgent, $headers); diff --git a/src/Provider/DonatjUAParser.php b/src/Provider/DonatjUAParser.php index f7d26d5..7ca36d8 100644 --- a/src/Provider/DonatjUAParser.php +++ b/src/Provider/DonatjUAParser.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/donatj/PhpUserAgent */ class DonatjUAParser extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'DonatjUAParser'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/donatj/PhpUserAgent'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'donatj/phpuseragentparser'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; private $functionName = '\parse_user_agent'; /** - * * @throws PackageNotLoadedException */ public function __construct() @@ -78,32 +78,6 @@ public function __construct() $this->checkIfInstalled(); } - /** - * - * @param array $resultRaw - * - * @return bool - */ - private function hasResult(array $resultRaw) - { - if ($this->isRealResult($resultRaw['browser'])) { - return true; - } - - return false; - } - - /** - * - * @param Model\Browser $browser - * @param array $resultRaw - */ - private function hydrateBrowser(Model\Browser $browser, array $resultRaw) - { - $browser->setName($this->getRealResult($resultRaw['browser'])); - $browser->getVersion()->setComplete($this->getRealResult($resultRaw['version'])); - } - public function parse($userAgent, array $headers = []) { $functionName = $this->functionName; @@ -114,19 +88,13 @@ public function parse($userAgent, array $headers = []) throw new NoResultFoundException('No result found for user agent: ' . $userAgent); } - /* - * Hydrate the model - */ + // Hydrate the model $result = new Model\UserAgent($this->getName(), $this->getVersion()); $result->setProviderResultRaw($resultRaw); - /* - * Bot detection - is currently not possible! - */ + // Bot detection - is currently not possible! - /* - * hydrate the result - */ + // hydrate the result $this->hydrateBrowser($result->getBrowser(), $resultRaw); // renderingEngine not available // os is mixed with device informations @@ -134,4 +102,22 @@ public function parse($userAgent, array $headers = []) return $result; } + + /** + * @return bool + */ + private function hasResult(array $resultRaw) + { + if ($this->isRealResult($resultRaw['browser'])) { + return true; + } + + return false; + } + + private function hydrateBrowser(Model\Browser $browser, array $resultRaw) + { + $browser->setName($this->getRealResult($resultRaw['browser'])); + $browser->getVersion()->setComplete($this->getRealResult($resultRaw['version'])); + } } diff --git a/src/Provider/Endorphin.php b/src/Provider/Endorphin.php index 21d65c4..7949966 100644 --- a/src/Provider/Endorphin.php +++ b/src/Provider/Endorphin.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/EndorphinDetector-studio/browser-detector */ class Endorphin extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'Endorphin'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/endorphin-studio/browser-detector'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'endorphin-studio/browser-detector'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ]; protected $defaultValues = [ - 'general' => [ '/^N\\\\A$/i', ], 'device' => [ - 'model' => [ '/^Desktop/i', ], @@ -83,14 +82,13 @@ class Endorphin extends AbstractProvider ]; /** - * Used for unitTests mocking + * Used for unitTests mocking. * * @var EndorphinDetector\Detector */ private $parser; /** - * * @throws PackageNotLoadedException */ public function __construct() @@ -99,8 +97,8 @@ public function __construct() } /** + * @param string $userAgent * - * @param string $userAgent * @return EndorphinDetector\DetectorResult */ public function getParser($userAgent) @@ -112,10 +110,41 @@ public function getParser($userAgent) return EndorphinDetector\Detector::analyse($userAgent); } + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getParser($userAgent); + + // No result found? + if ($this->hasResult($resultRaw) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isRealResult($resultRaw->Robot->getType()) === true) { + $this->hydrateBot($result->getBot(), $resultRaw->Robot); + + return $result; + } + + // hydrate the result + if ($resultRaw->Browser instanceof EndorphinDetector\Browser) { + $this->hydrateBrowser($result->getBrowser(), $resultRaw->Browser); + } + if ($resultRaw->OS instanceof EndorphinDetector\OS) { + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->OS); + } + if ($resultRaw->Device instanceof EndorphinDetector\Device) { + $this->hydrateDevice($result->getDevice(), $resultRaw->Device); + } + + return $result; + } + /** - * - * @param EndorphinDetector\DetectorResult $resultRaw - * * @return bool */ private function hasResult(EndorphinDetector\DetectorResult $resultRaw) @@ -139,11 +168,6 @@ private function hasResult(EndorphinDetector\DetectorResult $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param EndorphinDetector\Robot $resultRaw - */ private function hydrateBot(Model\Bot $bot, EndorphinDetector\Robot $resultRaw) { $bot->setIsBot(true); @@ -151,78 +175,21 @@ private function hydrateBot(Model\Bot $bot, EndorphinDetector\Robot $resultRaw) $bot->setType($this->getRealResult($resultRaw->getType())); } - /** - * - * @param Model\Browser $browser - * @param EndorphinDetector\Browser $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, EndorphinDetector\Browser $resultRaw) { $browser->setName($this->getRealResult($resultRaw->getName())); $browser->getVersion()->setComplete($this->getRealResult($resultRaw->getVersion())); } - /** - * - * @param Model\OperatingSystem $os - * @param EndorphinDetector\OS $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, EndorphinDetector\OS $resultRaw) { $os->setName($this->getRealResult($resultRaw->getName())); $os->getVersion()->setComplete($this->getRealResult($resultRaw->getVersion())); } - /** - * - * @param Model\Device $device - * @param EndorphinDetector\Device $resultRaw - */ private function hydrateDevice(Model\Device $device, EndorphinDetector\Device $resultRaw) { // $device->setModel($this->getRealResult($resultRaw->ModelName)); $device->setType($this->getRealResult($resultRaw->getType())); } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getParser($userAgent); - - /* - * No result found? - */ - if ($this->hasResult($resultRaw) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isRealResult($resultRaw->Robot->getType()) === true) { - $this->hydrateBot($result->getBot(), $resultRaw->Robot); - - return $result; - } - - /* - * hydrate the result - */ - if ($resultRaw->Browser instanceof EndorphinDetector\Browser) { - $this->hydrateBrowser($result->getBrowser(), $resultRaw->Browser); - } - if ($resultRaw->OS instanceof EndorphinDetector\OS) { - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->OS); - } - if ($resultRaw->Device instanceof EndorphinDetector\Device) { - $this->hydrateDevice($result->getDevice(), $resultRaw->Device); - } - - return $result; - } } diff --git a/src/Provider/HandsetDetection.php b/src/Provider/HandsetDetection.php index f95e32a..6dff226 100644 --- a/src/Provider/HandsetDetection.php +++ b/src/Provider/HandsetDetection.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/HandsetDetection/php-apikit */ class HandsetDetection extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'HandsetDetection'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/HandsetDetection/php-apikit'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'handsetdetection/php-apikit'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => false, + 'model' => true, + 'brand' => true, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [ '/^generic$/i', ], @@ -86,22 +86,16 @@ class HandsetDetection extends AbstractProvider ]; /** - * * @var Parser\HD4 */ private $parser; - /** - * - * @param Parser\HD4 $parser - */ public function __construct(Parser\HD4 $parser) { $this->parser = $parser; } /** - * * @return Parser\HD4 */ public function getParser() @@ -109,10 +103,46 @@ public function getParser() return $this->parser; } + public function parse($userAgent, array $headers = []) + { + $headers['User-Agent'] = $userAgent; + + $parser = $this->getParser(); + // $config = $parser->config; + + // $parser = new Parser\HD4($config); + + // No result found? + $result = $parser->deviceDetect($headers); + $resultRaw = $parser->getReply(); + + if ($result !== true) { + if (isset($resultRaw['status']) && $resultRaw['status'] == '299') { + throw new InvalidArgumentException('You need to warm-up the cache first to use this provider'); + } + + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // No result found? + if (!isset($resultRaw['hd_specs']) || $this->hasResult($resultRaw['hd_specs']) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw['hd_specs']); + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw['hd_specs']); + // renderingEngine not available + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw['hd_specs']); + $this->hydrateDevice($result->getDevice(), $resultRaw['hd_specs']); + + return $result; + } + /** - * - * @param array $resultRaw - * * @return bool */ private function hasResult(array $resultRaw) @@ -132,11 +162,6 @@ private function hasResult(array $resultRaw) return false; } - /** - * - * @param Model\Browser $browser - * @param array $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) { if (isset($resultRaw['general_browser'])) { @@ -147,11 +172,6 @@ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) } } - /** - * - * @param Model\OperatingSystem $os - * @param array $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, array $resultRaw) { if (isset($resultRaw['general_platform'])) { @@ -163,9 +183,7 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, array $result } /** - * * @param Model\UserAgent $device - * @param array $resultRaw */ private function hydrateDevice(Model\Device $device, array $resultRaw) { @@ -174,51 +192,4 @@ private function hydrateDevice(Model\Device $device, array $resultRaw) $device->setBrand($this->getRealResult($resultRaw['general_vendor'], 'device', 'brand')); } } - - public function parse($userAgent, array $headers = []) - { - $headers['User-Agent'] = $userAgent; - - $parser = $this->getParser(); - // $config = $parser->config; - - // $parser = new Parser\HD4($config); - - /* - * No result found? - */ - $result = $parser->deviceDetect($headers); - $resultRaw = $parser->getReply(); - - if ($result !== true) { - if (isset($resultRaw['status']) && $resultRaw['status'] == '299') { - throw new InvalidArgumentException('You need to warm-up the cache first to use this provider'); - } - - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * No result found? - */ - if (! isset($resultRaw['hd_specs']) || $this->hasResult($resultRaw['hd_specs']) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw['hd_specs']); - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw['hd_specs']); - // renderingEngine not available - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw['hd_specs']); - $this->hydrateDevice($result->getDevice(), $resultRaw['hd_specs']); - - return $result; - } } diff --git a/src/Provider/Http/AbstractHttpProvider.php b/src/Provider/Http/AbstractHttpProvider.php index 243dbc6..e09093f 100644 --- a/src/Provider/Http/AbstractHttpProvider.php +++ b/src/Provider/Http/AbstractHttpProvider.php @@ -1,4 +1,5 @@ * @license MIT @@ -17,22 +18,16 @@ abstract class AbstractHttpProvider extends AbstractProvider { /** - * * @var Client */ private $client; - /** - * - * @param Client $client - */ public function __construct(Client $client) { $this->client = $client; } /** - * * @return Client */ public function getClient() @@ -41,15 +36,14 @@ public function getClient() } /** + * @throws Exception\RequestException * - * @param RequestInterface $request * @return Response - * @throws Exception\RequestException */ protected function getResponse(RequestInterface $request) { try { - /* @var $response \GuzzleHttp\Psr7\Response */ + // @var $response \GuzzleHttp\Psr7\Response $response = $this->getClient()->send($request); } catch (GuzzleHttpException $ex) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '"', null, $ex); diff --git a/src/Provider/Http/DeviceAtlasCom.php b/src/Provider/Http/DeviceAtlasCom.php index fbfd59b..529312f 100644 --- a/src/Provider/Http/DeviceAtlasCom.php +++ b/src/Provider/Http/DeviceAtlasCom.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://deviceatlas.com/resources/enterprise-api-documentation */ class DeviceAtlasCom extends AbstractHttpProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'DeviceAtlasCom'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://deviceatlas.com/'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; @@ -73,11 +74,26 @@ public function __construct(Client $client, $apiKey) $this->apiKey = $apiKey; } + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getResult($userAgent, $headers); + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; + } + protected function getResult($userAgent, array $headers) { - /* - * an empty UserAgent makes no sense - */ + // an empty UserAgent makes no sense if ($userAgent == '') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } @@ -102,7 +118,7 @@ protected function getResult($userAgent, array $headers) try { $response = $this->getResponse($request); } catch (Exception\RequestException $ex) { - /* @var $prevEx \GuzzleHttp\Exception\ClientException */ + // @var $prevEx \GuzzleHttp\Exception\ClientException $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { @@ -112,35 +128,26 @@ protected function getResult($userAgent, array $headers) throw $ex; } - /* - * no json returned? - */ + // no json returned? $contentType = $response->getHeader('Content-Type'); - if (! isset($contentType[0]) || $contentType[0] != 'application/json; charset=UTF-8') { + if (!isset($contentType[0]) || $contentType[0] != 'application/json; charset=UTF-8') { throw new Exception\RequestException('Could not get valid "application/json" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } $content = json_decode($response->getBody()->getContents()); - if (! $content instanceof stdClass || ! isset($content->properties)) { + if (!$content instanceof stdClass || !isset($content->properties)) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } - /* - * No result found? - */ - if (! $content->properties instanceof stdClass || count((array) $content->properties) === 0) { + // No result found? + if (!$content->properties instanceof stdClass || \count((array) $content->properties) === 0) { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } return $content->properties; } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->browserName)) { @@ -152,11 +159,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\RenderingEngine $engine - * @param stdClass $resultRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) { if (isset($resultRaw->browserRenderingEngine)) { @@ -164,11 +166,6 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass } } - /** - * - * @param Model\OperatingSystem $os - * @param stdClass $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { if (isset($resultRaw->osName)) { @@ -181,9 +178,7 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $res } /** - * * @param Model\UserAgent $device - * @param stdClass $resultRaw */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { @@ -191,25 +186,4 @@ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) $device->setType($this->getRealResult($resultRaw->primaryHardwareType)); } } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getResult($userAgent, $headers); - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/Http/FiftyOneDegreesCom.php b/src/Provider/Http/FiftyOneDegreesCom.php index 5522e62..4d5a0f9 100644 --- a/src/Provider/Http/FiftyOneDegreesCom.php +++ b/src/Provider/Http/FiftyOneDegreesCom.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://51degrees.com */ class FiftyOneDegreesCom extends AbstractHttpProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'FiftyOneDegreesCom'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://51degrees.com'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; @@ -79,18 +80,40 @@ public function __construct(Client $client, $apiKey) $this->apiKey = $apiKey; } + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getResult($userAgent, $headers); + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if (isset($resultRaw->IsCrawler) && $resultRaw->IsCrawler === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; + } + /** + * @param string $userAgent * - * @param string $userAgent - * @param array $headers - * @return stdClass * @throws Exception\RequestException + * + * @return stdClass */ protected function getResult($userAgent, array $headers) { - /* - * an empty UserAgent makes no sense - */ + // an empty UserAgent makes no sense if ($userAgent == '') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } @@ -114,7 +137,7 @@ protected function getResult($userAgent, array $headers) try { $response = $this->getResponse($request); } catch (Exception\RequestException $ex) { - /* @var $prevEx \GuzzleHttp\Exception\ClientException */ + // @var $prevEx \GuzzleHttp\Exception\ClientException $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { @@ -124,38 +147,30 @@ protected function getResult($userAgent, array $headers) throw $ex; } - /* - * no json returned? - */ + // no json returned? $contentType = $response->getHeader('Content-Type'); - if (! isset($contentType[0]) || $contentType[0] != 'application/json; charset=utf-8') { + if (!isset($contentType[0]) || $contentType[0] != 'application/json; charset=utf-8') { throw new Exception\RequestException('Could not get valid "application/json; charset=utf-8" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } $content = json_decode($response->getBody()->getContents()); - /* - * No result - */ + // No result if (isset($content->MatchMethod) && $content->MatchMethod == 'None') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } - /* - * Missing data? - */ - if (! $content instanceof stdClass || ! isset($content->Values)) { + // Missing data? + if (!$content instanceof stdClass || !isset($content->Values)) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Data is missing "' . $response->getBody()->getContents() . '"'); } - /* - * Convert the values, to something useable - */ - $values = new \stdClass(); + // Convert the values, to something useable + $values = new stdClass(); $values->MatchMethod = $content->MatchMethod; foreach ($content->Values as $key => $value) { - if (is_array($value) && count($value) === 1 && isset($value[0])) { + if (\is_array($value) && \count($value) === 1 && isset($value[0])) { $values->{$key} = $value[0]; } } @@ -171,21 +186,11 @@ protected function getResult($userAgent, array $headers) return $values; } - /** - * - * @param Model\Bot $bot - * @param stdClass $resultRaw - */ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) { $bot->setIsBot(true); } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->BrowserName)) { @@ -197,11 +202,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\RenderingEngine $engine - * @param stdClass $resultRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) { if (isset($resultRaw->LayoutEngine)) { @@ -209,11 +209,6 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass } } - /** - * - * @param Model\OperatingSystem $os - * @param stdClass $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { if (isset($resultRaw->PlatformName)) { @@ -225,11 +220,6 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $res } } - /** - * - * @param Model\Device $device - * @param stdClass $resultRaw - */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { if (isset($resultRaw->HardwareVendor)) { @@ -245,34 +235,4 @@ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) $device->setIsMobile($this->getRealResult($resultRaw->IsMobile)); } } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getResult($userAgent, $headers); - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if (isset($resultRaw->IsCrawler) && $resultRaw->IsCrawler === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/Http/NeutrinoApiCom.php b/src/Provider/Http/NeutrinoApiCom.php index c05f4eb..9105dfa 100644 --- a/src/Provider/Http/NeutrinoApiCom.php +++ b/src/Provider/Http/NeutrinoApiCom.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://www.neutrinoapi.com/api/user-agent-info/ */ class NeutrinoApiCom extends AbstractHttpProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'NeutrinoApiCom'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://www.neutrinoapi.com/'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [ '/^unknown$/i', ], 'device' => [ - 'brand' => [ '/^Generic$/i', '/^generic web browser$/i', @@ -98,35 +97,60 @@ public function __construct(Client $client, $apiUserId, $apiKey) parent::__construct($client); $this->apiUserId = $apiUserId; - $this->apiKey = $apiKey; + $this->apiKey = $apiKey; } public function getVersion() { - return; + } + + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getResult($userAgent, $headers); + + // No result found? + if ($this->hasResult($resultRaw) !== true) { + throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isBot($resultRaw) === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; } /** + * @param string $userAgent * - * @param string $userAgent - * @param array $headers - * @return stdClass * @throws Exception\RequestException + * + * @return stdClass */ protected function getResult($userAgent, array $headers) { - /* - * an empty UserAgent makes no sense - */ + // an empty UserAgent makes no sense if ($userAgent == '') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } $params = [ - 'user-id' => $this->apiUserId, - 'api-key' => $this->apiKey, + 'user-id' => $this->apiUserId, + 'api-key' => $this->apiKey, 'output-format' => 'json', - 'output-case' => 'snake', + 'output-case' => 'snake', 'user-agent' => $userAgent, ]; @@ -140,7 +164,7 @@ protected function getResult($userAgent, array $headers) try { $response = $this->getResponse($request); } catch (Exception\RequestException $ex) { - /* @var $prevEx \GuzzleHttp\Exception\ClientException */ + // @var $prevEx \GuzzleHttp\Exception\ClientException $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { @@ -150,40 +174,36 @@ protected function getResult($userAgent, array $headers) throw $ex; } - /* - * no json returned? - */ + // no json returned? $contentType = $response->getHeader('Content-Type'); - if (! isset($contentType[0]) || $contentType[0] != 'application/json;charset=UTF-8') { + if (!isset($contentType[0]) || $contentType[0] != 'application/json;charset=UTF-8') { throw new Exception\RequestException('Could not get valid "application/json" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } $content = json_decode($response->getBody()->getContents()); - /* - * errors - */ + // errors if (isset($content->api_error)) { switch ($content->api_error) { - case 1: throw new Exception\RequestException('"' . $content->api_error_msg . '" response from "' . $request->getUri() . '". Response is "' . print_r($content, true) . '"'); + break; case 2: throw new Exception\LimitationExceededException('Exceeded the maximum number of request with API userId "' . $this->apiUserId . '" and key "' . $this->apiKey . '" for ' . $this->getName()); + break; default: throw new Exception\RequestException('"' . $content->api_error_msg . '" response from "' . $request->getUri() . '". Response is "' . print_r($content, true) . '"'); + break; } } - /* - * Missing data? - */ - if (! $content instanceof stdClass) { + // Missing data? + if (!$content instanceof stdClass) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } @@ -191,9 +211,6 @@ protected function getResult($userAgent, array $headers) } /** - * - * @param stdClass $resultRaw - * * @return bool */ private function hasResult(stdClass $resultRaw) @@ -206,9 +223,7 @@ private function hasResult(stdClass $resultRaw) } /** - * - * @param stdClass $resultRaw - * @return boolean + * @return bool */ private function isBot(stdClass $resultRaw) { @@ -219,11 +234,6 @@ private function isBot(stdClass $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param stdClass $resultRaw - */ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) { $bot->setIsBot(true); @@ -233,11 +243,6 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) } } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->browser_name)) { @@ -249,11 +254,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\OperatingSystem $os - * @param stdClass $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { if (isset($resultRaw->operating_system_family)) { @@ -265,11 +265,6 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $res } } - /** - * - * @param Model\Device $device - * @param stdClass $resultRaw - */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { if (isset($resultRaw->mobile_model)) { @@ -288,40 +283,4 @@ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) $device->setIsMobile(true); } } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getResult($userAgent, $headers); - - /* - * No result found? - */ - if ($this->hasResult($resultRaw) !== true) { - throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isBot($resultRaw) === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/Http/UdgerCom.php b/src/Provider/Http/UdgerCom.php index 1b51ba6..659c2db 100644 --- a/src/Provider/Http/UdgerCom.php +++ b/src/Provider/Http/UdgerCom.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://udger.com/support/documentation/?doc=38 */ class UdgerCom extends AbstractHttpProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'UdgerCom'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://udger.com/'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; @@ -81,28 +82,49 @@ public function __construct(Client $client, $apiKey) public function getVersion() { - return; + } + + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getResult($userAgent, $headers); + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isBot($resultRaw->info) === true) { + $this->hydrateBot($result->getBot(), $resultRaw->info); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw->info); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw->info); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->info); + $this->hydrateDevice($result->getDevice(), $resultRaw->info); + + return $result; } /** + * @param string $userAgent * - * @param string $userAgent - * @param array $headers - * @return stdClass * @throws Exception\RequestException + * + * @return stdClass */ protected function getResult($userAgent, array $headers) { - /* - * an empty UserAgent makes no sense - */ + // an empty UserAgent makes no sense if ($userAgent == '') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } $params = [ 'accesskey' => $this->apiKey, - 'uastrig' => $userAgent, + 'uastrig' => $userAgent, ]; $body = http_build_query($params, null, '&'); @@ -113,26 +135,20 @@ protected function getResult($userAgent, array $headers) $response = $this->getResponse($request); - /* - * no json returned? - */ + // no json returned? $contentType = $response->getHeader('Content-Type'); - if (! isset($contentType[0]) || $contentType[0] != 'application/json') { + if (!isset($contentType[0]) || $contentType[0] != 'application/json') { throw new Exception\RequestException('Could not get valid "application/json" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } $content = json_decode($response->getBody()->getContents()); - /* - * No result found? - */ + // No result found? if (isset($content->flag) && $content->flag == 3) { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } - /* - * Errors - */ + // Errors if (isset($content->flag) && $content->flag == 4) { throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName()); } @@ -145,10 +161,8 @@ protected function getResult($userAgent, array $headers) throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } - /* - * Missing data? - */ - if (! $content instanceof stdClass || ! isset($content->info)) { + // Missing data? + if (!$content instanceof stdClass || !isset($content->info)) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } @@ -156,9 +170,7 @@ protected function getResult($userAgent, array $headers) } /** - * - * @param stdClass $resultRaw - * @return boolean + * @return bool */ private function isBot(stdClass $resultRaw) { @@ -169,11 +181,6 @@ private function isBot(stdClass $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param stdClass $resultRaw - */ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) { $bot->setIsBot(true); @@ -183,11 +190,6 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) } } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->ua_family)) { @@ -199,11 +201,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\RenderingEngine $engine - * @param stdClass $resultRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) { if (isset($resultRaw->ua_engine)) { @@ -211,11 +208,6 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass } } - /** - * - * @param Model\OperatingSystem $os - * @param stdClass $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { if (isset($resultRaw->os_family)) { @@ -223,45 +215,10 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $res } } - /** - * - * @param Model\Device $device - * @param stdClass $resultRaw - */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { if (isset($resultRaw->device_name)) { $device->setType($this->getRealResult($resultRaw->device_name)); } } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getResult($userAgent, $headers); - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isBot($resultRaw->info) === true) { - $this->hydrateBot($result->getBot(), $resultRaw->info); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw->info); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw->info); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->info); - $this->hydrateDevice($result->getDevice(), $resultRaw->info); - - return $result; - } } diff --git a/src/Provider/Http/UserAgentApiCom.php b/src/Provider/Http/UserAgentApiCom.php index 67e4a01..72f7c70 100644 --- a/src/Provider/Http/UserAgentApiCom.php +++ b/src/Provider/Http/UserAgentApiCom.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://useragentapi.com/docs */ class UserAgentApiCom extends AbstractHttpProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'UserAgentApiCom'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'http://useragentapi.com/'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; @@ -75,21 +76,41 @@ public function __construct(Client $client, $apiKey) public function getVersion() { - return; + } + + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getResult($userAgent, $headers); + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isBot($resultRaw) === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; } /** + * @param string $userAgent * - * @param string $userAgent - * @param array $headers - * @return stdClass * @throws Exception\RequestException + * + * @return stdClass */ protected function getResult($userAgent, array $headers) { - /* - * an empty UserAgent makes no sense - */ + // an empty UserAgent makes no sense if ($userAgent == '') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } @@ -104,7 +125,7 @@ protected function getResult($userAgent, array $headers) try { $response = $this->getResponse($request); } catch (Exception\RequestException $ex) { - /* @var $prevEx \GuzzleHttp\Exception\ClientException */ + // @var $prevEx \GuzzleHttp\Exception\ClientException $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 400) { @@ -113,9 +134,7 @@ protected function getResult($userAgent, array $headers) ->getContents(); $content = json_decode($content); - /* - * Error - */ + // Error if (isset($content->error->code) && $content->error->code == 'key_invalid') { throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), null, $ex); } @@ -128,27 +147,21 @@ protected function getResult($userAgent, array $headers) throw $ex; } - /* - * no json returned? - */ + // no json returned? $contentType = $response->getHeader('Content-Type'); - if (! isset($contentType[0]) || $contentType[0] != 'application/json') { + if (!isset($contentType[0]) || $contentType[0] != 'application/json') { throw new Exception\RequestException('Could not get valid "application/json" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } $content = json_decode($response->getBody()->getContents()); - /* - * No result - */ + // No result if (isset($content->error->code) && $content->error->code == 'useragent_not_found') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } - /* - * Missing data? - */ - if (! $content instanceof stdClass || ! isset($content->data)) { + // Missing data? + if (!$content instanceof stdClass || !isset($content->data)) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Data is missing "' . $response->getBody()->getContents() . '"'); } @@ -156,9 +169,7 @@ protected function getResult($userAgent, array $headers) } /** - * - * @param stdClass $resultRaw - * @return boolean + * @return bool */ private function isBot(stdClass $resultRaw) { @@ -169,11 +180,6 @@ private function isBot(stdClass $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param stdClass $resultRaw - */ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) { $bot->setIsBot(true); @@ -183,11 +189,6 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) } } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->browser_name)) { @@ -199,11 +200,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\RenderingEngine $engine - * @param stdClass $resultRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) { if (isset($resultRaw->engine_name)) { @@ -215,44 +211,10 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass } } - /** - * - * @param Model\Device $device - * @param stdClass $resultRaw - */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { if (isset($resultRaw->platform_type)) { $device->setType($this->getRealResult($resultRaw->platform_type)); } } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getResult($userAgent, $headers); - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isBot($resultRaw) === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/Http/WhatIsMyBrowserCom.php b/src/Provider/Http/WhatIsMyBrowserCom.php index c224069..668f0da 100644 --- a/src/Provider/Http/WhatIsMyBrowserCom.php +++ b/src/Provider/Http/WhatIsMyBrowserCom.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://developers.whatismybrowser.com/reference */ class WhatIsMyBrowserCom extends AbstractHttpProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'WhatIsMyBrowserCom'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://www.whatismybrowser.com/'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], @@ -51,20 +52,19 @@ class WhatIsMyBrowserCom extends AbstractHttpProvider 'model' => true, 'brand' => true, - 'type' => true, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ]; protected $defaultValues = [ - 'general' => [], 'browser' => [ @@ -107,27 +107,53 @@ public function __construct(Client $client, $apiKey) public function getVersion() { - return; + } + + public function parse($userAgent, array $headers = []) + { + $resultRaw = $this->getResult($userAgent, $headers); + + // No result found? + if ($this->hasResult($resultRaw) !== true) { + throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isBot($resultRaw) === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; } /** + * @param string $userAgent * - * @param string $userAgent - * @param array $headers - * @return stdClass * @throws Exception\RequestException + * + * @return stdClass */ protected function getResult($userAgent, array $headers) { - /* - * an empty UserAgent makes no sense - */ + // an empty UserAgent makes no sense if ($userAgent == '') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } $params = [ - 'user_key' => $this->apiKey, + 'user_key' => $this->apiKey, 'user_agent' => $userAgent, ]; @@ -137,33 +163,25 @@ protected function getResult($userAgent, array $headers) $response = $this->getResponse($request); - /* - * no json returned? - */ + // no json returned? $contentType = $response->getHeader('Content-Type'); - if (! isset($contentType[0]) || $contentType[0] != 'application/json') { + if (!isset($contentType[0]) || $contentType[0] != 'application/json') { throw new Exception\RequestException('Could not get valid "application/json" response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } $content = json_decode($response->getBody()->getContents()); - /* - * No result - */ + // No result if (isset($content->message_code) && $content->message_code == 'no_user_agent') { throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); } - /* - * Limit exceeded - */ + // Limit exceeded if (isset($content->message_code) && $content->message_code == 'usage_limit_exceeded') { throw new Exception\LimitationExceededException('Exceeded the maximum number of request with API key "' . $this->apiKey . '" for ' . $this->getName()); } - /* - * Error - */ + // Error if (isset($content->message_code) && $content->message_code == 'no_api_user_key') { throw new Exception\InvalidCredentialsException('Missing API key for ' . $this->getName()); } @@ -172,14 +190,12 @@ protected function getResult($userAgent, array $headers) throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName()); } - if (! isset($content->result) || $content->result !== 'success') { + if (!isset($content->result) || $content->result !== 'success') { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Response is "' . $response->getBody()->getContents() . '"'); } - /* - * Missing data? - */ - if (! $content instanceof stdClass || ! isset($content->parse) || ! $content->parse instanceof stdClass) { + // Missing data? + if (!$content instanceof stdClass || !isset($content->parse) || !$content->parse instanceof stdClass) { throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '". Response is "' . print_r($content, true) . '"'); } @@ -187,9 +203,6 @@ protected function getResult($userAgent, array $headers) } /** - * - * @param stdClass $resultRaw - * * @return bool */ private function hasResult(stdClass $resultRaw) @@ -218,9 +231,7 @@ private function hasResult(stdClass $resultRaw) } /** - * - * @param stdClass $resultRaw - * @return boolean + * @return bool */ private function isBot(stdClass $resultRaw) { @@ -231,11 +242,6 @@ private function isBot(stdClass $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param stdClass $resultRaw - */ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) { $bot->setIsBot(true); @@ -249,11 +255,6 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) } } - /** - * - * @param Model\Browser $browser - * @param stdClass $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { if (isset($resultRaw->browser_name)) { @@ -265,11 +266,6 @@ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) } } - /** - * - * @param Model\RenderingEngine $engine - * @param stdClass $resultRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) { if (isset($resultRaw->layout_engine_name)) { @@ -281,11 +277,6 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass } } - /** - * - * @param Model\OperatingSystem $os - * @param stdClass $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { if (isset($resultRaw->operating_system_name)) { @@ -297,11 +288,6 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $res } } - /** - * - * @param Model\Device $device - * @param stdClass $resultRaw - */ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) { if (isset($resultRaw->operating_platform)) { @@ -316,41 +302,4 @@ private function hydrateDevice(Model\Device $device, stdClass $resultRaw) $device->setType($this->getRealResult($resultRaw->hardware_type)); } } - - public function parse($userAgent, array $headers = []) - { - $resultRaw = $this->getResult($userAgent, $headers); - - /* - * No result found? - */ - if ($this->hasResult($resultRaw) !== true) { - throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isBot($resultRaw) === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw); - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/JenssegersAgent.php b/src/Provider/JenssegersAgent.php index 2622505..e97bc23 100644 --- a/src/Provider/JenssegersAgent.php +++ b/src/Provider/JenssegersAgent.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/jenssegers/agent */ class JenssegersAgent extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'JenssegersAgent'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/jenssegers/agent'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'jenssegers/agent'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [], 'browser' => [ @@ -80,14 +80,13 @@ class JenssegersAgent extends AbstractProvider ]; /** - * Used for unitTests mocking + * Used for unitTests mocking. * * @var Agent */ private $parser; /** - * * @throws PackageNotLoadedException */ public function __construct() @@ -96,7 +95,6 @@ public function __construct() } /** - * * @return Agent */ public function getParser() @@ -108,10 +106,58 @@ public function getParser() return new Agent(); } + public function parse($userAgent, array $headers = []) + { + $parser = $this->getParser(); + $parser->setHttpHeaders($headers); + $parser->setUserAgent($userAgent); + + /* + * Since Mobile_Detect to a regex comparison on every call + * We cache it here for all checks and hydration + */ + $browserName = $parser->browser(); + $osName = $parser->platform(); + + $resultCache = [ + 'browserName' => $browserName, + 'browserVersion' => $parser->version($browserName), + + 'osName' => $osName, + 'osVersion' => $parser->version($osName), + + 'deviceModel' => $parser->device(), + 'isMobile' => $parser->isMobile(), + + 'isRobot' => $parser->isRobot(), + 'botName' => $parser->robot(), + ]; + + // No result found? + if ($this->hasResult($resultCache) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultCache); + + // Bot detection + if ($resultCache['isRobot'] === true) { + $this->hydrateBot($result->getBot(), $resultCache); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultCache); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultCache); + $this->hydrateDevice($result->getDevice(), $resultCache); + + return $result; + } + /** - * - * @param array $resultRaw - * * @return bool */ private function hasResult(array $resultRaw) @@ -127,22 +173,12 @@ private function hasResult(array $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param array $resultRaw - */ private function hydrateBot(Model\Bot $bot, array $resultRaw) { $bot->setIsBot(true); $bot->setName($this->getRealResult($resultRaw['botName'])); } - /** - * - * @param Model\Browser $browser - * @param array $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) { if ($this->isRealResult($resultRaw['browserName'], 'browser', 'name') === true) { @@ -151,11 +187,6 @@ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) } } - /** - * - * @param Model\OperatingSystem $os - * @param array $resultRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, array $resultRaw) { if ($this->isRealResult($resultRaw['osName']) === true) { @@ -164,74 +195,10 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, array $result } } - /** - * - * @param Model\Device $device - * @param array $resultRaw - */ private function hydrateDevice(Model\Device $device, array $resultRaw) { if ($resultRaw['isMobile'] === true) { $device->setIsMobile(true); } } - - public function parse($userAgent, array $headers = []) - { - $parser = $this->getParser(); - $parser->setHttpHeaders($headers); - $parser->setUserAgent($userAgent); - - /* - * Since Mobile_Detect to a regex comparison on every call - * We cache it here for all checks and hydration - */ - $browserName = $parser->browser(); - $osName = $parser->platform(); - - $resultCache = [ - 'browserName' => $browserName, - 'browserVersion' => $parser->version($browserName), - - 'osName' => $osName, - 'osVersion' => $parser->version($osName), - - 'deviceModel' => $parser->device(), - 'isMobile' => $parser->isMobile(), - - 'isRobot' => $parser->isRobot(), - 'botName' => $parser->robot(), - ]; - - /* - * No result found? - */ - if ($this->hasResult($resultCache) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultCache); - - /* - * Bot detection - */ - if ($resultCache['isRobot'] === true) { - $this->hydrateBot($result->getBot(), $resultCache); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultCache); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultCache); - $this->hydrateDevice($result->getDevice(), $resultCache); - - return $result; - } } diff --git a/src/Provider/PiwikDeviceDetector.php b/src/Provider/PiwikDeviceDetector.php index 875c041..07ea1a2 100644 --- a/src/Provider/PiwikDeviceDetector.php +++ b/src/Provider/PiwikDeviceDetector.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/piwik/device-detector */ class PiwikDeviceDetector extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'PiwikDeviceDetector'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/piwik/device-detector'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'piwik/device-detector'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ]; protected $defaultValues = [ - 'general' => [ '/^UNK$/i', ], @@ -83,14 +83,13 @@ class PiwikDeviceDetector extends AbstractProvider ]; /** - * * @var DeviceDetector */ private $parser; /** + * @param DeviceDetector $parser * - * @param DeviceDetector $parser * @throws PackageNotLoadedException */ public function __construct(DeviceDetector $parser = null) @@ -103,7 +102,6 @@ public function __construct(DeviceDetector $parser = null) } /** - * * @return DeviceDetector */ public function getParser() @@ -117,25 +115,54 @@ public function getParser() return $this->parser; } + public function parse($userAgent, array $headers = []) + { + $dd = $this->getParser(); + + $dd->setUserAgent($userAgent); + $dd->parse(); + + // No result found? + if ($this->hasResult($dd) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($this->getResultRaw($dd)); + + // Bot detection + if ($dd->isBot() === true) { + $this->hydrateBot($result->getBot(), $dd->getBot()); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $dd->getClient()); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $dd->getClient()); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $dd->getOs()); + $this->hydrateDevice($result->getDevice(), $dd); + + return $result; + } + /** - * - * @param DeviceDetector $dd - * * @return array */ private function getResultRaw(DeviceDetector $dd) { $raw = [ - 'client' => $dd->getClient(), + 'client' => $dd->getClient(), 'operatingSystem' => $dd->getOs(), 'device' => [ - 'brand' => $dd->getBrand(), + 'brand' => $dd->getBrand(), 'brandName' => $dd->getBrandName(), 'model' => $dd->getModel(), - 'device' => $dd->getDevice(), + 'device' => $dd->getDevice(), 'deviceName' => $dd->getDeviceName(), ], @@ -145,28 +172,28 @@ private function getResultRaw(DeviceDetector $dd) 'isBot' => $dd->isBot(), // client - 'isBrowser' => $dd->isBrowser(), - 'isFeedReader' => $dd->isFeedReader(), - 'isMobileApp' => $dd->isMobileApp(), - 'isPIM' => $dd->isPIM(), - 'isLibrary' => $dd->isLibrary(), + 'isBrowser' => $dd->isBrowser(), + 'isFeedReader' => $dd->isFeedReader(), + 'isMobileApp' => $dd->isMobileApp(), + 'isPIM' => $dd->isPIM(), + 'isLibrary' => $dd->isLibrary(), 'isMediaPlayer' => $dd->isMediaPlayer(), // deviceType - 'isCamera' => $dd->isCamera(), - 'isCarBrowser' => $dd->isCarBrowser(), - 'isConsole' => $dd->isConsole(), - 'isFeaturePhone' => $dd->isFeaturePhone(), - 'isPhablet' => $dd->isPhablet(), + 'isCamera' => $dd->isCamera(), + 'isCarBrowser' => $dd->isCarBrowser(), + 'isConsole' => $dd->isConsole(), + 'isFeaturePhone' => $dd->isFeaturePhone(), + 'isPhablet' => $dd->isPhablet(), 'isPortableMediaPlayer' => $dd->isPortableMediaPlayer(), - 'isSmartDisplay' => $dd->isSmartDisplay(), - 'isSmartphone' => $dd->isSmartphone(), - 'isTablet' => $dd->isTablet(), - 'isTV' => $dd->isTV(), + 'isSmartDisplay' => $dd->isSmartDisplay(), + 'isSmartphone' => $dd->isSmartphone(), + 'isTablet' => $dd->isTablet(), + 'isTV' => $dd->isTV(), // other special - 'isDesktop' => $dd->isDesktop(), - 'isMobile' => $dd->isMobile(), + 'isDesktop' => $dd->isDesktop(), + 'isMobile' => $dd->isMobile(), 'isTouchEnabled' => $dd->isTouchEnabled(), ], ]; @@ -175,9 +202,6 @@ private function getResultRaw(DeviceDetector $dd) } /** - * - * @param DeviceDetector $dd - * * @return bool */ private function hasResult(DeviceDetector $dd) @@ -204,9 +228,7 @@ private function hasResult(DeviceDetector $dd) } /** - * - * @param Model\Bot $bot - * @param array|boolean $botRaw + * @param array|bool $botRaw */ private function hydrateBot(Model\Bot $bot, $botRaw) { @@ -221,9 +243,7 @@ private function hydrateBot(Model\Bot $bot, $botRaw) } /** - * - * @param Model\Browser $browser - * @param array|string $clientRaw + * @param array|string $clientRaw */ private function hydrateBrowser(Model\Browser $browser, $clientRaw) { @@ -237,9 +257,7 @@ private function hydrateBrowser(Model\Browser $browser, $clientRaw) } /** - * - * @param Model\RenderingEngine $engine - * @param array|string $clientRaw + * @param array|string $clientRaw */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, $clientRaw) { @@ -249,9 +267,7 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, $clientRa } /** - * - * @param Model\OperatingSystem $os - * @param array|string $osRaw + * @param array|string $osRaw */ private function hydrateOperatingSystem(Model\OperatingSystem $os, $osRaw) { @@ -265,9 +281,7 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, $osRaw) } /** - * * @param Model\UserAgent $device - * @param DeviceDetector $dd */ private function hydrateDevice(Model\Device $device, DeviceDetector $dd) { @@ -283,44 +297,4 @@ private function hydrateDevice(Model\Device $device, DeviceDetector $dd) $device->setIsTouch(true); } } - - public function parse($userAgent, array $headers = []) - { - $dd = $this->getParser(); - - $dd->setUserAgent($userAgent); - $dd->parse(); - - /* - * No result found? - */ - if ($this->hasResult($dd) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($this->getResultRaw($dd)); - - /* - * Bot detection - */ - if ($dd->isBot() === true) { - $this->hydrateBot($result->getBot(), $dd->getBot()); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $dd->getClient()); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $dd->getClient()); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $dd->getOs()); - $this->hydrateDevice($result->getDevice(), $dd); - - return $result; - } } diff --git a/src/Provider/SinergiBrowserDetector.php b/src/Provider/SinergiBrowserDetector.php index 6514156..6857f9c 100644 --- a/src/Provider/SinergiBrowserDetector.php +++ b/src/Provider/SinergiBrowserDetector.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/sinergi/php-browser-detector */ class SinergiBrowserDetector extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'SinergiBrowserDetector'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/sinergi/php-browser-detector'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'sinergi/browser-detector'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => false, - 'type' => false, + 'model' => true, + 'brand' => false, + 'type' => false, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [ '/^unknown$/i', ], @@ -82,28 +82,27 @@ class SinergiBrowserDetector extends AbstractProvider ]; /** - * Used for unitTests mocking + * Used for unitTests mocking. * * @var BrowserDetector\Browser */ private $browserParser; /** - * Used for unitTests mocking + * Used for unitTests mocking. * * @var BrowserDetector\Os */ private $osParser; /** - * Used for unitTests mocking + * Used for unitTests mocking. * * @var BrowserDetector\Device */ private $deviceParser; /** - * * @throws PackageNotLoadedException */ public function __construct() @@ -112,8 +111,8 @@ public function __construct() } /** + * @param string $userAgent * - * @param string $userAgent * @return BrowserDetector\Browser */ public function getBrowserParser($userAgent) @@ -126,8 +125,8 @@ public function getBrowserParser($userAgent) } /** + * @param string $userAgent * - * @param string $userAgent * @return BrowserDetector\Os */ public function getOperatingSystemParser($userAgent) @@ -140,8 +139,8 @@ public function getOperatingSystemParser($userAgent) } /** + * @param string $userAgent * - * @param string $userAgent * @return BrowserDetector\Device */ public function getDeviceParser($userAgent) @@ -153,13 +152,44 @@ public function getDeviceParser($userAgent) return new BrowserDetector\Device($userAgent); } + public function parse($userAgent, array $headers = []) + { + $browserRaw = $this->getBrowserParser($userAgent); + $osRaw = $this->getOperatingSystemParser($userAgent); + $deviceRaw = $this->getDeviceParser($userAgent); + + // No result found? + if ($this->hasResult($browserRaw, $osRaw, $deviceRaw) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw([ + 'browser' => $browserRaw, + 'operatingSystem' => $osRaw, + 'device' => $deviceRaw, + ]); + + // Bot detection + if ($browserRaw->isRobot() === true) { + $bot = $result->getBot(); + $bot->setIsBot(true); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $browserRaw); + // renderingEngine not available + $this->hydrateOperatingSystem($result->getOperatingSystem(), $osRaw); + $this->hydrateDevice($result->getDevice(), $osRaw, $deviceRaw); + + return $result; + } + /** - * - * @param BrowserDetector\Browser $browserRaw - * @param BrowserDetector\Os $osRaw - * @param BrowserDetector\Device $deviceRaw - * - * @return boolean + * @return bool */ private function hasResult(BrowserDetector\Browser $browserRaw, BrowserDetector\Os $osRaw, BrowserDetector\Device $deviceRaw) { @@ -182,22 +212,12 @@ private function hasResult(BrowserDetector\Browser $browserRaw, BrowserDetector\ return false; } - /** - * - * @param Model\Browser $browser - * @param BrowserDetector\Browser $browserRaw - */ private function hydrateBrowser(Model\Browser $browser, BrowserDetector\Browser $browserRaw) { $browser->setName($this->getRealResult($browserRaw->getName())); $browser->getVersion()->setComplete($this->getRealResult($browserRaw->getVersion())); } - /** - * - * @param Model\OperatingSystem $os - * @param BrowserDetector\Os $osRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, BrowserDetector\Os $osRaw) { $os->setName($this->getRealResult($osRaw->getName())); @@ -205,10 +225,7 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, BrowserDetect } /** - * - * @param Model\UserAgent $device - * @param BrowserDetector\Os $osRaw - * @param BrowserDetector\Device $deviceRaw + * @param Model\UserAgent $device */ private function hydrateDevice(Model\Device $device, BrowserDetector\Os $osRaw, BrowserDetector\Device $deviceRaw) { @@ -218,48 +235,4 @@ private function hydrateDevice(Model\Device $device, BrowserDetector\Os $osRaw, $device->setIsMobile(true); } } - - public function parse($userAgent, array $headers = []) - { - $browserRaw = $this->getBrowserParser($userAgent); - $osRaw = $this->getOperatingSystemParser($userAgent); - $deviceRaw = $this->getDeviceParser($userAgent); - - /* - * No result found? - */ - if ($this->hasResult($browserRaw, $osRaw, $deviceRaw) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw([ - 'browser' => $browserRaw, - 'operatingSystem' => $osRaw, - 'device' => $deviceRaw, - ]); - - /* - * Bot detection - */ - if ($browserRaw->isRobot() === true) { - $bot = $result->getBot(); - $bot->setIsBot(true); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $browserRaw); - // renderingEngine not available - $this->hydrateOperatingSystem($result->getOperatingSystem(), $osRaw); - $this->hydrateDevice($result->getDevice(), $osRaw, $deviceRaw); - - return $result; - } } diff --git a/src/Provider/UAParser.php b/src/Provider/UAParser.php index b30c102..ef4a07e 100644 --- a/src/Provider/UAParser.php +++ b/src/Provider/UAParser.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/ua-parser/uap-php */ class UAParser extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'UAParser'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/ua-parser/uap-php'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'ua-parser/uap-php'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => false, + 'model' => true, + 'brand' => true, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [ '/^Other$/i', - ], 'device' => [ - 'brand' => [ '/^Generic/i', '/^unknown$/i', @@ -109,8 +107,8 @@ class UAParser extends AbstractProvider private $parser; /** + * @param Parser $parser * - * @param Parser $parser * @throws PackageNotLoadedException */ public function __construct(Parser $parser = null) @@ -123,7 +121,6 @@ public function __construct(Parser $parser = null) } /** - * * @return Parser */ public function getParser() @@ -137,10 +134,39 @@ public function getParser() return $this->parser; } + public function parse($userAgent, array $headers = []) + { + $parser = $this->getParser(); + + // @var $resultRaw \UAParser\Result\Client + $resultRaw = $parser->parse($userAgent); + + // No result found? + if ($this->hasResult($resultRaw) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isBot($resultRaw) === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw->ua); + // renderingEngine not available + $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->os); + $this->hydrateDevice($result->getDevice(), $resultRaw->device); + + return $result; + } + /** - * - * @param \UAParser\Result\Client $resultRaw - * * @return bool */ private function hasResult(\UAParser\Result\Client $resultRaw) @@ -165,9 +191,6 @@ private function hasResult(\UAParser\Result\Client $resultRaw) } /** - * - * @param \UAParser\Result\Client $resultRaw - * * @return bool */ private function isBot(\UAParser\Result\Client $resultRaw) @@ -179,22 +202,12 @@ private function isBot(\UAParser\Result\Client $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param \UAParser\Result\Client $resultRaw - */ private function hydrateBot(Model\Bot $bot, \UAParser\Result\Client $resultRaw) { $bot->setIsBot(true); $bot->setName($this->getRealResult($resultRaw->ua->family, 'bot', 'name')); } - /** - * - * @param Model\Browser $browser - * @param \UAParser\Result\UserAgent $uaRaw - */ private function hydrateBrowser(Model\Browser $browser, \UAParser\Result\UserAgent $uaRaw) { $browser->setName($this->getRealResult($uaRaw->family)); @@ -204,11 +217,6 @@ private function hydrateBrowser(Model\Browser $browser, \UAParser\Result\UserAge $browser->getVersion()->setPatch($this->getRealResult($uaRaw->patch)); } - /** - * - * @param Model\OperatingSystem $os - * @param \UAParser\Result\OperatingSystem $osRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, \UAParser\Result\OperatingSystem $osRaw) { $os->setName($this->getRealResult($osRaw->family)); @@ -219,53 +227,11 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, \UAParser\Res } /** - * - * @param Model\UserAgent $device - * @param \UAParser\Result\Device $deviceRaw + * @param Model\UserAgent $device */ private function hydrateDevice(Model\Device $device, \UAParser\Result\Device $deviceRaw) { $device->setModel($this->getRealResult($deviceRaw->model, 'device', 'model')); $device->setBrand($this->getRealResult($deviceRaw->brand, 'device', 'brand')); } - - public function parse($userAgent, array $headers = []) - { - $parser = $this->getParser(); - - /* @var $resultRaw \UAParser\Result\Client */ - $resultRaw = $parser->parse($userAgent); - - /* - * No result found? - */ - if ($this->hasResult($resultRaw) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isBot($resultRaw) === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw->ua); - // renderingEngine not available - $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->os); - $this->hydrateDevice($result->getDevice(), $resultRaw->device); - - return $result; - } } diff --git a/src/Provider/WhichBrowser.php b/src/Provider/WhichBrowser.php index 27a900b..deef63b 100644 --- a/src/Provider/WhichBrowser.php +++ b/src/Provider/WhichBrowser.php @@ -1,4 +1,5 @@ * @author Niels Leenheer * @license MIT + * * @see https://github.com/WhichBrowser/Parser */ class WhichBrowser extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'WhichBrowser'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/WhichBrowser/Parser'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'whichbrowser/parser'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; /** - * Used for unitTests mocking + * Used for unitTests mocking. * * @var WhichBrowserParser */ private $parser; /** - * * @throws PackageNotLoadedException */ public function __construct() @@ -86,8 +86,6 @@ public function __construct() } /** - * - * @param array $headers * @return WhichBrowserParser */ public function getParser(array $headers) @@ -99,22 +97,43 @@ public function getParser(array $headers) return new WhichBrowserParser($headers); } - /** - * - * @param Model\Bot $bot - * @param \WhichBrowser\Model\Browser $browserRaw - */ + public function parse($userAgent, array $headers = []) + { + $headers['User-Agent'] = $userAgent; + + $parser = $this->getParser($headers); + + // No result found? + if ($parser->isDetected() !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($parser->toArray()); + + // Bot detection + if ($parser->getType() === 'bot') { + $this->hydrateBot($result->getBot(), $parser->browser); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $parser->browser); + $this->hydrateRenderingEngine($result->getRenderingEngine(), $parser->engine); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $parser->os); + $this->hydrateDevice($result->getDevice(), $parser->device, $parser); + + return $result; + } + private function hydrateBot(Model\Bot $bot, \WhichBrowser\Model\Browser $browserRaw) { $bot->setIsBot(true); $bot->setName($this->getRealResult($browserRaw->getName())); } - /** - * - * @param Model\Browser $browser - * @param \WhichBrowser\Model\Browser $browserRaw - */ private function hydrateBrowser(Model\Browser $browser, \WhichBrowser\Model\Browser $browserRaw) { if ($this->isRealResult($browserRaw->getName(), 'browser', 'name') === true) { @@ -125,7 +144,7 @@ private function hydrateBrowser(Model\Browser $browser, \WhichBrowser\Model\Brow } if (isset($browserRaw->using) && $browserRaw->using instanceof \WhichBrowser\Model\Using) { - /* @var $usingRaw \WhichBrowser\Model\Using */ + // @var $usingRaw \WhichBrowser\Model\Using $usingRaw = $browserRaw->using; if ($this->isRealResult($usingRaw->getName()) === true) { @@ -136,34 +155,18 @@ private function hydrateBrowser(Model\Browser $browser, \WhichBrowser\Model\Brow } } - /** - * - * @param Model\RenderingEngine $engine - * @param \WhichBrowser\Model\Engine $engineRaw - */ private function hydrateRenderingEngine(Model\RenderingEngine $engine, \WhichBrowser\Model\Engine $engineRaw) { $engine->setName($this->getRealResult($engineRaw->getName())); $engine->getVersion()->setComplete($this->getRealResult($engineRaw->getVersion())); } - /** - * - * @param Model\OperatingSystem $os - * @param \WhichBrowser\Model\Os $osRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, \WhichBrowser\Model\Os $osRaw) { $os->setName($this->getRealResult($osRaw->getName())); $os->getVersion()->setComplete($this->getRealResult($osRaw->getVersion())); } - /** - * - * @param Model\Device $device - * @param \WhichBrowser\Model\Device $deviceRaw - * @param WhichBrowserParser $parser - */ private function hydrateDevice(Model\Device $device, \WhichBrowser\Model\Device $deviceRaw, WhichBrowserParser $parser) { $device->setModel($this->getRealResult($deviceRaw->getModel())); @@ -174,43 +177,4 @@ private function hydrateDevice(Model\Device $device, \WhichBrowser\Model\Device $device->setIsMobile(true); } } - - public function parse($userAgent, array $headers = []) - { - $headers['User-Agent'] = $userAgent; - - $parser = $this->getParser($headers); - - /* - * No result found? - */ - if ($parser->isDetected() !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($parser->toArray()); - - /* - * Bot detection - */ - if ($parser->getType() === 'bot') { - $this->hydrateBot($result->getBot(), $parser->browser); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $parser->browser); - $this->hydrateRenderingEngine($result->getRenderingEngine(), $parser->engine); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $parser->os); - $this->hydrateDevice($result->getDevice(), $parser->device, $parser); - - return $result; - } } diff --git a/src/Provider/Woothee.php b/src/Provider/Woothee.php index db93836..5ce2fc9 100644 --- a/src/Provider/Woothee.php +++ b/src/Provider/Woothee.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/woothee/woothee-php */ class Woothee extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'Woothee'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/woothee/woothee-php'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'woothee/woothee'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [ '/^UNKNOWN$/i', ], @@ -91,7 +91,6 @@ class Woothee extends AbstractProvider private $parser; /** - * * @throws PackageNotLoadedException */ public function __construct() @@ -100,7 +99,6 @@ public function __construct() } /** - * * @return Classifier */ public function getParser() @@ -114,10 +112,38 @@ public function getParser() return $this->parser; } + public function parse($userAgent, array $headers = []) + { + $parser = $this->getParser(); + + $resultRaw = $parser->parse($userAgent); + + // No result found? + if ($this->hasResult($resultRaw) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw($resultRaw); + + // Bot detection + if ($this->isBot($resultRaw) === true) { + $this->hydrateBot($result->getBot(), $resultRaw); + + return $result; + } + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $resultRaw); + // renderingEngine not available + // operatingSystem filled OS is mixed! Examples: iPod, iPhone, Android... + $this->hydrateDevice($result->getDevice(), $resultRaw); + + return $result; + } + /** - * - * @param array $resultRaw - * * @return bool */ private function hasResult(array $resultRaw) @@ -134,9 +160,7 @@ private function hasResult(array $resultRaw) } /** - * - * @param array $resultRaw - * @return boolean + * @return bool */ private function isBot(array $resultRaw) { @@ -147,11 +171,6 @@ private function isBot(array $resultRaw) return false; } - /** - * - * @param Model\Bot $bot - * @param array $resultRaw - */ private function hydrateBot(Model\Bot $bot, array $resultRaw) { $bot->setIsBot(true); @@ -161,11 +180,6 @@ private function hydrateBot(Model\Bot $bot, array $resultRaw) } } - /** - * - * @param Model\Browser $browser - * @param array $resultRaw - */ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) { if (isset($resultRaw['name'])) { @@ -177,54 +191,10 @@ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) } } - /** - * - * @param Model\Device $device - * @param array $resultRaw - */ private function hydrateDevice(Model\Device $device, array $resultRaw) { if (isset($resultRaw['category'])) { $device->setType($this->getRealResult($resultRaw['category'], 'device', 'type')); } } - - public function parse($userAgent, array $headers = []) - { - $parser = $this->getParser(); - - $resultRaw = $parser->parse($userAgent); - - /* - * No result found? - */ - if ($this->hasResult($resultRaw) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw($resultRaw); - - /* - * Bot detection - */ - if ($this->isBot($resultRaw) === true) { - $this->hydrateBot($result->getBot(), $resultRaw); - - return $result; - } - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $resultRaw); - // renderingEngine not available - // operatingSystem filled OS is mixed! Examples: iPod, iPhone, Android... - $this->hydrateDevice($result->getDevice(), $resultRaw); - - return $result; - } } diff --git a/src/Provider/Zsxsoft.php b/src/Provider/Zsxsoft.php index de4e62e..c634206 100644 --- a/src/Provider/Zsxsoft.php +++ b/src/Provider/Zsxsoft.php @@ -1,4 +1,5 @@ * @license MIT + * * @see https://github.com/zsxsoft/php-useragent */ class Zsxsoft extends AbstractProvider { /** - * Name of the provider + * Name of the provider. * * @var string */ protected $name = 'Zsxsoft'; /** - * Homepage of the provider + * Homepage of the provider. * * @var string */ protected $homepage = 'https://github.com/zsxsoft/php-useragent'; /** - * Composer package name + * Composer package name. * * @var string */ protected $packageName = 'zsxsoft/php-useragent'; protected $detectionCapabilities = [ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => false, + 'model' => true, + 'brand' => true, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ]; protected $defaultValues = [ - 'general' => [ '/^Unknown$/i', ], @@ -91,8 +91,8 @@ class Zsxsoft extends AbstractProvider private $parser; /** + * @param UserAgent $parser * - * @param UserAgent $parser * @throws PackageNotLoadedException */ public function __construct(UserAgent $parser = null) @@ -105,7 +105,6 @@ public function __construct(UserAgent $parser = null) } /** - * * @return UserAgent */ public function getParser() @@ -119,12 +118,39 @@ public function getParser() return $this->parser; } + public function parse($userAgent, array $headers = []) + { + $parser = $this->getParser(); + $parser->analyze($userAgent); + + $browser = $parser->browser; + $os = $parser->os; + $device = $parser->device; + $platform = $parser->platform; + + // No result found? + if ($this->hasResult($browser, $os, $device) !== true) { + throw new NoResultFoundException('No result found for user agent: ' . $userAgent); + } + + // Hydrate the model + $result = new Model\UserAgent($this->getName(), $this->getVersion()); + $result->setProviderResultRaw([ + 'browser' => $browser, + 'os' => $os, + 'device' => $device, + 'platform' => $platform, + ]); + + // hydrate the result + $this->hydrateBrowser($result->getBrowser(), $browser); + $this->hydrateOperatingSystem($result->getOperatingSystem(), $os); + $this->hydrateDevice($result->getDevice(), $device); + + return $result; + } + /** - * - * @param array $browser - * @param array $os - * @param array $device - * * @return bool */ private function hasResult(array $browser, array $os, array $device) @@ -148,11 +174,6 @@ private function hasResult(array $browser, array $os, array $device) return false; } - /** - * - * @param Model\Browser $browser - * @param array $browserRaw - */ private function hydrateBrowser(Model\Browser $browser, array $browserRaw) { if (isset($browserRaw['name'])) { @@ -164,11 +185,6 @@ private function hydrateBrowser(Model\Browser $browser, array $browserRaw) } } - /** - * - * @param Model\OperatingSystem $os - * @param array $osRaw - */ private function hydrateOperatingSystem(Model\OperatingSystem $os, array $osRaw) { if (isset($osRaw['name'])) { @@ -180,11 +196,6 @@ private function hydrateOperatingSystem(Model\OperatingSystem $os, array $osRaw) } } - /** - * - * @param Model\Device $device - * @param array $deviceRaw - */ private function hydrateDevice(Model\Device $device, array $deviceRaw) { if (isset($deviceRaw['model'])) { @@ -195,42 +206,4 @@ private function hydrateDevice(Model\Device $device, array $deviceRaw) $device->setBrand($this->getRealResult($deviceRaw['brand'])); } } - - public function parse($userAgent, array $headers = []) - { - $parser = $this->getParser(); - $parser->analyze($userAgent); - - $browser = $parser->browser; - $os = $parser->os; - $device = $parser->device; - $platform = $parser->platform; - - /* - * No result found? - */ - if ($this->hasResult($browser, $os, $device) !== true) { - throw new NoResultFoundException('No result found for user agent: ' . $userAgent); - } - - /* - * Hydrate the model - */ - $result = new Model\UserAgent($this->getName(), $this->getVersion()); - $result->setProviderResultRaw([ - 'browser' => $browser, - 'os' => $os, - 'device' => $device, - 'platform' => $platform, - ]); - - /* - * hydrate the result - */ - $this->hydrateBrowser($result->getBrowser(), $browser); - $this->hydrateOperatingSystem($result->getOperatingSystem(), $os); - $this->hydrateDevice($result->getDevice(), $device); - - return $result; - } } diff --git a/tests/integration/Provider/AbstractBrowscapTestCase.php b/tests/integration/Provider/AbstractBrowscapTestCase.php index feda01c..8cd6305 100644 --- a/tests/integration/Provider/AbstractBrowscapTestCase.php +++ b/tests/integration/Provider/AbstractBrowscapTestCase.php @@ -1,14 +1,16 @@ * @license MIT + * + * @internal + * @coversNothing */ class AbstractBrowscapTestCase extends AbstractProviderTestCase { diff --git a/tests/integration/Provider/AbstractProviderTestCase.php b/tests/integration/Provider/AbstractProviderTestCase.php index b34f7c1..3cf9899 100644 --- a/tests/integration/Provider/AbstractProviderTestCase.php +++ b/tests/integration/Provider/AbstractProviderTestCase.php @@ -1,11 +1,10 @@ * @license MIT */ diff --git a/tests/integration/Provider/BrowscapFullTest.php b/tests/integration/Provider/BrowscapFullTest.php index 74160a8..48dc8c9 100644 --- a/tests/integration/Provider/BrowscapFullTest.php +++ b/tests/integration/Provider/BrowscapFullTest.php @@ -1,42 +1,40 @@ * @license MIT * * @coversNothing + * + * @internal */ class BrowscapFullTest extends AbstractBrowscapTestCase { public function testMethodParse() { $provider = new BrowscapFull($this->getParserWithWarmCache('full')); - $parser = $provider->getParser(); + $parser = $provider->getParser(); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('getBrowser'), 'method getBrowser() does not exist anymore'); - /* - * test paramters - */ - $method = $class->getMethod('getBrowser'); + // test paramters + $method = $class->getMethod('getBrowser'); $parameters = $method->getParameters(); - $this->assertEquals(1, count($parameters)); + $this->assertEquals(1, \count($parameters)); } public function testMethodsResult() { $provider = new BrowscapFull($this->getParserWithWarmCache('full')); - $parser = $provider->getParser(); + $parser = $provider->getParser(); - /* @var $result \stdClass */ + // @var $result \stdClass $result = $parser->getBrowser('A real user agent...'); $this->assertInstanceOf('stdClass', $result); @@ -77,7 +75,7 @@ public function testRealResultBot() $result = $provider->parse('Mozilla/2.0 (compatible; Ask Jeeves)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -89,7 +87,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -101,7 +99,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -115,21 +113,19 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'AskJeeves', - 'type' => 'Bot/Crawler', + 'name' => 'AskJeeves', + 'type' => 'Bot/Crawler', ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -148,7 +144,7 @@ public function testRealResultDevice() $result = $provider->parse('Mozilla/5.0 (SMART-TV; X11; Linux armv7l) AppleWebkit/537.42 (KHTML, like Gecko) Chromium/48.0.1349.2 Chrome/25.0.1349.2 Safari/537.42'); $this->assertEquals([ 'browser' => [ - 'name' => 'Chromium', + 'name' => 'Chromium', 'version' => [ 'major' => 48, 'minor' => null, @@ -160,7 +156,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'Blink', + 'name' => 'Blink', 'version' => [ 'major' => null, 'minor' => null, @@ -172,7 +168,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'Linux', + 'name' => 'Linux', 'version' => [ 'major' => null, 'minor' => null, @@ -186,21 +182,19 @@ public function testRealResultDevice() 'device' => [ 'model' => 'Smart TV', 'brand' => 'Samsung', - 'type' => 'TV Device', + 'type' => 'TV Device', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); diff --git a/tests/integration/Provider/BrowscapLiteTest.php b/tests/integration/Provider/BrowscapLiteTest.php index c2036e5..0304804 100644 --- a/tests/integration/Provider/BrowscapLiteTest.php +++ b/tests/integration/Provider/BrowscapLiteTest.php @@ -1,15 +1,16 @@ * @license MIT * * @coversNothing + * + * @internal */ class BrowscapLiteTest extends AbstractBrowscapTestCase { @@ -42,7 +43,7 @@ public function testRealResultDevice() $this->assertEquals([ 'browser' => [ - 'name' => 'Chromium', + 'name' => 'Chromium', 'version' => [ 'major' => 48, 'minor' => null, @@ -54,7 +55,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -66,7 +67,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'Linux', + 'name' => 'Linux', 'version' => [ 'major' => null, 'minor' => null, @@ -80,15 +81,15 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'TV Device', + 'type' => 'TV Device', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/BrowscapPhpTest.php b/tests/integration/Provider/BrowscapPhpTest.php index f471616..84e1eef 100644 --- a/tests/integration/Provider/BrowscapPhpTest.php +++ b/tests/integration/Provider/BrowscapPhpTest.php @@ -1,15 +1,16 @@ * @license MIT * * @coversNothing + * + * @internal */ class BrowscapPhpTest extends AbstractBrowscapTestCase { @@ -30,7 +31,7 @@ public function testRealResultBot() $result = $provider->parse('Mozilla/2.0 (compatible; Ask Jeeves)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -42,7 +43,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -54,7 +55,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -68,15 +69,15 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'AskJeeves', - 'type' => null, + 'name' => 'AskJeeves', + 'type' => null, ], ], $result->toArray()); } @@ -88,7 +89,7 @@ public function testRealResultDevice() $result = $provider->parse('Mozilla/5.0 (SMART-TV; X11; Linux armv7l) AppleWebkit/537.42 (KHTML, like Gecko) Chromium/48.0.1349.2 Chrome/25.0.1349.2 Safari/537.42'); $this->assertEquals([ 'browser' => [ - 'name' => 'Chromium', + 'name' => 'Chromium', 'version' => [ 'major' => 48, 'minor' => null, @@ -100,7 +101,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -112,7 +113,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'Linux', + 'name' => 'Linux', 'version' => [ 'major' => null, 'minor' => null, @@ -126,15 +127,15 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'TV Device', + 'type' => 'TV Device', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/ChainTest.php b/tests/integration/Provider/ChainTest.php index 8171f96..4c8fe65 100644 --- a/tests/integration/Provider/ChainTest.php +++ b/tests/integration/Provider/ChainTest.php @@ -1,4 +1,5 @@ * @license MIT * @coversNothing + * + * @internal */ class ChainTest extends AbstractProviderTestCase { @@ -27,7 +29,7 @@ public function testNoResultFoundSingleProvider() } /** - * Also with multiple providers the excepction must be thrown + * Also with multiple providers the excepction must be thrown. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -55,7 +57,7 @@ public function testRealResultSingleProvider() } /** - * This test makes sure, that the chain provider go to the next provider when no result is found + * This test makes sure, that the chain provider go to the next provider when no result is found. */ public function testRealResultTwoProviderSecondUsed() { @@ -72,7 +74,7 @@ public function testRealResultTwoProviderSecondUsed() } /** - * This test makes sure, that the chain provider stops when a result is found + * This test makes sure, that the chain provider stops when a result is found. */ public function testRealResultThreeProviderSecondUsed() { diff --git a/tests/integration/Provider/DonatjUAParserTest.php b/tests/integration/Provider/DonatjUAParserTest.php index 10c6ba5..6dff1f1 100644 --- a/tests/integration/Provider/DonatjUAParserTest.php +++ b/tests/integration/Provider/DonatjUAParserTest.php @@ -1,15 +1,16 @@ * @license MIT * * @coversNothing + * + * @internal */ class DonatjUAParserTest extends AbstractProviderTestCase { @@ -30,7 +31,7 @@ public function testRealResult() $result = $provider->parse('Mozilla/5.0 (X11; U; CrOS i686 0.9.128; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.339'); $this->assertEquals([ 'browser' => [ - 'name' => 'Chrome', + 'name' => 'Chrome', 'version' => [ 'major' => 8, 'minor' => 0, @@ -42,7 +43,7 @@ public function testRealResult() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -54,7 +55,7 @@ public function testRealResult() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -68,27 +69,25 @@ public function testRealResult() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ 'platform' => 'Chrome OS', - 'browser' => 'Chrome', - 'version' => '8.0.552.339', + 'browser' => 'Chrome', + 'version' => '8.0.552.339', ], $rawResult); } } diff --git a/tests/integration/Provider/EndorphinTest.php b/tests/integration/Provider/EndorphinTest.php index eb0a9ef..b9264eb 100644 --- a/tests/integration/Provider/EndorphinTest.php +++ b/tests/integration/Provider/EndorphinTest.php @@ -1,14 +1,16 @@ * @license MIT * * @coversNothing + * + * @internal */ class EndorphinTest extends AbstractProviderTestCase { @@ -29,7 +31,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.googlebot.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -41,7 +43,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -53,7 +55,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -67,21 +69,19 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Google (Search)', - 'type' => 'Search Engine', + 'name' => 'Google (Search)', + 'type' => 'Search Engine', ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('EndorphinStudio\Detector\DetectorResult', $rawResult); @@ -99,7 +99,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 7534, 'minor' => 48, @@ -111,7 +111,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -123,7 +123,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'Mac OS X', + 'name' => 'Mac OS X', 'version' => [ 'major' => null, 'minor' => null, @@ -137,15 +137,15 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/HandsetDetectionTest.php b/tests/integration/Provider/HandsetDetectionTest.php index a8b3adf..ccb027b 100644 --- a/tests/integration/Provider/HandsetDetectionTest.php +++ b/tests/integration/Provider/HandsetDetectionTest.php @@ -1,39 +1,20 @@ * @license MIT * * @coversNothing + * + * @internal */ class HandsetDetectionTest extends AbstractProviderTestCase { - private function getParser() - { - $config = [ - 'username' => 'something', - 'secret' => 'something', - - 'use_local' => true, - 'filesdir' => 'tests/resources/handset-detection', - - 'log_unknown' => false, - - 'cache' => [ - 'none' => true, - ], - ]; - - $parser = new Parser\HD4($config); - - return $parser; - } - /** * @expectedException \UserAgentParser\Exception\InvalidArgumentException */ @@ -41,10 +22,10 @@ public function testNoResourcesAvailable() { $config = [ 'username' => 'something', - 'secret' => 'something', + 'secret' => 'something', 'use_local' => true, - 'filesdir' => 'tests', + 'filesdir' => 'tests', 'log_unknown' => false, @@ -77,7 +58,7 @@ public function testRealResult() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Mobile Safari', + 'name' => 'Mobile Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -89,7 +70,7 @@ public function testRealResult() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -101,7 +82,7 @@ public function testRealResult() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -115,21 +96,19 @@ public function testRealResult() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInternalType('array', $rawResult); @@ -144,4 +123,25 @@ public function testRealResult() $this->assertArrayHasKey('general_browser', $rawResult); $this->assertArrayHasKey('general_browser_version', $rawResult); } + + private function getParser() + { + $config = [ + 'username' => 'something', + 'secret' => 'something', + + 'use_local' => true, + 'filesdir' => 'tests/resources/handset-detection', + + 'log_unknown' => false, + + 'cache' => [ + 'none' => true, + ], + ]; + + $parser = new Parser\HD4($config); + + return $parser; + } } diff --git a/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php b/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php index 115ef0d..8a7d1f6 100644 --- a/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php +++ b/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php @@ -1,4 +1,5 @@ move test/client.php.dist to test/client.php and define your things! - */ + // If you need an alternativ client to test the integration -> move test/client.php.dist to test/client.php and define your things! if (file_exists('tests/client.php')) { $client = include 'tests/client.php'; @@ -32,14 +29,13 @@ public function setUp() } /** - * * @return Client */ protected function getClient() { if ($this->client === null) { $handler = new CurlHandler(); - $stack = HandlerStack::create($handler); + $stack = HandlerStack::create($handler); $this->client = new Client([ 'handler' => $stack, diff --git a/tests/integration/Provider/Http/DeviceAtlasComTest.php b/tests/integration/Provider/Http/DeviceAtlasComTest.php index 941dfbd..ad7a46f 100644 --- a/tests/integration/Provider/Http/DeviceAtlasComTest.php +++ b/tests/integration/Provider/Http/DeviceAtlasComTest.php @@ -1,10 +1,13 @@ markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -35,7 +38,7 @@ public function testNoResultFound() public function testRealResultDevice() { - if (! defined('CREDENTIALS_DEVICE_ATLAS_COM_KEY')) { + if (!\defined('CREDENTIALS_DEVICE_ATLAS_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -44,7 +47,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -56,7 +59,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => null, 'minor' => null, @@ -68,7 +71,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -82,21 +85,19 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'Mobile Phone', + 'type' => 'Mobile Phone', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -112,14 +113,14 @@ public function testRealResultDevice() public function testEncodeIsCorrect() { - if (! defined('CREDENTIALS_DEVICE_ATLAS_COM_KEY')) { + if (!\defined('CREDENTIALS_DEVICE_ATLAS_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } $provider = new DeviceAtlasCom($this->getClient(), CREDENTIALS_DEVICE_ATLAS_COM_KEY); $userAgent = 'Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; HTC T9299+ For AT&T Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; - $result = $provider->parse($userAgent); + $result = $provider->parse($userAgent); $this->assertEquals('WebKit', $result->getRenderingEngine() ->getName()); diff --git a/tests/integration/Provider/Http/FiftyOneDegreesComTest.php b/tests/integration/Provider/Http/FiftyOneDegreesComTest.php index 9cdcf56..8e48682 100644 --- a/tests/integration/Provider/Http/FiftyOneDegreesComTest.php +++ b/tests/integration/Provider/Http/FiftyOneDegreesComTest.php @@ -1,10 +1,13 @@ markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -39,7 +42,7 @@ public function testNoResultFound() public function testRealResultBot() { - if (! defined('CREDENTIALS_FIFTYONE_DEGREES_COM_KEY')) { + if (!\defined('CREDENTIALS_FIFTYONE_DEGREES_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -48,7 +51,7 @@ public function testRealResultBot() $result = $provider->parse('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0); 360Spider(compatible; HaosouSpider; http://www.haosou.com/help/help_3_2.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -60,7 +63,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -72,7 +75,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -86,22 +89,22 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } public function testRealResultDevice() { - if (! defined('CREDENTIALS_FIFTYONE_DEGREES_COM_KEY')) { + if (!\defined('CREDENTIALS_FIFTYONE_DEGREES_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -110,7 +113,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Mobile Safari', + 'name' => 'Mobile Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -122,7 +125,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => null, 'minor' => null, @@ -134,7 +137,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -148,21 +151,19 @@ public function testRealResultDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'SmartPhone', + 'type' => 'SmartPhone', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); diff --git a/tests/integration/Provider/Http/NeutrinoApiComTest.php b/tests/integration/Provider/Http/NeutrinoApiComTest.php index 2df7b18..3e0ac11 100644 --- a/tests/integration/Provider/Http/NeutrinoApiComTest.php +++ b/tests/integration/Provider/Http/NeutrinoApiComTest.php @@ -1,10 +1,13 @@ markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -29,7 +32,7 @@ public function testInvalidCredentials() */ public function testNoResultFound() { - if (! defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || ! defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { + if (!\defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || !\defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -40,7 +43,7 @@ public function testNoResultFound() public function testRealResultBot() { - if (! defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || ! defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { + if (!\defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || !\defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -49,7 +52,7 @@ public function testRealResultBot() $result = $provider->parse('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -61,7 +64,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -73,7 +76,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -87,21 +90,19 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -126,7 +127,7 @@ public function testRealResultBot() public function testRealResultDevice() { - if (! defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || ! defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { + if (!\defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || !\defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -135,7 +136,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -147,7 +148,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -159,7 +160,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -173,21 +174,19 @@ public function testRealResultDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'mobile-browser', + 'type' => 'mobile-browser', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -196,14 +195,14 @@ public function testRealResultDevice() public function testEncodeIsCorrect() { - if (! defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || ! defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { + if (!\defined('CREDENTIALS_NEUTRINO_API_COM_USER_ID') || !\defined('CREDENTIALS_NEUTRINO_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } $provider = new NeutrinoApiCom($this->getClient(), CREDENTIALS_NEUTRINO_API_COM_USER_ID, CREDENTIALS_NEUTRINO_API_COM_KEY); $userAgent = 'Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; HTC T9299+ For AT&T Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; - $result = $provider->parse($userAgent); + $result = $provider->parse($userAgent); $this->assertEquals('HTC', $result->getDevice() ->getBrand()); diff --git a/tests/integration/Provider/Http/UdgerComTest.php b/tests/integration/Provider/Http/UdgerComTest.php index 0fb3d0c..a0d5154 100644 --- a/tests/integration/Provider/Http/UdgerComTest.php +++ b/tests/integration/Provider/Http/UdgerComTest.php @@ -1,10 +1,13 @@ getClient(), 'invalid_api_key'); + $provider = new UdgerCom($this->getClient(), 'invalid_api_key'); $result = $provider->parse('...'); } @@ -24,7 +27,7 @@ public function testInvalidCredentials() */ public function testNoResultFound() { - if (! defined('CREDENTIALS_UDGER_COM_KEY')) { + if (!\defined('CREDENTIALS_UDGER_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } diff --git a/tests/integration/Provider/Http/UserAgentApiComTest.php b/tests/integration/Provider/Http/UserAgentApiComTest.php index 7853240..5ca159e 100644 --- a/tests/integration/Provider/Http/UserAgentApiComTest.php +++ b/tests/integration/Provider/Http/UserAgentApiComTest.php @@ -1,10 +1,13 @@ markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -48,7 +51,7 @@ public function testNoResultFound() public function testRealResultBot() { - if (! defined('CREDENTIALS_USER_AGENT_API_COM_KEY')) { + if (!\defined('CREDENTIALS_USER_AGENT_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -57,7 +60,7 @@ public function testRealResultBot() $result = $provider->parse('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -69,7 +72,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -81,7 +84,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -95,21 +98,19 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -122,7 +123,7 @@ public function testRealResultBot() public function testRealResultDevice() { - if (! defined('CREDENTIALS_USER_AGENT_API_COM_KEY')) { + if (!\defined('CREDENTIALS_USER_AGENT_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -131,7 +132,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 7534, 'minor' => 48, @@ -143,7 +144,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => 534, 'minor' => 46, @@ -155,7 +156,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -169,21 +170,19 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'Mobile', + 'type' => 'Mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -201,14 +200,14 @@ public function testRealResultDevice() public function testEncodeIsCorrect() { - if (! defined('CREDENTIALS_USER_AGENT_API_COM_KEY')) { + if (!\defined('CREDENTIALS_USER_AGENT_API_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } $provider = new UserAgentApiCom($this->getClient(), CREDENTIALS_USER_AGENT_API_COM_KEY); $userAgent = 'Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; HTC T9299+ For AT&T Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; - $result = $provider->parse($userAgent); + $result = $provider->parse($userAgent); $this->assertEquals('WebKit', $result->getRenderingEngine() ->getName()); diff --git a/tests/integration/Provider/Http/WhatIsMyBrowserComTest.php b/tests/integration/Provider/Http/WhatIsMyBrowserComTest.php index 5871392..d10eaae 100644 --- a/tests/integration/Provider/Http/WhatIsMyBrowserComTest.php +++ b/tests/integration/Provider/Http/WhatIsMyBrowserComTest.php @@ -1,10 +1,13 @@ markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -35,7 +38,7 @@ public function testNoResultFound() public function testRealResultDevice() { - if (! defined('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY')) { + if (!\defined('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -45,7 +48,7 @@ public function testRealResultDevice() $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -57,7 +60,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => 534, 'minor' => 46, @@ -69,7 +72,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -83,21 +86,19 @@ public function testRealResultDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); @@ -149,7 +150,7 @@ public function testRealResultDevice() public function testRealResultBot() { - if (! defined('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY')) { + if (!\defined('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } @@ -162,7 +163,7 @@ public function testRealResultBot() $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -174,7 +175,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -186,7 +187,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -200,29 +201,29 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => '360Spider', - 'type' => 'crawler', + 'name' => '360Spider', + 'type' => 'crawler', ], ], $result->toArray()); } public function testEncodeIsCorrect() { - if (! defined('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY')) { + if (!\defined('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } $provider = new WhatIsMyBrowserCom($this->getClient(), CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY); $userAgent = 'Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; HTC T9299+ For AT&T Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; - $result = $provider->parse($userAgent); + $result = $provider->parse($userAgent); $this->assertEquals($userAgent, $result->getProviderResultRaw()->user_agent); } diff --git a/tests/integration/Provider/JenssegersAgentTest.php b/tests/integration/Provider/JenssegersAgentTest.php index 0d6f82f..f01fa2d 100644 --- a/tests/integration/Provider/JenssegersAgentTest.php +++ b/tests/integration/Provider/JenssegersAgentTest.php @@ -1,15 +1,16 @@ * @license MIT * * @coversNothing + * + * @internal */ class JenssegersAgentTest extends AbstractProviderTestCase { @@ -30,7 +31,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.googlebot.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -42,7 +43,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -54,7 +55,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -68,31 +69,29 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Google', - 'type' => null, + 'name' => 'Google', + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ - 'browserName' => false, + 'browserName' => false, 'browserVersion' => false, - 'osName' => false, + 'osName' => false, 'osVersion' => false, 'deviceModel' => 'Bot', - 'isMobile' => false, + 'isMobile' => false, 'isRobot' => true, 'botName' => 'Google', @@ -106,7 +105,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -118,7 +117,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -130,7 +129,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -144,15 +143,15 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/PiwikDeviceDetectorTest.php b/tests/integration/Provider/PiwikDeviceDetectorTest.php index b107148..4aebceb 100644 --- a/tests/integration/Provider/PiwikDeviceDetectorTest.php +++ b/tests/integration/Provider/PiwikDeviceDetectorTest.php @@ -1,27 +1,27 @@ * @license MIT * * @coversNothing + * + * @internal */ class PiwikDeviceDetectorTest extends AbstractProviderTestCase { public function testMethods() { $provider = new PiwikDeviceDetector(); - $parser = $provider->getParser(); + $parser = $provider->getParser(); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('setUserAgent'), 'method setUserAgent() does not exist anymore'); $this->assertTrue($class->hasMethod('parse'), 'method parse() does not exist anymore'); @@ -56,7 +56,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.googlebot.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -68,7 +68,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -80,7 +80,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -94,43 +94,41 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => 'Search bot', + 'name' => 'Googlebot', + 'type' => 'Search bot', ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ - 'client' => null, + 'client' => null, 'operatingSystem' => null, 'device' => [ - 'brand' => null, + 'brand' => null, 'brandName' => null, 'model' => null, - 'device' => null, + 'device' => null, 'deviceName' => null, ], 'bot' => [ - 'name' => 'Googlebot', + 'name' => 'Googlebot', 'category' => 'Search bot', - 'url' => 'http://www.google.com/bot.html', + 'url' => 'http://www.google.com/bot.html', 'producer' => [ 'name' => 'Google Inc.', - 'url' => 'http://www.google.com', + 'url' => 'http://www.google.com', ], ], @@ -138,28 +136,28 @@ public function testRealResultBot() 'isBot' => true, // client - 'isBrowser' => false, - 'isFeedReader' => false, - 'isMobileApp' => false, - 'isPIM' => false, - 'isLibrary' => false, + 'isBrowser' => false, + 'isFeedReader' => false, + 'isMobileApp' => false, + 'isPIM' => false, + 'isLibrary' => false, 'isMediaPlayer' => false, // deviceType - 'isCamera' => false, - 'isCarBrowser' => false, - 'isConsole' => false, - 'isFeaturePhone' => false, - 'isPhablet' => false, + 'isCamera' => false, + 'isCarBrowser' => false, + 'isConsole' => false, + 'isFeaturePhone' => false, + 'isPhablet' => false, 'isPortableMediaPlayer' => false, - 'isSmartDisplay' => false, - 'isSmartphone' => false, - 'isTablet' => false, - 'isTV' => false, + 'isSmartDisplay' => false, + 'isSmartphone' => false, + 'isTablet' => false, + 'isTV' => false, // other special - 'isDesktop' => false, - 'isMobile' => false, + 'isDesktop' => false, + 'isMobile' => false, 'isTouchEnabled' => false, ], ], $rawResult); @@ -172,7 +170,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Mobile Safari', + 'name' => 'Mobile Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -184,7 +182,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => null, 'minor' => null, @@ -196,7 +194,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => null, @@ -210,15 +208,15 @@ public function testRealResultDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'smartphone', + 'type' => 'smartphone', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/SinergiBrowserDetectorTest.php b/tests/integration/Provider/SinergiBrowserDetectorTest.php index c9ca1b4..78202dc 100644 --- a/tests/integration/Provider/SinergiBrowserDetectorTest.php +++ b/tests/integration/Provider/SinergiBrowserDetectorTest.php @@ -1,15 +1,17 @@ * @license MIT * * @coversNothing + * + * @internal */ class SinergiBrowserDetectorTest extends AbstractProviderTestCase { @@ -19,10 +21,8 @@ public function testBrowserParser() $parser = $provider->getBrowserParser('something'); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); $this->assertTrue($class->hasMethod('getVersion'), 'method getVersion() does not exist anymore'); @@ -35,10 +35,8 @@ public function testOsParser() $parser = $provider->getOperatingSystemParser('something'); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); $this->assertTrue($class->hasMethod('getVersion'), 'method getVersion() does not exist anymore'); @@ -51,10 +49,8 @@ public function testDeviceParser() $parser = $provider->getDeviceParser('something'); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); } @@ -76,7 +72,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.googlebot.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -88,7 +84,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -100,7 +96,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -114,21 +110,19 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInternalType('array', $rawResult); @@ -159,7 +153,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -171,7 +165,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -183,7 +177,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -197,15 +191,15 @@ public function testRealResultDevice() 'device' => [ 'model' => 'iPhone', 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/UAParserTest.php b/tests/integration/Provider/UAParserTest.php index 479ee66..72daf79 100644 --- a/tests/integration/Provider/UAParserTest.php +++ b/tests/integration/Provider/UAParserTest.php @@ -1,44 +1,37 @@ * @license MIT * * @coversNothing + * + * @internal */ class UAParserTest extends AbstractProviderTestCase { - private function getParser() - { - return new \UAParser\Parser(include 'tests/resources/uaparser/regexes.php'); - } - public function testMethodParse() { $provider = new UAParser($this->getParser()); - $parser = $provider->getParser(); + $parser = $provider->getParser(); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('parse'), 'method parse() does not exist anymore'); - /* - * test paramters - */ - $method = $class->getMethod('parse'); + // test paramters + $method = $class->getMethod('parse'); $parameters = $method->getParameters(); - $this->assertEquals(2, count($parameters)); + $this->assertEquals(2, \count($parameters)); - /* @var $optionalPara \ReflectionParameter */ + // @var $optionalPara \ReflectionParameter $optionalPara = $parameters[1]; $this->assertTrue($optionalPara->isOptional(), '2nd parameter of parse() is not optional anymore'); @@ -47,14 +40,14 @@ public function testMethodParse() public function testParseResult() { $provider = new UAParser($this->getParser()); - $parser = $provider->getParser(); + $parser = $provider->getParser(); - /* @var $result \UAParser\Result\Client */ + // @var $result \UAParser\Result\Client $result = $parser->parse('A real user agent...'); $this->assertInstanceOf('UAParser\Result\Client', $result); - $class = new \ReflectionClass($result); + $class = new ReflectionClass($result); $this->assertTrue($class->hasProperty('ua'), 'property ua does not exist anymore'); $this->assertInstanceOf('UAParser\Result\UserAgent', $result->ua); @@ -68,7 +61,7 @@ public function testParseResult() public function testClassBrowserResult() { - $class = new \ReflectionClass('UAParser\Result\OperatingSystem'); + $class = new ReflectionClass('UAParser\Result\OperatingSystem'); $this->assertTrue($class->hasProperty('family'), 'property family does not exist anymore'); $this->assertTrue($class->hasProperty('major'), 'property major does not exist anymore'); @@ -78,7 +71,7 @@ public function testClassBrowserResult() public function testClassOsResult() { - $class = new \ReflectionClass('UAParser\Result\UserAgent'); + $class = new ReflectionClass('UAParser\Result\UserAgent'); $this->assertTrue($class->hasProperty('family'), 'property family does not exist anymore'); $this->assertTrue($class->hasProperty('major'), 'property major does not exist anymore'); @@ -88,7 +81,7 @@ public function testClassOsResult() public function testClassDeviceResult() { - $class = new \ReflectionClass('UAParser\Result\Device'); + $class = new ReflectionClass('UAParser\Result\Device'); $this->assertTrue($class->hasProperty('model'), 'property family does not exist anymore'); $this->assertTrue($class->hasProperty('brand'), 'property major does not exist anymore'); @@ -112,7 +105,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.googlebot.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -124,7 +117,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -136,7 +129,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -150,21 +143,19 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('UAParser\Result\Client', $rawResult); @@ -205,7 +196,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Mobile Safari', + 'name' => 'Mobile Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -217,7 +208,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -229,7 +220,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -243,16 +234,21 @@ public function testRealResultDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } + + private function getParser() + { + return new \UAParser\Parser(include 'tests/resources/uaparser/regexes.php'); + } } diff --git a/tests/integration/Provider/WhichBrowserTest.php b/tests/integration/Provider/WhichBrowserTest.php index e93e7c0..dc8bd53 100644 --- a/tests/integration/Provider/WhichBrowserTest.php +++ b/tests/integration/Provider/WhichBrowserTest.php @@ -1,15 +1,17 @@ * @license MIT * * @coversNothing + * + * @internal */ class WhichBrowserTest extends AbstractProviderTestCase { @@ -23,10 +25,8 @@ public function testRealResult() $this->assertInstanceOf('WhichBrowser\Parser', $parser); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('isDetected'), 'method isDetected() does not exist anymore'); $this->assertTrue($class->hasMethod('toArray'), 'method toArray() does not exist anymore'); @@ -48,7 +48,7 @@ public function testRealResult() public function testClassBrowserResult() { - $class = new \ReflectionClass('WhichBrowser\Model\Browser'); + $class = new ReflectionClass('WhichBrowser\Model\Browser'); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); $this->assertTrue($class->hasMethod('getVersion'), 'method getVersion() does not exist anymore'); @@ -58,7 +58,7 @@ public function testClassBrowserResult() public function testClassBrowserUsingResult() { - $class = new \ReflectionClass('WhichBrowser\Model\Using'); + $class = new ReflectionClass('WhichBrowser\Model\Using'); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); $this->assertTrue($class->hasMethod('getVersion'), 'method getVersion() does not exist anymore'); @@ -66,7 +66,7 @@ public function testClassBrowserUsingResult() public function testClassEngineResult() { - $class = new \ReflectionClass('WhichBrowser\Model\Engine'); + $class = new ReflectionClass('WhichBrowser\Model\Engine'); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); $this->assertTrue($class->hasMethod('getVersion'), 'method getVersion() does not exist anymore'); @@ -74,7 +74,7 @@ public function testClassEngineResult() public function testClassOsResult() { - $class = new \ReflectionClass('WhichBrowser\Model\Os'); + $class = new ReflectionClass('WhichBrowser\Model\Os'); $this->assertTrue($class->hasMethod('getName'), 'method getName() does not exist anymore'); $this->assertTrue($class->hasMethod('getVersion'), 'method getVersion() does not exist anymore'); @@ -82,7 +82,7 @@ public function testClassOsResult() public function testClassDeviceResult() { - $class = new \ReflectionClass('WhichBrowser\Model\Device'); + $class = new ReflectionClass('WhichBrowser\Model\Device'); $this->assertTrue($class->hasMethod('getModel'), 'method getModel() does not exist anymore'); $this->assertTrue($class->hasMethod('getManufacturer'), 'method getManufacturer() does not exist anymore'); @@ -105,7 +105,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.google.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -117,7 +117,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -129,7 +129,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -143,28 +143,26 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ - 'browser' => [ - 'name' => 'Googlebot', + 'browser' => [ + 'name' => 'Googlebot', 'version' => '2.1', ], - 'device' => [ + 'device' => [ 'type' => 'bot', ], ], $rawResult); @@ -177,7 +175,7 @@ public function testRealResultDevice() $result = $provider->parse('Mozilla/5.0 (Linux; Android 4.3; SCH-R970C Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.3'); $this->assertEquals([ 'browser' => [ - 'name' => 'Chrome', + 'name' => 'Chrome', 'version' => [ 'major' => 34, 'minor' => null, @@ -189,7 +187,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => 'Blink', + 'name' => 'Blink', 'version' => [ 'major' => null, 'minor' => null, @@ -201,7 +199,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'Android', + 'name' => 'Android', 'version' => [ 'major' => 4, 'minor' => 3, @@ -215,40 +213,38 @@ public function testRealResultDevice() 'device' => [ 'model' => 'Galaxy S4', 'brand' => 'Samsung', - 'type' => 'mobile:smart', + 'type' => 'mobile:smart', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ - 'browser' => [ - 'name' => 'Chrome', + 'browser' => [ + 'name' => 'Chrome', 'version' => '34', - 'type' => 'browser', + 'type' => 'browser', ], 'engine' => [ - 'name' => 'Blink', + 'name' => 'Blink', ], 'os' => [ - 'name' => 'Android', + 'name' => 'Android', 'version' => '4.3', ], - 'device' => [ - 'type' => 'mobile', - 'subtype' => 'smart', + 'device' => [ + 'type' => 'mobile', + 'subtype' => 'smart', 'manufacturer' => 'Samsung', - 'model' => 'Galaxy S4', + 'model' => 'Galaxy S4', ], ], $rawResult); } diff --git a/tests/integration/Provider/WootheeTest.php b/tests/integration/Provider/WootheeTest.php index c3b6d3b..557aabb 100644 --- a/tests/integration/Provider/WootheeTest.php +++ b/tests/integration/Provider/WootheeTest.php @@ -1,37 +1,35 @@ * @license MIT * * @coversNothing + * + * @internal */ class WootheeTest extends AbstractProviderTestCase { public function testMethodParse() { $provider = new Woothee(); - $parser = $provider->getParser(); + $parser = $provider->getParser(); - /* - * test method exists - */ - $class = new \ReflectionClass($parser); + // test method exists + $class = new ReflectionClass($parser); $this->assertTrue($class->hasMethod('parse'), 'method parse() does not exist anymore'); - /* - * test paramters - */ - $method = $class->getMethod('parse'); + // test paramters + $method = $class->getMethod('parse'); $parameters = $method->getParameters(); - $this->assertEquals(1, count($parameters)); + $this->assertEquals(1, \count($parameters)); } /** @@ -51,7 +49,7 @@ public function testRealResultBot() $result = $provider->parse('Googlebot/2.1 (+http://www.googlebot.com/bot.html)'); $this->assertEquals([ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -63,7 +61,7 @@ public function testRealResultBot() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -75,7 +73,7 @@ public function testRealResultBot() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -89,28 +87,26 @@ public function testRealResultBot() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ - 'name' => 'misc crawler', - 'category' => 'crawler', - 'os' => 'UNKNOWN', - 'version' => 'UNKNOWN', - 'vendor' => 'UNKNOWN', + 'name' => 'misc crawler', + 'category' => 'crawler', + 'os' => 'UNKNOWN', + 'version' => 'UNKNOWN', + 'vendor' => 'UNKNOWN', 'os_version' => 'UNKNOWN', ], $rawResult); } @@ -122,7 +118,7 @@ public function testRealResultDevice() $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'); $this->assertEquals([ 'browser' => [ - 'name' => 'Safari', + 'name' => 'Safari', 'version' => [ 'major' => 5, 'minor' => 1, @@ -134,7 +130,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -146,7 +142,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -160,15 +156,15 @@ public function testRealResultDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'smartphone', + 'type' => 'smartphone', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); } diff --git a/tests/integration/Provider/ZsxsoftTest.php b/tests/integration/Provider/ZsxsoftTest.php index 929725e..47325b3 100644 --- a/tests/integration/Provider/ZsxsoftTest.php +++ b/tests/integration/Provider/ZsxsoftTest.php @@ -1,15 +1,16 @@ * @license MIT * * @coversNothing + * + * @internal */ class ZsxsoftTest extends AbstractProviderTestCase { @@ -30,7 +31,7 @@ public function testRealResultDevice() $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' => 'Opera', + 'name' => 'Opera', 'version' => [ 'major' => 26, 'minor' => 0, @@ -42,7 +43,7 @@ public function testRealResultDevice() ], ], 'renderingEngine' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -54,7 +55,7 @@ public function testRealResultDevice() ], ], 'operatingSystem' => [ - 'name' => 'Android', + 'name' => 'Android', 'version' => [ 'major' => 5, 'minor' => 0, @@ -68,60 +69,58 @@ public function testRealResultDevice() 'device' => [ 'model' => 'Nexus 7', 'brand' => 'Google', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], 'bot' => [ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ], $result->toArray()); - /* - * Test the raw result - */ + // Test the raw result $rawResult = $result->getProviderResultRaw(); $this->assertEquals([ 'browser' => [ - 'link' => 'http://www.opera.com/', - 'title' => 'Opera 26.0.1656.87080', - 'name' => 'Opera', + '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', + 'code' => 'opera-1', + 'image' => 'img/16/browser/opera-1.png', ], 'os' => [ - 'link' => 'http://www.android.com/', - 'name' => 'Android', + 'link' => 'http://www.android.com/', + 'name' => 'Android', 'version' => '5.0.1', - 'code' => 'android', - 'x64' => false, - 'title' => 'Android 5.0.1', - 'type' => 'os', - 'dir' => 'os', - 'image' => 'img/16/os/android.png', + 'code' => 'android', + 'x64' => false, + 'title' => 'Android 5.0.1', + 'type' => 'os', + 'dir' => 'os', + 'image' => 'img/16/os/android.png', ], 'device' => [ - 'link' => 'https://www.google.com/nexus/', + 'link' => 'https://www.google.com/nexus/', 'title' => 'Google Nexus 7', 'model' => 'Nexus 7', 'brand' => 'Google', - 'code' => 'google-nexusone', - 'dir' => 'device', - 'type' => 'device', + 'code' => 'google-nexusone', + 'dir' => 'device', + 'type' => 'device', 'image' => 'img/16/device/google-nexusone.png', ], 'platform' => [ - 'link' => 'https://www.google.com/nexus/', + 'link' => 'https://www.google.com/nexus/', 'title' => 'Google Nexus 7', 'model' => 'Nexus 7', 'brand' => 'Google', - 'code' => 'google-nexusone', - 'dir' => 'device', - 'type' => 'device', + 'code' => 'google-nexusone', + 'dir' => 'device', + 'type' => 'device', 'image' => 'img/16/device/google-nexusone.png', ], ], $rawResult); diff --git a/tests/unit/Model/BotTest.php b/tests/unit/Model/BotTest.php index 2aa263d..96850f2 100644 --- a/tests/unit/Model/BotTest.php +++ b/tests/unit/Model/BotTest.php @@ -1,16 +1,17 @@ * @license MIT * - * @covers UserAgentParser\Model\Bot + * @covers \UserAgentParser\Model\Bot + * + * @internal */ class BotTest extends PHPUnit_Framework_TestCase { @@ -55,8 +56,8 @@ public function testToArray() $this->assertEquals([ 'isBot' => null, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], $bot->toArray()); $bot->setIsBot(true); @@ -65,8 +66,8 @@ public function testToArray() $this->assertEquals([ 'isBot' => true, - 'name' => 'my bot name2', - 'type' => 'backlink', + 'name' => 'my bot name2', + 'type' => 'backlink', ], $bot->toArray()); } } diff --git a/tests/unit/Model/BrowserTest.php b/tests/unit/Model/BrowserTest.php index 94b443b..7a89f7b 100644 --- a/tests/unit/Model/BrowserTest.php +++ b/tests/unit/Model/BrowserTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Model\Browser + * @covers \UserAgentParser\Model\Browser + * + * @internal */ class BrowserTest extends PHPUnit_Framework_TestCase { @@ -42,14 +43,14 @@ public function testToArray() $browser = new Browser(); $this->assertEquals([ - 'name' => null, + 'name' => null, 'version' => $browser->getVersion() ->toArray(), ], $browser->toArray()); $browser->setName('Chrome'); $this->assertEquals([ - 'name' => 'Chrome', + 'name' => 'Chrome', 'version' => $browser->getVersion() ->toArray(), ], $browser->toArray()); diff --git a/tests/unit/Model/DeviceTest.php b/tests/unit/Model/DeviceTest.php index 9e1a64b..30a5f65 100644 --- a/tests/unit/Model/DeviceTest.php +++ b/tests/unit/Model/DeviceTest.php @@ -1,16 +1,17 @@ * @license MIT * - * @covers UserAgentParser\Model\Device + * @covers \UserAgentParser\Model\Device + * + * @internal */ class DeviceTest extends PHPUnit_Framework_TestCase { @@ -72,11 +73,11 @@ public function testToArray() $device = new Device(); $this->assertEquals([ - 'model' => null, - 'brand' => null, - 'type' => null, + 'model' => null, + 'brand' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], $device->toArray()); $device->setModel('iPad'); @@ -86,11 +87,11 @@ public function testToArray() $device->setIsTouch(true); $this->assertEquals([ - 'model' => 'iPad', - 'brand' => 'Apple', - 'type' => 'tablet', + 'model' => 'iPad', + 'brand' => 'Apple', + 'type' => 'tablet', 'isMobile' => false, - 'isTouch' => true, + 'isTouch' => true, ], $device->toArray()); } } diff --git a/tests/unit/Model/OperatingSystemTest.php b/tests/unit/Model/OperatingSystemTest.php index cde2430..5190a00 100644 --- a/tests/unit/Model/OperatingSystemTest.php +++ b/tests/unit/Model/OperatingSystemTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Model\OperatingSystem + * @covers \UserAgentParser\Model\OperatingSystem + * + * @internal */ class OperatingSystemTest extends PHPUnit_Framework_TestCase { @@ -42,14 +43,14 @@ public function testToArray() $os = new OperatingSystem(); $this->assertEquals([ - 'name' => null, + 'name' => null, 'version' => $os->getVersion() ->toArray(), ], $os->toArray()); $os->setName('Linux'); $this->assertEquals([ - 'name' => 'Linux', + 'name' => 'Linux', 'version' => $os->getVersion() ->toArray(), ], $os->toArray()); diff --git a/tests/unit/Model/RenderingEngineTest.php b/tests/unit/Model/RenderingEngineTest.php index e59e504..1bac038 100644 --- a/tests/unit/Model/RenderingEngineTest.php +++ b/tests/unit/Model/RenderingEngineTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Model\RenderingEngine + * @covers \UserAgentParser\Model\RenderingEngine + * + * @internal */ class RenderingEngineTest extends PHPUnit_Framework_TestCase { @@ -42,14 +43,14 @@ public function testToArray() $engine = new RenderingEngine(); $this->assertEquals([ - 'name' => null, + 'name' => null, 'version' => $engine->getVersion() ->toArray(), ], $engine->toArray()); $engine->setName('Trident'); $this->assertEquals([ - 'name' => 'Trident', + 'name' => 'Trident', 'version' => $engine->getVersion() ->toArray(), ], $engine->toArray()); diff --git a/tests/unit/Model/UserAgentTest.php b/tests/unit/Model/UserAgentTest.php index 2ec2c8a..e2b1f20 100644 --- a/tests/unit/Model/UserAgentTest.php +++ b/tests/unit/Model/UserAgentTest.php @@ -1,18 +1,17 @@ * @license MIT * - * @covers UserAgentParser\Model\UserAgent + * @covers \UserAgentParser\Model\UserAgent + * + * @internal */ class UserAgentTest extends PHPUnit_Framework_TestCase { @@ -112,19 +111,19 @@ public function testToArray() $ua = new UserAgent(); $this->assertEquals([ - 'browser' => $ua->getBrowser()->toArray(), - 'renderingEngine' => $ua->getRenderingEngine()->toArray(), - 'operatingSystem' => $ua->getOperatingSystem()->toArray(), - 'device' => $ua->getDevice()->toArray(), - 'bot' => $ua->getBot()->toArray(), + 'browser' => $ua->getBrowser()->toArray(), + 'renderingEngine' => $ua->getRenderingEngine()->toArray(), + 'operatingSystem' => $ua->getOperatingSystem()->toArray(), + 'device' => $ua->getDevice()->toArray(), + 'bot' => $ua->getBot()->toArray(), ], $ua->toArray()); $this->assertEquals([ - 'browser' => $ua->getBrowser()->toArray(), - 'renderingEngine' => $ua->getRenderingEngine()->toArray(), - 'operatingSystem' => $ua->getOperatingSystem()->toArray(), - 'device' => $ua->getDevice()->toArray(), - 'bot' => $ua->getBot()->toArray(), + 'browser' => $ua->getBrowser()->toArray(), + 'renderingEngine' => $ua->getRenderingEngine()->toArray(), + 'operatingSystem' => $ua->getOperatingSystem()->toArray(), + 'device' => $ua->getDevice()->toArray(), + 'bot' => $ua->getBot()->toArray(), 'providerResultRaw' => null, ], $ua->toArray(true)); } diff --git a/tests/unit/Model/VersionTest.php b/tests/unit/Model/VersionTest.php index ed90ed6..f93a4b5 100644 --- a/tests/unit/Model/VersionTest.php +++ b/tests/unit/Model/VersionTest.php @@ -1,16 +1,17 @@ * @license MIT * - * @covers UserAgentParser\Model\Version + * @covers \UserAgentParser\Model\Version + * + * @internal */ class VersionTest extends PHPUnit_Framework_TestCase { @@ -56,7 +57,7 @@ public function testCompleteSimple() $this->assertEquals('2.0', $version->getComplete()); $this->assertEquals(2, $version->getMajor()); $this->assertEquals(0, $version->getMinor()); - $this->assertEquals(null, $version->getPatch()); + $this->assertNull($version->getPatch()); $version->setMajor(3); $this->assertEquals('3.0', $version->getComplete()); diff --git a/tests/unit/Provider/AbstractBrowscapTest.php b/tests/unit/Provider/AbstractBrowscapTest.php index d94b566..46e6928 100644 --- a/tests/unit/Provider/AbstractBrowscapTest.php +++ b/tests/unit/Provider/AbstractBrowscapTest.php @@ -1,49 +1,22 @@ * @license MIT * - * @covers UserAgentParser\Provider\AbstractBrowscap + * @covers \UserAgentParser\Provider\AbstractBrowscap + * + * @internal */ class AbstractBrowscapTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser(\stdClass $result = null, $date = null) - { - if ($date === null) { - $date = new \DateTime('2016-03-10 18:00:00'); - } - - $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); - $cache->expects($this->any()) - ->method('getType') - ->will($this->returnValue('')); - $cache->expects($this->any()) - ->method('getVersion') - ->will($this->returnValue('321')); - $cache->expects($this->any()) - ->method('getReleaseDate') - ->will($this->returnValue($date->format('r'))); - - $parser = self::createMock('BrowscapPHP\Browscap'); - $parser->expects($this->any()) - ->method('getCache') - ->will($this->returnValue($cache)); - $parser->expects($this->any()) - ->method('getBrowser') - ->will($this->returnValue($result)); - - return $parser; - } - /** * Warm cache is missing! * @@ -57,7 +30,7 @@ public function testConstructExceptionNOWarmCache() $parser = self::createMock('BrowscapPHP\Browscap'); $parser->expects($this->any()) ->method('getCache') - ->will($this->returnValue($cache)); + ->willReturn($cache); $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ $parser, @@ -66,7 +39,7 @@ public function testConstructExceptionNOWarmCache() } /** - * Different type + * Different type. * * @expectedException \UserAgentParser\Exception\InvalidArgumentException * @expectedExceptionMessage Expected the "anotherExceptedType" data file. Instead got the "" data file @@ -119,7 +92,7 @@ public function testVersion() public function testUpdateDate() { - $date = new \DateTime('2016-03-10 18:00:00'); + $date = new DateTime('2016-03-10 18:00:00'); $parser = $this->getParser(null, $date); @@ -140,34 +113,33 @@ public function testDetectionCapabilities() ]); $this->assertEquals([ - 'browser' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -178,30 +150,22 @@ public function testIsRealResult() $provider = new BrowscapPhp($parser); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'unknown'); $this->assertIsRealResult($provider, true, 'unknown something'); $this->assertIsRealResult($provider, true, 'something unknown'); - /* - * browser name - */ + // browser name $this->assertIsRealResult($provider, false, 'Default Browser', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'Default Browser something', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'something Default Browser', 'browser', 'name'); - /* - * device model - */ + // device model $this->assertIsRealResult($provider, false, 'general', 'device', 'model'); $this->assertIsRealResult($provider, false, 'general something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something general', 'device', 'model'); - /* - * bot name - */ + // bot name $this->assertIsRealResult($provider, false, 'General Crawlers', 'bot', 'name'); $this->assertIsRealResult($provider, false, 'General Crawlers something', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'something General Crawlers', 'bot', 'name'); @@ -221,13 +185,13 @@ public function testParser() } /** - * Provider no result + * Provider no result. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundException() { - $result = new \stdClass(); + $result = new stdClass(); $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ $this->getParser($result), @@ -237,13 +201,13 @@ public function testParseNoResultFoundException() } /** - * Provider result empty + * Provider result empty. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundExceptionResultEmpty() { - $result = new \stdClass(); + $result = new stdClass(); $result->browser = ''; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -254,13 +218,13 @@ public function testParseNoResultFoundExceptionResultEmpty() } /** - * Provider result unknown + * Provider result unknown. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundExceptionResultUnknown() { - $result = new \stdClass(); + $result = new stdClass(); $result->browser = 'unknown'; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -271,13 +235,13 @@ public function testParseNoResultFoundExceptionResultUnknown() } /** - * Provider result Default Browser + * Provider result Default Browser. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundExceptionResultDefaultBrowser() { - $result = new \stdClass(); + $result = new stdClass(); $result->browser = 'Default Browser'; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -292,19 +256,19 @@ public function testParseNoResultFoundExceptionResultDefaultBrowser() */ public function testProviderNameAndVersionIsInResult() { - $result = new \stdClass(); - $result->browser = 'Google Bot'; + $result = new stdClass(); + $result->browser = 'Google Bot'; $result->browser_type = 'Crawler'; - $result->crawler = true; + $result->crawler = true; $provider = $this->getMockBuilder('UserAgentParser\Provider\AbstractBrowscap') - ->setConstructorArgs([$this->getParser($result)]) - ->setMethods(['getName']) - ->getMockForAbstractClass(); + ->setConstructorArgs([$this->getParser($result)]) + ->setMethods(['getName']) + ->getMockForAbstractClass(); $provider->expects($this->any()) - ->method('getName') - ->will($this->returnValue('Browscap')); + ->method('getName') + ->willReturn('Browscap'); $result = $provider->parse('A real user agent...'); @@ -313,14 +277,14 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot - Crawler + * Bot - Crawler. */ public function testParseBotCrawler() { - $result = new \stdClass(); - $result->browser = 'Google Bot'; + $result = new stdClass(); + $result->browser = 'Google Bot'; $result->browser_type = 'Crawler'; - $result->crawler = true; + $result->crawler = true; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ $this->getParser($result), @@ -331,8 +295,8 @@ public function testParseBotCrawler() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Google Bot', - 'type' => 'Crawler', + 'name' => 'Google Bot', + 'type' => 'Crawler', ], ]; @@ -340,14 +304,14 @@ public function testParseBotCrawler() } /** - * Bot - Rss + * Bot - Rss. */ public function testParseBotRss() { - $result = new \stdClass(); - $result->browser = 'Hatena RSS'; - $result->browser_type = 'Bot/Crawler'; - $result->crawler = true; + $result = new stdClass(); + $result->browser = 'Hatena RSS'; + $result->browser_type = 'Bot/Crawler'; + $result->crawler = true; $result->issyndicationreader = true; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -359,8 +323,8 @@ public function testParseBotRss() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Hatena RSS', - 'type' => 'RSS', + 'name' => 'Hatena RSS', + 'type' => 'RSS', ], ]; @@ -368,14 +332,14 @@ public function testParseBotRss() } /** - * Bot - other type + * Bot - other type. */ public function testParseBotOtherType() { - $result = new \stdClass(); - $result->browser = 'Hatena RSS'; + $result = new stdClass(); + $result->browser = 'Hatena RSS'; $result->browser_type = 'Bot/test'; - $result->crawler = true; + $result->crawler = true; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ $this->getParser($result), @@ -386,8 +350,8 @@ public function testParseBotOtherType() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Hatena RSS', - 'type' => 'Bot/test', + 'name' => 'Hatena RSS', + 'type' => 'Bot/test', ], ]; @@ -395,11 +359,11 @@ public function testParseBotOtherType() } /** - * Bot - name default + * Bot - name default. */ public function testParseBotNameDefault() { - $result = new \stdClass(); + $result = new stdClass(); $result->browser = 'General Crawlers'; $result->crawler = true; @@ -412,8 +376,8 @@ public function testParseBotNameDefault() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -421,11 +385,11 @@ public function testParseBotNameDefault() } /** - * Browser small + * Browser small. */ public function testParseBrowserSmall() { - $result = new \stdClass(); + $result = new stdClass(); $result->browser = 'Midori'; $result->version = '0.0'; $result->crawler = false; @@ -438,7 +402,7 @@ public function testParseBrowserSmall() $expectedResult = [ 'browser' => [ - 'name' => 'Midori', + 'name' => 'Midori', 'version' => [ 'major' => null, 'minor' => null, @@ -455,24 +419,24 @@ public function testParseBrowserSmall() } /** - * Browser with all + * Browser with all. */ public function testParseAll() { - $result = new \stdClass(); + $result = new stdClass(); $result->browser = 'Midori'; $result->version = '1.5.2'; - $result->renderingengine_name = 'WebKit'; + $result->renderingengine_name = 'WebKit'; $result->renderingengine_version = '13.0'; - $result->platform = 'iOS'; + $result->platform = 'iOS'; $result->platform_version = '5.0'; - $result->device_name = 'iPad'; - $result->device_brand_name = 'Apple'; - $result->device_type = 'Tablet'; - $result->ismobiledevice = true; + $result->device_name = 'iPad'; + $result->device_brand_name = 'Apple'; + $result->device_type = 'Tablet'; + $result->ismobiledevice = true; $result->device_pointing_method = 'touchscreen'; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -483,7 +447,7 @@ public function testParseAll() $expectedResult = [ 'browser' => [ - 'name' => 'Midori', + 'name' => 'Midori', 'version' => [ 'major' => 1, 'minor' => 5, @@ -496,7 +460,7 @@ public function testParseAll() ], 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => 13, 'minor' => 0, @@ -509,7 +473,7 @@ public function testParseAll() ], 'operatingSystem' => [ - 'name' => 'iOS', + 'name' => 'iOS', 'version' => [ 'major' => 5, 'minor' => 0, @@ -524,10 +488,10 @@ public function testParseAll() 'device' => [ 'model' => 'iPad', 'brand' => 'Apple', - 'type' => 'Tablet', + 'type' => 'Tablet', 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], ]; @@ -535,12 +499,12 @@ public function testParseAll() } /** - * Device - model default + * Device - model default. */ public function testParseDeviceModelDefault() { - $result = new \stdClass(); - $result->browser = 'Midori'; + $result = new stdClass(); + $result->browser = 'Midori'; $result->device_name = 'general'; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -551,7 +515,7 @@ public function testParseDeviceModelDefault() $expectedResult = [ 'browser' => [ - 'name' => 'Midori', + 'name' => 'Midori', 'version' => [ 'major' => null, 'minor' => null, @@ -566,10 +530,10 @@ public function testParseDeviceModelDefault() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -577,12 +541,12 @@ public function testParseDeviceModelDefault() } /** - * Device - model default + * Device - model default. */ public function testParseDeviceModelDefault2() { - $result = new \stdClass(); - $result->browser = 'Midori'; + $result = new stdClass(); + $result->browser = 'Midori'; $result->device_name = 'desktop'; $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ @@ -593,7 +557,7 @@ public function testParseDeviceModelDefault2() $expectedResult = [ 'browser' => [ - 'name' => 'Midori', + 'name' => 'Midori', 'version' => [ 'major' => null, 'minor' => null, @@ -608,13 +572,46 @@ public function testParseDeviceModelDefault2() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @param null|mixed $date + * + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser(stdClass $result = null, $date = null) + { + if ($date === null) { + $date = new DateTime('2016-03-10 18:00:00'); + } + + $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); + $cache->expects($this->any()) + ->method('getType') + ->willReturn(''); + $cache->expects($this->any()) + ->method('getVersion') + ->willReturn('321'); + $cache->expects($this->any()) + ->method('getReleaseDate') + ->willReturn($date->format('r')); + + $parser = self::createMock('BrowscapPHP\Browscap'); + $parser->expects($this->any()) + ->method('getCache') + ->willReturn($cache); + $parser->expects($this->any()) + ->method('getBrowser') + ->willReturn($result); + + return $parser; + } } diff --git a/tests/unit/Provider/AbstractProviderTest.php b/tests/unit/Provider/AbstractProviderTest.php index f555263..e0d552b 100644 --- a/tests/unit/Provider/AbstractProviderTest.php +++ b/tests/unit/Provider/AbstractProviderTest.php @@ -1,12 +1,16 @@ * @license MIT * - * @covers UserAgentParser\Provider\AbstractProvider + * @covers \UserAgentParser\Provider\AbstractProvider + * + * @internal */ class AbstractProviderTest extends AbstractProviderTestCase { @@ -16,8 +20,8 @@ public function testGetName() $this->assertNull($provider->getName()); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('name'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('name'); $property->setAccessible(true); $property->setValue($provider, 'MyName'); @@ -30,8 +34,8 @@ public function testGetHomepage() $this->assertNull($provider->getHomepage()); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('homepage'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('homepage'); $property->setAccessible(true); $property->setValue($provider, 'https://github.com/vendor/package'); @@ -44,8 +48,8 @@ public function testGetPackageName() $this->assertNull($provider->getPackageName()); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'vendor/package'); @@ -62,8 +66,8 @@ public function testVersionNull() // no package match $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'vendor/package'); @@ -74,8 +78,8 @@ public function testVersion() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'piwik/device-detector'); @@ -93,8 +97,8 @@ public function testUpdateDateNull() // no package match $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'vendor/package'); @@ -105,8 +109,8 @@ public function testUpdateDate() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'piwik/device-detector'); @@ -127,13 +131,13 @@ public function testCheckIfInstalled() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'thadafinser/user-agent-parser'); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('checkIfInstalled'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('checkIfInstalled'); $method->setAccessible(true); // no return, just no exception expected @@ -147,13 +151,13 @@ public function testCheckIfInstalledException() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('packageName'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('packageName'); $property->setAccessible(true); $property->setValue($provider, 'vendor/package'); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('checkIfInstalled'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('checkIfInstalled'); $method->setAccessible(true); $method->invoke($provider); @@ -163,8 +167,8 @@ public function testIsRealResult() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('isRealResult'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('isRealResult'); $method->setAccessible(true); $this->assertFalse($method->invoke($provider, '')); @@ -177,7 +181,7 @@ public function testIsRealResultWithDefaultValues() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); + $reflection = new ReflectionClass($provider); $property = $reflection->getProperty('defaultValues'); $property->setAccessible(true); @@ -207,8 +211,8 @@ public function testGetRealResult() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('getRealResult'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('getRealResult'); $method->setAccessible(true); $this->assertNull($method->invoke($provider, '')); @@ -221,7 +225,7 @@ public function testGetRealResultWithDefaultValues() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); - $reflection = new \ReflectionClass($provider); + $reflection = new ReflectionClass($provider); $property = $reflection->getProperty('defaultValues'); $property->setAccessible(true); diff --git a/tests/unit/Provider/AbstractProviderTestCase.php b/tests/unit/Provider/AbstractProviderTestCase.php index 3af46c9..a094783 100644 --- a/tests/unit/Provider/AbstractProviderTestCase.php +++ b/tests/unit/Provider/AbstractProviderTestCase.php @@ -1,15 +1,16 @@ * @license MIT */ @@ -19,7 +20,7 @@ protected function assertProviderResult($result, array $expectedResult) { $this->assertInstanceOf('UserAgentParser\Model\UserAgent', $result); - $model = new UserAgent(); + $model = new UserAgent(); $expectedResult = array_merge($model->toArray(), $expectedResult); $this->assertEquals($result->toArray(), $expectedResult); @@ -27,15 +28,14 @@ protected function assertProviderResult($result, array $expectedResult) protected function assertIsRealResult(AbstractProvider $provider, $expected, $value, $group = null, $part = null) { - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('isRealResult'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('isRealResult'); $method->setAccessible(true); $this->assertSame($expected, $method->invoke($provider, $value, $group, $part), $value); } /** - * * @return Client */ protected function getClient(array $responseQueue = []) diff --git a/tests/unit/Provider/BrowscapFullTest.php b/tests/unit/Provider/BrowscapFullTest.php index 72709ec..55cd959 100644 --- a/tests/unit/Provider/BrowscapFullTest.php +++ b/tests/unit/Provider/BrowscapFullTest.php @@ -1,41 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\BrowscapFull + * @covers \UserAgentParser\Provider\BrowscapFull + * + * @internal */ class BrowscapFullTest extends AbstractProviderTestCase { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser(\stdClass $result = null) - { - $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); - $cache->expects($this->any()) - ->method('getType') - ->will($this->returnValue('FULL')); - - $parser = self::createMock('BrowscapPHP\Browscap'); - $parser->expects($this->any()) - ->method('getCache') - ->will($this->returnValue($cache)); - $parser->expects($this->any()) - ->method('getBrowser') - ->will($this->returnValue($result)); - - return $parser; - } - public function testGetName() { $provider = new BrowscapFull($this->getParser()); @@ -48,35 +28,55 @@ public function testDetectionCapabilities() $provider = new BrowscapFull($this->getParser()); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ], $provider->getDetectionCapabilities()); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser(stdClass $result = null) + { + $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); + $cache->expects($this->any()) + ->method('getType') + ->willReturn('FULL'); + + $parser = self::createMock('BrowscapPHP\Browscap'); + $parser->expects($this->any()) + ->method('getCache') + ->willReturn($cache); + $parser->expects($this->any()) + ->method('getBrowser') + ->willReturn($result); + + return $parser; + } } diff --git a/tests/unit/Provider/BrowscapLiteTest.php b/tests/unit/Provider/BrowscapLiteTest.php index c919477..3d9ec32 100644 --- a/tests/unit/Provider/BrowscapLiteTest.php +++ b/tests/unit/Provider/BrowscapLiteTest.php @@ -1,41 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\BrowscapLite + * @covers \UserAgentParser\Provider\BrowscapLite + * + * @internal */ class BrowscapLiteTest extends AbstractProviderTestCase { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser(\stdClass $result = null) - { - $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); - $cache->expects($this->any()) - ->method('getType') - ->will($this->returnValue('LITE')); - - $parser = self::createMock('BrowscapPHP\Browscap'); - $parser->expects($this->any()) - ->method('getCache') - ->will($this->returnValue($cache)); - $parser->expects($this->any()) - ->method('getBrowser') - ->will($this->returnValue($result)); - - return $parser; - } - public function testGetName() { $provider = new BrowscapLite($this->getParser()); @@ -48,35 +28,55 @@ public function testDetectionCapabilities() $provider = new BrowscapLite($this->getParser()); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser(stdClass $result = null) + { + $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); + $cache->expects($this->any()) + ->method('getType') + ->willReturn('LITE'); + + $parser = self::createMock('BrowscapPHP\Browscap'); + $parser->expects($this->any()) + ->method('getCache') + ->willReturn($cache); + $parser->expects($this->any()) + ->method('getBrowser') + ->willReturn($result); + + return $parser; + } } diff --git a/tests/unit/Provider/BrowscapPhpTest.php b/tests/unit/Provider/BrowscapPhpTest.php index 67d55bd..d1e93e4 100644 --- a/tests/unit/Provider/BrowscapPhpTest.php +++ b/tests/unit/Provider/BrowscapPhpTest.php @@ -1,40 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\BrowscapPhp + * @covers \UserAgentParser\Provider\BrowscapPhp + * + * @internal */ class BrowscapPhpTest extends AbstractProviderTestCase { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser(\stdClass $result = null) - { - $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); - $cache->expects($this->any()) - ->method('getType') - ->will($this->returnValue('')); - - $parser = self::createMock('BrowscapPHP\Browscap'); - $parser->expects($this->any()) - ->method('getCache') - ->will($this->returnValue($cache)); - $parser->expects($this->any()) - ->method('getBrowser') - ->will($this->returnValue($result)); - - return $parser; - } - public function testGetName() { $provider = new BrowscapPhp($this->getParser()); @@ -47,35 +28,55 @@ public function testDetectionCapabilities() $provider = new BrowscapPhp($this->getParser()); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser(stdClass $result = null) + { + $cache = self::createMock('BrowscapPHP\Cache\BrowscapCache'); + $cache->expects($this->any()) + ->method('getType') + ->willReturn(''); + + $parser = self::createMock('BrowscapPHP\Browscap'); + $parser->expects($this->any()) + ->method('getCache') + ->willReturn($cache); + $parser->expects($this->any()) + ->method('getBrowser') + ->willReturn($result); + + return $parser; + } } diff --git a/tests/unit/Provider/ChainTest.php b/tests/unit/Provider/ChainTest.php index 8134183..f7f4b2e 100644 --- a/tests/unit/Provider/ChainTest.php +++ b/tests/unit/Provider/ChainTest.php @@ -1,31 +1,33 @@ * @license MIT * - * @covers UserAgentParser\Provider\Chain + * @covers \UserAgentParser\Provider\Chain + * + * @internal */ class ChainTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** - * - * @var \PHPUnit_Framework_MockObject_MockObject + * @var PHPUnit_Framework_MockObject_MockObject */ private $provider; - public function setUp() + protected function setUp() { parent::setUp(); $this->provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); } - public function tearDown() + protected function tearDown() { parent::tearDown(); @@ -90,34 +92,33 @@ public function testDetectionCapabilities() $provider = new Chain(); $this->assertEquals([ - 'browser' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -126,14 +127,11 @@ public function testIsRealResult() { $provider = new Chain(); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'something UNKNOWN'); } /** - * * @todo should throw another exception! since no provider was provided! * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -172,7 +170,7 @@ public function testParseWithProviderAndValidResult() $provider = $this->provider; $provider->expects($this->any()) ->method('parse') - ->will($this->returnValue($resultMock)); + ->willReturn($resultMock); $chain = new Chain([ $provider, @@ -191,15 +189,15 @@ public function testProviderNameAndVersionIsInResult() $resultMock = self::createMock('UserAgentParser\Model\UserAgent'); $resultMock->expects($this->any()) ->method('getProviderName') - ->will($this->returnValue('SomeProvider')); + ->willReturn('SomeProvider'); $resultMock->expects($this->any()) ->method('getProviderVersion') - ->will($this->returnValue('1.2')); + ->willReturn('1.2'); $provider = $this->provider; $provider->expects($this->any()) ->method('parse') - ->will($this->returnValue($resultMock)); + ->willReturn($resultMock); $chain = new Chain([ $provider, diff --git a/tests/unit/Provider/DonatjUAParserTest.php b/tests/unit/Provider/DonatjUAParserTest.php index 96d108f..4ee31ef 100644 --- a/tests/unit/Provider/DonatjUAParserTest.php +++ b/tests/unit/Provider/DonatjUAParserTest.php @@ -1,19 +1,18 @@ * @license MIT */ + namespace UserAgentParser\Provider { - use UserAgentParserTest\Unit\Provider\DonatjUAParserTest; /** * This is need to mock the testing! * - * @param string $userAgent + * @param string $userAgent + * * @return array */ function parse_user_agent($userAgent) @@ -24,13 +23,15 @@ function parse_user_agent($userAgent) ]; } } + namespace UserAgentParserTest\Unit\Provider { - use UserAgentParser\Provider\DonatjUAParser; /** - * @covers UserAgentParser\Provider\DonatjUAParser + * @covers \UserAgentParser\Provider\DonatjUAParser + * + * @internal */ class DonatjUAParserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -78,34 +79,33 @@ public function testDetectionCapabilities() $provider = new DonatjUAParser(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -114,9 +114,7 @@ public function testIsRealResult() { $provider = new DonatjUAParser(); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'UNKNOWN something'); } @@ -131,7 +129,7 @@ public function testParseNoResultFoundException() $provider = new DonatjUAParser(); $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('functionName'); + $property = $reflection->getProperty('functionName'); $property->setAccessible(true); $property->setValue($provider, '\UserAgentParser\Provider\parse_user_agent'); @@ -149,7 +147,7 @@ public function testProviderNameAndVersionIsInResult() $provider = new DonatjUAParser(); $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('functionName'); + $property = $reflection->getProperty('functionName'); $property->setAccessible(true); $property->setValue($provider, '\UserAgentParser\Provider\parse_user_agent'); @@ -164,7 +162,7 @@ public function testProviderNameAndVersionIsInResult() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { @@ -174,7 +172,7 @@ public function testParseBrowser() $provider = new DonatjUAParser(); $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('functionName'); + $property = $reflection->getProperty('functionName'); $property->setAccessible(true); $property->setValue($provider, '\UserAgentParser\Provider\parse_user_agent'); @@ -186,7 +184,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 0, diff --git a/tests/unit/Provider/EndorphinTest.php b/tests/unit/Provider/EndorphinTest.php index b75d94c..0122d61 100644 --- a/tests/unit/Provider/EndorphinTest.php +++ b/tests/unit/Provider/EndorphinTest.php @@ -1,33 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\Endorphin + * @covers \UserAgentParser\Provider\Endorphin + * + * @internal */ class EndorphinTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser() - { - $parser = self::createMock('EndorphinStudio\Detector\DetectorResult'); - - $parser->Browser = self::createMock('EndorphinStudio\Detector\Browser'); - $parser->OS = self::createMock('EndorphinStudio\Detector\OS'); - $parser->Device = self::createMock('EndorphinStudio\Detector\Device'); - $parser->Robot = self::createMock('EndorphinStudio\Detector\Robot'); - - return $parser; - } - public function testGetName() { $provider = new Endorphin(); @@ -68,34 +56,33 @@ public function testDetectionCapabilities() $provider = new Endorphin(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ], $provider->getDetectionCapabilities()); } @@ -104,9 +91,7 @@ public function testIsRealResult() { $provider = new Endorphin(); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'something'); } @@ -126,8 +111,8 @@ public function testParseNoResultFoundException() $provider = new Endorphin(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -142,15 +127,15 @@ public function testProviderNameAndVersionIsInResult() $parser = $this->getParser(); $parser->Robot->expects($this->any()) ->method('getName') - ->will($this->returnValue('Google (Smartphone)')); + ->willReturn('Google (Smartphone)'); $parser->Robot->expects($this->any()) ->method('getType') - ->will($this->returnValue('Search Engine')); + ->willReturn('Search Engine'); $provider = new Endorphin(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -161,22 +146,22 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { $parser = $this->getParser(); $parser->Robot->expects($this->any()) ->method('getName') - ->will($this->returnValue('Google (Smartphone)')); + ->willReturn('Google (Smartphone)'); $parser->Robot->expects($this->any()) ->method('getType') - ->will($this->returnValue('Search Engine')); + ->willReturn('Search Engine'); $provider = new Endorphin(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -185,8 +170,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Google (Smartphone)', - 'type' => 'Search Engine', + 'name' => 'Google (Smartphone)', + 'type' => 'Search Engine', ], ]; @@ -194,22 +179,22 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $parser = $this->getParser(); $parser->Browser->expects($this->any()) ->method('getName') - ->will($this->returnValue('Firefox')); + ->willReturn('Firefox'); $parser->Browser->expects($this->any()) ->method('getVersion') - ->will($this->returnValue('3.2.1')); + ->willReturn('3.2.1'); $provider = new Endorphin(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -217,7 +202,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -234,22 +219,22 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { $parser = $this->getParser(); $parser->OS->expects($this->any()) ->method('getName') - ->will($this->returnValue('Windows')); + ->willReturn('Windows'); $parser->OS->expects($this->any()) ->method('getVersion') - ->will($this->returnValue('7.0.1')); + ->willReturn('7.0.1'); $provider = new Endorphin(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -257,7 +242,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -274,22 +259,22 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { $parser = $this->getParser(); $parser->Device->expects($this->any()) ->method('getName') - ->will($this->returnValue('iPhone')); + ->willReturn('iPhone'); $parser->Device->expects($this->any()) ->method('getType') - ->will($this->returnValue('mobile')); + ->willReturn('mobile'); $provider = new Endorphin(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -299,13 +284,28 @@ public function testParseDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser() + { + $parser = self::createMock('EndorphinStudio\Detector\DetectorResult'); + + $parser->Browser = self::createMock('EndorphinStudio\Detector\Browser'); + $parser->OS = self::createMock('EndorphinStudio\Detector\OS'); + $parser->Device = self::createMock('EndorphinStudio\Detector\Device'); + $parser->Robot = self::createMock('EndorphinStudio\Detector\Robot'); + + return $parser; + } } diff --git a/tests/unit/Provider/HandsetDetectionTest.php b/tests/unit/Provider/HandsetDetectionTest.php index 93fd8e3..b31c8b5 100644 --- a/tests/unit/Provider/HandsetDetectionTest.php +++ b/tests/unit/Provider/HandsetDetectionTest.php @@ -1,28 +1,20 @@ * @license MIT * - * @covers UserAgentParser\Provider\HandsetDetection + * @covers \UserAgentParser\Provider\HandsetDetection + * + * @internal */ class HandsetDetectionTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser() - { - $parser = self::createMock('HandsetDetection\HD4'); - - return $parser; - } - public function testGetName() { $provider = new HandsetDetection($this->getParser()); @@ -63,34 +55,33 @@ public function testDetectionCapabilities() $provider = new HandsetDetection($this->getParser()); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => false, + 'model' => true, + 'brand' => true, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -99,18 +90,14 @@ public function testIsRealResult() { $provider = new HandsetDetection($this->getParser()); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'something'); $this->assertIsRealResult($provider, false, 'generic', 'device', 'model'); $this->assertIsRealResult($provider, true, 'generic something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something generic', 'device', 'model'); - /* - * device model - */ + // device model $this->assertIsRealResult($provider, false, 'analyzer', 'device', 'model'); $this->assertIsRealResult($provider, false, 'analyzer something', 'device', 'model'); $this->assertIsRealResult($provider, false, 'something analyzer', 'device', 'model'); @@ -159,10 +146,10 @@ public function testParseNoResultFoundExceptionDefaultValue() $parser->expects($this->any()) ->method('getReply') ->willReturn([ - 'hd_specs' => [ - 'general_browser' => 'generic', - ], - ]); + 'hd_specs' => [ + 'general_browser' => 'generic', + ], + ]); $provider = new HandsetDetection($parser); @@ -181,11 +168,11 @@ public function testProviderNameAndVersionIsInResult() $parser->expects($this->any()) ->method('getReply') ->willReturn([ - 'hd_specs' => [ - 'general_browser' => 'Firefox', - 'general_browser_version' => '3.2.1', - ], - ]); + 'hd_specs' => [ + 'general_browser' => 'Firefox', + 'general_browser_version' => '3.2.1', + ], + ]); $provider = new HandsetDetection($parser); @@ -196,7 +183,7 @@ public function testProviderNameAndVersionIsInResult() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { @@ -207,11 +194,11 @@ public function testParseBrowser() $parser->expects($this->any()) ->method('getReply') ->willReturn([ - 'hd_specs' => [ - 'general_browser' => 'Firefox', - 'general_browser_version' => '3.2.1', - ], - ]); + 'hd_specs' => [ + 'general_browser' => 'Firefox', + 'general_browser_version' => '3.2.1', + ], + ]); $provider = new HandsetDetection($parser); @@ -219,7 +206,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -236,7 +223,7 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { @@ -247,11 +234,11 @@ public function testParseOperatingSystem() $parser->expects($this->any()) ->method('getReply') ->willReturn([ - 'hd_specs' => [ - 'general_platform' => 'Windows', - 'general_platform_version' => '7.0.1', - ], - ]); + 'hd_specs' => [ + 'general_platform' => 'Windows', + 'general_platform_version' => '7.0.1', + ], + ]); $provider = new HandsetDetection($parser); @@ -259,7 +246,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -276,7 +263,7 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { @@ -287,11 +274,11 @@ public function testParseDevice() $parser->expects($this->any()) ->method('getReply') ->willReturn([ - 'hd_specs' => [ - 'general_model' => 'iPhone', - 'general_vendor' => 'Apple', - ], - ]); + 'hd_specs' => [ + 'general_model' => 'iPhone', + 'general_vendor' => 'Apple', + ], + ]); $provider = new HandsetDetection($parser); @@ -301,13 +288,23 @@ public function testParseDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser() + { + $parser = self::createMock('HandsetDetection\HD4'); + + return $parser; + } } diff --git a/tests/unit/Provider/Http/AbstractHttpProviderTest.php b/tests/unit/Provider/Http/AbstractHttpProviderTest.php index 0dd1cb6..91f7405 100644 --- a/tests/unit/Provider/Http/AbstractHttpProviderTest.php +++ b/tests/unit/Provider/Http/AbstractHttpProviderTest.php @@ -1,23 +1,25 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\AbstractHttpProvider + * @covers \UserAgentParser\Provider\Http\AbstractHttpProvider + * + * @internal */ class AbstractHttpProviderTest extends AbstractProviderTestCase { /** - * A general RequestException + * A general RequestException. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -31,8 +33,8 @@ public function testGetResultRequestException() $this->getClient($responseQueue), ]); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('getResponse'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('getResponse'); $method->setAccessible(true); $request = new Request('GET', 'http://example.com'); @@ -41,7 +43,7 @@ public function testGetResultRequestException() } /** - * Got a response, but not 200 + * Got a response, but not 200. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -55,8 +57,8 @@ public function testGetResultRequestExceptionNotStatus200() $this->getClient($responseQueue), ]); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('getResponse'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('getResponse'); $method->setAccessible(true); $request = new Request('GET', 'http://example.com'); @@ -65,7 +67,7 @@ public function testGetResultRequestExceptionNotStatus200() } /** - * Valid response + * Valid response. */ public function testGetResultValid() { @@ -77,8 +79,8 @@ public function testGetResultValid() $this->getClient($responseQueue), ]); - $reflection = new \ReflectionClass($provider); - $method = $reflection->getMethod('getResponse'); + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('getResponse'); $method->setAccessible(true); $request = new Request('GET', 'http://example.com'); diff --git a/tests/unit/Provider/Http/DeviceAtlasComTest.php b/tests/unit/Provider/Http/DeviceAtlasComTest.php index 947e64c..4e5e2f7 100644 --- a/tests/unit/Provider/Http/DeviceAtlasComTest.php +++ b/tests/unit/Provider/Http/DeviceAtlasComTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\DeviceAtlasCom + * @covers \UserAgentParser\Provider\Http\DeviceAtlasCom + * + * @internal */ class DeviceAtlasComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -57,34 +58,33 @@ public function testDetectionCapabilities() $provider = new DeviceAtlasCom($this->getClient(), 'apiKey123'); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -93,14 +93,12 @@ public function testIsRealResult() { $provider = new DeviceAtlasCom($this->getClient(), 'apiKey123'); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'something UNKNOWN'); } /** - * Empty user agent + * Empty user agent. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -116,7 +114,7 @@ public function testParseNoResultFoundExceptionEmptyUserAgent() } /** - * 403 + * 403. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ @@ -134,7 +132,7 @@ public function testParseInvalidCredentialsException() } /** - * 500 + * 500. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -150,7 +148,7 @@ public function testParseRequestException() } /** - * No JSON returned + * No JSON returned. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -168,7 +166,7 @@ public function testParseRequestExceptionContentType() } /** - * Missing data + * Missing data. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -186,13 +184,13 @@ public function testParseRequestExceptionNoData() } /** - * no result found + * no result found. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->properties = new stdClass(); $responseQueue = [ @@ -211,11 +209,11 @@ public function testParseNoResultFoundException() */ public function testProviderNameAndVersionIsInResult() { - $properties = new stdClass(); - $properties->browserName = 'Firefox'; + $properties = new stdClass(); + $properties->browserName = 'Firefox'; $properties->browserVersion = '3.2.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->properties = $properties; $responseQueue = [ @@ -233,15 +231,15 @@ public function testProviderNameAndVersionIsInResult() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $properties = new stdClass(); - $properties->browserName = 'Firefox'; + $properties = new stdClass(); + $properties->browserName = 'Firefox'; $properties->browserVersion = '3.2.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->properties = $properties; $responseQueue = [ @@ -256,7 +254,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -273,14 +271,14 @@ public function testParseBrowser() } /** - * Engine only + * Engine only. */ public function testParseEngine() { - $properties = new stdClass(); + $properties = new stdClass(); $properties->browserRenderingEngine = 'WebKit'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->properties = $properties; $responseQueue = [ @@ -295,7 +293,7 @@ public function testParseEngine() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => null, 'minor' => null, @@ -312,15 +310,15 @@ public function testParseEngine() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { - $properties = new stdClass(); - $properties->osName = 'Windows'; + $properties = new stdClass(); + $properties->osName = 'Windows'; $properties->osVersion = '7'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->properties = $properties; $responseQueue = [ @@ -335,7 +333,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => null, @@ -352,14 +350,14 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { - $properties = new stdClass(); + $properties = new stdClass(); $properties->primaryHardwareType = 'mobile'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->properties = $properties; $responseQueue = [ @@ -376,10 +374,10 @@ public function testParseDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; diff --git a/tests/unit/Provider/Http/FiftyOneDegreesComTest.php b/tests/unit/Provider/Http/FiftyOneDegreesComTest.php index 2a55f95..85b2fdc 100644 --- a/tests/unit/Provider/Http/FiftyOneDegreesComTest.php +++ b/tests/unit/Provider/Http/FiftyOneDegreesComTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\FiftyOneDegreesCom + * @covers \UserAgentParser\Provider\Http\FiftyOneDegreesCom + * + * @internal */ class FiftyOneDegreesComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -56,34 +58,33 @@ public function testDetectionCapabilities() $provider = new FiftyOneDegreesCom($this->getClient(), 'apiKey123'); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -92,16 +93,14 @@ public function testIsRealResult() { $provider = new FiftyOneDegreesCom($this->getClient(), 'apiKey123'); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'Unknown'); $this->assertIsRealResult($provider, true, 'Unknown something'); $this->assertIsRealResult($provider, true, 'something Unknown'); } /** - * Empty user agent + * Empty user agent. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -121,7 +120,7 @@ public function testParseNoResultFoundExceptionEmptyUserAgent() */ public function testParseNoResultFoundException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'None'; $responseQueue = [ @@ -136,7 +135,7 @@ public function testParseNoResultFoundException() } /** - * No JSON returned + * No JSON returned. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -154,13 +153,13 @@ public function testParseRequestExceptionContentType() } /** - * user_key_invalid + * user_key_invalid. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ public function testParseInvalidCredentialsExceptionInvalidKey() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'None'; $responseQueue = [ @@ -175,13 +174,13 @@ public function testParseInvalidCredentialsExceptionInvalidKey() } /** - * unknown + * unknown. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestExceptionUnknown() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'None'; $responseQueue = [ @@ -200,7 +199,7 @@ public function testParseRequestExceptionUnknown() */ public function testParseRequestExceptionMissingData() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; $responseQueue = [ @@ -219,14 +218,14 @@ public function testParseRequestExceptionMissingData() */ public function testProviderNameAndVersionIsInResult() { - $parseResult = new stdClass(); + $parseResult = new stdClass(); $parseResult->IsCrawler = [ 'True', ]; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; - $rawResult->Values = $parseResult; + $rawResult->Values = $parseResult; $responseQueue = [ new Response(200, [ @@ -243,18 +242,18 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { - $parseResult = new stdClass(); + $parseResult = new stdClass(); $parseResult->IsCrawler = [ 'True', ]; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; - $rawResult->Values = $parseResult; + $rawResult->Values = $parseResult; $responseQueue = [ new Response(200, [ @@ -269,8 +268,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -278,11 +277,11 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $parseResult = new stdClass(); + $parseResult = new stdClass(); $parseResult->BrowserName = [ 'Firefox', ]; @@ -290,9 +289,9 @@ public function testParseBrowser() '3.2.1', ]; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; - $rawResult->Values = $parseResult; + $rawResult->Values = $parseResult; $responseQueue = [ new Response(200, [ @@ -306,7 +305,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -323,18 +322,18 @@ public function testParseBrowser() } /** - * Engine only + * Engine only. */ public function testParseEngine() { - $parseResult = new stdClass(); + $parseResult = new stdClass(); $parseResult->LayoutEngine = [ 'Webkit', ]; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; - $rawResult->Values = $parseResult; + $rawResult->Values = $parseResult; $responseQueue = [ new Response(200, [ @@ -348,7 +347,7 @@ public function testParseEngine() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => null, 'minor' => null, @@ -365,11 +364,11 @@ public function testParseEngine() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { - $parseResult = new stdClass(); + $parseResult = new stdClass(); $parseResult->PlatformName = [ 'BlackBerryOS', ]; @@ -377,9 +376,9 @@ public function testParseOperatingSystem() '6.0.0', ]; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; - $rawResult->Values = $parseResult; + $rawResult->Values = $parseResult; $responseQueue = [ new Response(200, [ @@ -393,7 +392,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'BlackBerryOS', + 'name' => 'BlackBerryOS', 'version' => [ 'major' => 6, 'minor' => 0, @@ -410,11 +409,11 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { - $parseResult = new stdClass(); + $parseResult = new stdClass(); $parseResult->HardwareVendor = [ 'Dell', ]; @@ -428,9 +427,9 @@ public function testParseDevice() 'True', ]; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; - $rawResult->Values = $parseResult; + $rawResult->Values = $parseResult; $responseQueue = [ new Response(200, [ @@ -446,10 +445,10 @@ public function testParseDevice() 'device' => [ 'model' => 'Galaxy Note', 'brand' => 'Dell', - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], ]; diff --git a/tests/unit/Provider/Http/NeutrinoApiComTest.php b/tests/unit/Provider/Http/NeutrinoApiComTest.php index 85d9d23..7dab972 100644 --- a/tests/unit/Provider/Http/NeutrinoApiComTest.php +++ b/tests/unit/Provider/Http/NeutrinoApiComTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\NeutrinoApiCom + * @covers \UserAgentParser\Provider\Http\NeutrinoApiCom + * + * @internal */ class NeutrinoApiComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -57,34 +58,33 @@ public function testDetectionCapabilities() $provider = new NeutrinoApiCom($this->getClient(), 'apiUser', 'apiKey123'); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -93,16 +93,12 @@ public function testIsRealResult() { $provider = new NeutrinoApiCom($this->getClient(), 'apiUser', 'apiKey123'); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'unknown'); $this->assertIsRealResult($provider, true, 'unknown something'); $this->assertIsRealResult($provider, true, 'something unknown'); - /* - * device brand - */ + // device brand $this->assertIsRealResult($provider, false, 'Generic', 'device', 'brand'); $this->assertIsRealResult($provider, true, 'Generic something', 'device', 'brand'); $this->assertIsRealResult($provider, true, 'something Generic', 'device', 'brand'); @@ -111,9 +107,7 @@ public function testIsRealResult() $this->assertIsRealResult($provider, true, 'generic web browser something', 'device', 'brand'); $this->assertIsRealResult($provider, true, 'something generic web browser', 'device', 'brand'); - /* - * device model - */ + // device model $this->assertIsRealResult($provider, false, 'Android', 'device', 'model'); $this->assertIsRealResult($provider, false, 'Android something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something Android', 'device', 'model'); @@ -144,7 +138,7 @@ public function testIsRealResult() } /** - * Empty user agent + * Empty user agent. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -160,7 +154,7 @@ public function testParseNoResultFoundExceptionEmptyUserAgent() } /** - * 403 + * 403. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ @@ -176,7 +170,7 @@ public function testParseInvalidCredentialsException() } /** - * 500 + * 500. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -192,7 +186,7 @@ public function testParseRequestException() } /** - * No JSON returned + * No JSON returned. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -210,14 +204,14 @@ public function testParseRequestExceptionContentType() } /** - * Error code 1 + * Error code 1. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestExceptionCode1() { - $rawResult = new stdClass(); - $rawResult->api_error = 1; + $rawResult = new stdClass(); + $rawResult->api_error = 1; $rawResult->api_error_msg = 'something'; $responseQueue = [ @@ -232,14 +226,14 @@ public function testParseRequestExceptionCode1() } /** - * Error code 2 + * Error code 2. * * @expectedException \UserAgentParser\Exception\LimitationExceededException */ public function testParseLimitationExceededExceptionCode2() { - $rawResult = new stdClass(); - $rawResult->api_error = 2; + $rawResult = new stdClass(); + $rawResult->api_error = 2; $rawResult->api_error_msg = 'something'; $responseQueue = [ @@ -254,14 +248,14 @@ public function testParseLimitationExceededExceptionCode2() } /** - * Error code something + * Error code something. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestExceptionCodeSomething() { - $rawResult = new stdClass(); - $rawResult->api_error = 1337; + $rawResult = new stdClass(); + $rawResult->api_error = 1337; $rawResult->api_error_msg = 'something'; $responseQueue = [ @@ -276,7 +270,7 @@ public function testParseRequestExceptionCodeSomething() } /** - * Missing data + * Missing data. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -294,13 +288,13 @@ public function testParseRequestExceptionNoData() } /** - * no result found + * no result found. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->type = 'unknown'; $responseQueue = [ @@ -319,8 +313,8 @@ public function testParseNoResultFoundException() */ public function testProviderNameAndVersionIsInResult() { - $rawResult = new stdClass(); - $rawResult->type = 'robot'; + $rawResult = new stdClass(); + $rawResult->type = 'robot'; $rawResult->browser_name = 'Googlebot'; $responseQueue = [ @@ -338,12 +332,12 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { - $rawResult = new stdClass(); - $rawResult->type = 'robot'; + $rawResult = new stdClass(); + $rawResult->type = 'robot'; $rawResult->browser_name = 'Googlebot'; $responseQueue = [ @@ -359,8 +353,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -368,14 +362,14 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $rawResult = new stdClass(); - $rawResult->type = 'desktop-browser'; + $rawResult = new stdClass(); + $rawResult->type = 'desktop-browser'; $rawResult->browser_name = 'Firefox'; - $rawResult->version = '3.2.1'; + $rawResult->version = '3.2.1'; $responseQueue = [ new Response(200, [ @@ -389,7 +383,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -404,10 +398,10 @@ public function testParseBrowser() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'desktop-browser', + 'type' => 'desktop-browser', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -415,13 +409,13 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { - $rawResult = new stdClass(); - $rawResult->type = 'desktop-browser'; - $rawResult->operating_system_family = 'Windows'; + $rawResult = new stdClass(); + $rawResult->type = 'desktop-browser'; + $rawResult->operating_system_family = 'Windows'; $rawResult->operating_system_version = '7'; $responseQueue = [ @@ -436,7 +430,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => null, @@ -451,10 +445,10 @@ public function testParseOperatingSystem() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'desktop-browser', + 'type' => 'desktop-browser', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -462,15 +456,15 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { - $rawResult = new stdClass(); - $rawResult->type = 'mobile-browser'; + $rawResult = new stdClass(); + $rawResult->type = 'mobile-browser'; $rawResult->mobile_model = 'iPhone'; $rawResult->mobile_brand = 'Apple'; - $rawResult->is_mobile = true; + $rawResult->is_mobile = true; $responseQueue = [ new Response(200, [ @@ -486,10 +480,10 @@ public function testParseDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'mobile-browser', + 'type' => 'mobile-browser', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -497,12 +491,12 @@ public function testParseDevice() } /** - * Device - default value + * Device - default value. */ public function testParseDeviceDefaultValue() { - $rawResult = new stdClass(); - $rawResult->type = 'mobile-browser'; + $rawResult = new stdClass(); + $rawResult->type = 'mobile-browser'; $rawResult->mobile_model = 'Android'; $rawResult->mobile_brand = 'Generic'; @@ -520,10 +514,10 @@ public function testParseDeviceDefaultValue() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'mobile-browser', + 'type' => 'mobile-browser', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; diff --git a/tests/unit/Provider/Http/UdgerComTest.php b/tests/unit/Provider/Http/UdgerComTest.php index afc3b8f..38d2db2 100644 --- a/tests/unit/Provider/Http/UdgerComTest.php +++ b/tests/unit/Provider/Http/UdgerComTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\UdgerCom + * @covers \UserAgentParser\Provider\Http\UdgerCom + * + * @internal */ class UdgerComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -57,34 +58,33 @@ public function testDetectionCapabilities() $provider = new UdgerCom($this->getClient(), 'apiKey123'); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -93,16 +93,14 @@ public function testIsRealResult() { $provider = new UdgerCom($this->getClient(), 'apiKey123'); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'unknown'); $this->assertIsRealResult($provider, true, 'unknown something'); $this->assertIsRealResult($provider, true, 'something unknown'); } /** - * Empty user agent + * Empty user agent. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -118,13 +116,13 @@ public function testParseNoResultFoundExceptionEmptyUserAgent() } /** - * 200 - flag 4 + * 200 - flag 4. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ public function testParseInvalidCredentialsException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->flag = 4; $responseQueue = [ @@ -139,13 +137,13 @@ public function testParseInvalidCredentialsException() } /** - * 200 - flag 6 + * 200 - flag 6. * * @expectedException \UserAgentParser\Exception\LimitationExceededException */ public function testParseLimitationExceededException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->flag = 6; $responseQueue = [ @@ -160,13 +158,13 @@ public function testParseLimitationExceededException() } /** - * 200 - flag 99 + * 200 - flag 99. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestException1() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->flag = 99; $responseQueue = [ @@ -181,7 +179,7 @@ public function testParseRequestException1() } /** - * 500 + * 500. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -197,7 +195,7 @@ public function testParseRequestException2() } /** - * No JSON returned + * No JSON returned. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -215,13 +213,13 @@ public function testParseRequestExceptionContentType() } /** - * No result found + * No result found. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->flag = 3; $responseQueue = [ @@ -236,7 +234,7 @@ public function testParseNoResultFoundException() } /** - * Missing data + * Missing data. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -260,11 +258,11 @@ public function testParseRequestExceptionNoData() */ public function testProviderNameAndVersionIsInResult() { - $info = new stdClass(); - $info->type = 'Robot'; + $info = new stdClass(); + $info->type = 'Robot'; $info->ua_family = 'Googlebot'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->info = $info; $responseQueue = [ @@ -282,15 +280,15 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { - $info = new stdClass(); - $info->type = 'Robot'; + $info = new stdClass(); + $info->type = 'Robot'; $info->ua_family = 'Googlebot'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->info = $info; $responseQueue = [ @@ -306,8 +304,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -315,15 +313,15 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $info = new stdClass(); + $info = new stdClass(); $info->ua_family = 'Firefox'; - $info->ua_ver = '3.0.1'; + $info->ua_ver = '3.0.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->info = $info; $responseQueue = [ @@ -338,7 +336,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 0, @@ -355,14 +353,14 @@ public function testParseBrowser() } /** - * Rendering engine only + * Rendering engine only. */ public function testParseRenderingEngine() { - $info = new stdClass(); + $info = new stdClass(); $info->ua_engine = 'Webkit'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->info = $info; $responseQueue = [ @@ -377,7 +375,7 @@ public function testParseRenderingEngine() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => null, 'minor' => null, @@ -394,14 +392,14 @@ public function testParseRenderingEngine() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { - $info = new stdClass(); + $info = new stdClass(); $info->os_family = 'Windows'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->info = $info; $responseQueue = [ @@ -416,7 +414,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => null, 'minor' => null, @@ -433,14 +431,14 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { - $info = new stdClass(); + $info = new stdClass(); $info->device_name = 'watch'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->info = $info; $responseQueue = [ @@ -457,10 +455,10 @@ public function testParseDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'watch', + 'type' => 'watch', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; diff --git a/tests/unit/Provider/Http/UserAgentApiComTest.php b/tests/unit/Provider/Http/UserAgentApiComTest.php index e670853..099e292 100644 --- a/tests/unit/Provider/Http/UserAgentApiComTest.php +++ b/tests/unit/Provider/Http/UserAgentApiComTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\UserAgentApiCom + * @covers \UserAgentParser\Provider\Http\UserAgentApiCom + * + * @internal */ class UserAgentApiComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -57,34 +58,33 @@ public function testDetectionCapabilities() $provider = new UserAgentApiCom($this->getClient(), 'apiKey123'); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -93,14 +93,12 @@ public function testIsRealResult() { $provider = new UserAgentApiCom($this->getClient(), 'apiKey123'); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'something UNKNOWN'); } /** - * Empty user agent + * Empty user agent. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -116,14 +114,14 @@ public function testParseNoResultFoundExceptionEmptyUserAgent() } /** - * 400 - key_invalid + * 400 - key_invalid. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ public function testParseInvalidCredentialsException() { - $rawResult = new stdClass(); - $rawResult->error = new stdClass(); + $rawResult = new stdClass(); + $rawResult->error = new stdClass(); $rawResult->error->code = 'key_invalid'; $responseQueue = [ @@ -136,14 +134,14 @@ public function testParseInvalidCredentialsException() } /** - * 400 - useragent_invalid + * 400 - useragent_invalid. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestExceptionUserAgentInvalid() { - $rawResult = new stdClass(); - $rawResult->error = new stdClass(); + $rawResult = new stdClass(); + $rawResult->error = new stdClass(); $rawResult->error->code = 'useragent_invalid'; $responseQueue = [ @@ -156,7 +154,7 @@ public function testParseRequestExceptionUserAgentInvalid() } /** - * 500 + * 500. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -172,7 +170,7 @@ public function testParseRequestException() } /** - * No JSON returned + * No JSON returned. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -190,14 +188,14 @@ public function testParseRequestExceptionContentType() } /** - * No result found + * No result found. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoResultFoundException() { - $rawResult = new stdClass(); - $rawResult->error = new stdClass(); + $rawResult = new stdClass(); + $rawResult->error = new stdClass(); $rawResult->error->code = 'useragent_not_found'; $responseQueue = [ @@ -212,7 +210,7 @@ public function testParseNoResultFoundException() } /** - * Missing data + * Missing data. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -236,11 +234,11 @@ public function testParseRequestExceptionNoData() */ public function testProviderNameAndVersionIsInResult() { - $data = new stdClass(); + $data = new stdClass(); $data->platform_type = 'Bot'; $data->platform_name = 'Googlebot'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->data = $data; $responseQueue = [ @@ -258,15 +256,15 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { - $data = new stdClass(); + $data = new stdClass(); $data->platform_type = 'Bot'; $data->platform_name = 'Googlebot'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->data = $data; $responseQueue = [ @@ -282,8 +280,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -291,15 +289,15 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $data = new stdClass(); - $data->browser_name = 'Firefox'; + $data = new stdClass(); + $data->browser_name = 'Firefox'; $data->browser_version = '3.0.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->data = $data; $responseQueue = [ @@ -314,7 +312,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 0, @@ -331,15 +329,15 @@ public function testParseBrowser() } /** - * Rendering engine only + * Rendering engine only. */ public function testParseRenderingEngine() { - $data = new stdClass(); - $data->engine_name = 'Webkit'; + $data = new stdClass(); + $data->engine_name = 'Webkit'; $data->engine_version = '3.2.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->data = $data; $responseQueue = [ @@ -354,7 +352,7 @@ public function testParseRenderingEngine() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => 3, 'minor' => 2, @@ -371,14 +369,14 @@ public function testParseRenderingEngine() } /** - * Device only + * Device only. */ public function testParseDevice() { - $data = new stdClass(); + $data = new stdClass(); $data->platform_type = 'mobile'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->data = $data; $responseQueue = [ @@ -395,10 +393,10 @@ public function testParseDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; diff --git a/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php b/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php index f6facce..cdb4a37 100644 --- a/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php +++ b/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php @@ -1,4 +1,5 @@ * @license MIT * - * @covers UserAgentParser\Provider\Http\WhatIsMyBrowserCom + * @covers \UserAgentParser\Provider\Http\WhatIsMyBrowserCom + * + * @internal */ class WhatIsMyBrowserComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { @@ -56,34 +58,33 @@ public function testDetectionCapabilities() $provider = new WhatIsMyBrowserCom($this->getClient(), 'apiKey123'); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ], $provider->getDetectionCapabilities()); } @@ -92,9 +93,7 @@ public function testIsRealResult() { $provider = new WhatIsMyBrowserCom($this->getClient(), 'apiKey123'); - /* - * browser name - */ + // browser name $this->assertIsRealResult($provider, false, 'Unknown Mobile Browser', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'Unknown Mobile Browser something', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'something Unknown Mobile Browser', 'browser', 'name'); @@ -111,16 +110,12 @@ public function testIsRealResult() $this->assertIsRealResult($provider, true, 'a UNIX based OS something', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'something a UNIX based OS', 'browser', 'name'); - /* - * OS name - */ + // OS name $this->assertIsRealResult($provider, false, 'Smart TV', 'operatingSystem', 'name'); $this->assertIsRealResult($provider, true, 'Smart TV something', 'operatingSystem', 'name'); $this->assertIsRealResult($provider, true, 'something Smart TV', 'operatingSystem', 'name'); - /* - * device model - */ + // device model $this->assertIsRealResult($provider, false, 'HTC', 'device', 'model'); $this->assertIsRealResult($provider, true, 'HTC something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something HTC', 'device', 'model'); @@ -143,7 +138,7 @@ public function testIsRealResult() } /** - * Empty user agent + * Empty user agent. * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ @@ -159,7 +154,7 @@ public function testParseNoResultFoundExceptionEmptyUserAgent() } /** - * No JSON returned + * No JSON returned. * * @expectedException \UserAgentParser\Exception\RequestException */ @@ -181,7 +176,7 @@ public function testParseRequestExceptionContentType() */ public function testParseNoResultFoundException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->message_code = 'no_user_agent'; $responseQueue = [ @@ -196,13 +191,13 @@ public function testParseNoResultFoundException() } /** - * usage_limit_exceeded + * usage_limit_exceeded. * * @expectedException \UserAgentParser\Exception\LimitationExceededException */ public function testParseLimitationExceededException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->message_code = 'usage_limit_exceeded'; $responseQueue = [ @@ -217,13 +212,13 @@ public function testParseLimitationExceededException() } /** - * no_api_user_key + * no_api_user_key. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ public function testParseInvalidCredentialsExceptionNoKey() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->message_code = 'no_api_user_key'; $responseQueue = [ @@ -238,13 +233,13 @@ public function testParseInvalidCredentialsExceptionNoKey() } /** - * user_key_invalid + * user_key_invalid. * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ public function testParseInvalidCredentialsExceptionInvalidKey() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->message_code = 'user_key_invalid'; $responseQueue = [ @@ -259,13 +254,13 @@ public function testParseInvalidCredentialsExceptionInvalidKey() } /** - * unknown + * unknown. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestExceptionUnknown() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'unknown'; $responseQueue = [ @@ -280,13 +275,13 @@ public function testParseRequestExceptionUnknown() } /** - * missing data + * missing data. * * @expectedException \UserAgentParser\Exception\RequestException */ public function testParseRequestExceptionMissingData() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; $responseQueue = [ @@ -305,9 +300,9 @@ public function testParseRequestExceptionMissingData() */ public function testNoResultFoundException() { - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = new stdClass(); + $rawResult->parse = new stdClass(); $responseQueue = [ new Response(200, [ @@ -325,13 +320,13 @@ public function testNoResultFoundException() */ public function testNoResultFoundExceptionDefaultValue() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; $parseResult->browser_name = 'Unknown browser'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -349,13 +344,13 @@ public function testNoResultFoundExceptionDefaultValue() */ public function testNoResultFoundExceptionDefaultValue2() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; $parseResult->operating_platform = 'Mobile'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -373,15 +368,15 @@ public function testNoResultFoundExceptionDefaultValue2() */ public function testProviderNameAndVersionIsInResult() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->software_type = 'bot'; - $parseResult->browser_name = '360Spider'; - $parseResult->software_sub_type = 'crawler'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->software_type = 'bot'; + $parseResult->browser_name = '360Spider'; + $parseResult->software_sub_type = 'crawler'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -398,19 +393,19 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->software_type = 'bot'; - $parseResult->browser_name = '360Spider'; - $parseResult->software_sub_type = 'crawler'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->software_type = 'bot'; + $parseResult->browser_name = '360Spider'; + $parseResult->software_sub_type = 'crawler'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -425,8 +420,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => '360Spider', - 'type' => 'crawler', + 'name' => '360Spider', + 'type' => 'crawler', ], ]; @@ -434,18 +429,18 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->browser_name = 'Firefox'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->browser_name = 'Firefox'; $parseResult->browser_version_full = '3.2.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -459,7 +454,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -476,18 +471,18 @@ public function testParseBrowser() } /** - * Browser only + * Browser only. */ public function testParseBrowserDefaultValue() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->browser_name = 'Unknown browser'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->browser_name = 'Unknown browser'; $parseResult->layout_engine_name = 'Webkit'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -501,7 +496,7 @@ public function testParseBrowserDefaultValue() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => null, 'minor' => null, @@ -518,18 +513,18 @@ public function testParseBrowserDefaultValue() } /** - * Engine only + * Engine only. */ public function testParseEngine() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->layout_engine_name = 'Webkit'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->layout_engine_name = 'Webkit'; $parseResult->layout_engine_version = '3.2.1'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -543,7 +538,7 @@ public function testParseEngine() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => 3, 'minor' => 2, @@ -560,18 +555,18 @@ public function testParseEngine() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->operating_system_name = 'BlackBerryOS'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->operating_system_name = 'BlackBerryOS'; $parseResult->operating_system_version_full = '6.0.0'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -585,7 +580,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'BlackBerryOS', + 'name' => 'BlackBerryOS', 'version' => [ 'major' => 6, 'minor' => 0, @@ -602,17 +597,17 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDeviceOnlyVendor() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; $parseResult->operating_platform_vendor_name = 'Dell'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -628,10 +623,10 @@ public function testParseDeviceOnlyVendor() 'device' => [ 'model' => null, 'brand' => 'Dell', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -639,19 +634,19 @@ public function testParseDeviceOnlyVendor() } /** - * Device only + * Device only. */ public function testParseDevice() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->operating_platform = 'Galaxy Note'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->operating_platform = 'Galaxy Note'; $parseResult->operating_platform_vendor_name = 'Dell'; - $parseResult->hardware_type = 'mobile'; + $parseResult->hardware_type = 'mobile'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -667,10 +662,10 @@ public function testParseDevice() 'device' => [ 'model' => 'Galaxy Note', 'brand' => 'Dell', - 'type' => 'mobile', + 'type' => 'mobile', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -678,18 +673,18 @@ public function testParseDevice() } /** - * Device only + * Device only. */ public function testParseDeviceDefaultValue() { - $parseResult = new stdClass(); - $parseResult->user_agent = 'A real user agent...'; - $parseResult->operating_platform = 'Android Phone'; + $parseResult = new stdClass(); + $parseResult->user_agent = 'A real user agent...'; + $parseResult->operating_platform = 'Android Phone'; $parseResult->operating_platform_vendor_name = 'Dell'; - $rawResult = new stdClass(); + $rawResult = new stdClass(); $rawResult->result = 'success'; - $rawResult->parse = $parseResult; + $rawResult->parse = $parseResult; $responseQueue = [ new Response(200, [ @@ -705,10 +700,10 @@ public function testParseDeviceDefaultValue() 'device' => [ 'model' => null, 'brand' => 'Dell', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; diff --git a/tests/unit/Provider/JenssegersAgentTest.php b/tests/unit/Provider/JenssegersAgentTest.php index 04bd2f6..202f196 100644 --- a/tests/unit/Provider/JenssegersAgentTest.php +++ b/tests/unit/Provider/JenssegersAgentTest.php @@ -1,29 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\JenssegersAgent + * @covers \UserAgentParser\Provider\JenssegersAgent + * + * @internal */ class JenssegersAgentTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser() - { - $parser = self::createMock('Jenssegers\Agent\Agent'); - - return $parser; - } - public function testGetName() { $provider = new JenssegersAgent(); @@ -64,34 +56,33 @@ public function testDetectionCapabilities() $provider = new JenssegersAgent(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => false, + 'model' => false, + 'brand' => false, + 'type' => false, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -100,9 +91,7 @@ public function testIsRealResult() { $provider = new JenssegersAgent(); - /* - * browser name - */ + // browser name $this->assertIsRealResult($provider, false, 'GenericBrowser', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'GenericBrowser something', 'browser', 'name'); $this->assertIsRealResult($provider, true, 'something GenericBrowser', 'browser', 'name'); @@ -124,8 +113,8 @@ public function testParseNoResultFoundException() $provider = new JenssegersAgent(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -140,16 +129,16 @@ public function testProviderNameAndVersionIsInResult() $parser = $this->getParser(); $parser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('robot') - ->will($this->returnValue('Googlebot')); + ->willReturn('Googlebot'); $provider = new JenssegersAgent(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -160,23 +149,23 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('robot') - ->will($this->returnValue('Googlebot')); + ->willReturn('Googlebot'); $provider = new JenssegersAgent(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -185,8 +174,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -194,22 +183,22 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('browser') - ->will($this->returnValue('Firefox')); + ->willReturn('Firefox'); $parser->expects($this->any()) ->method('version') - ->will($this->returnValue('3.2.1')); + ->willReturn('3.2.1'); $provider = new JenssegersAgent(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -217,7 +206,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -234,22 +223,22 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOs() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('platform') - ->will($this->returnValue('Windows')); + ->willReturn('Windows'); $parser->expects($this->any()) ->method('version') - ->will($this->returnValue('7.0.1')); + ->willReturn('7.0.1'); $provider = new JenssegersAgent(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -257,7 +246,7 @@ public function testParseOs() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -274,19 +263,19 @@ public function testParseOs() } /** - * Device only + * Device only. */ public function testDeviceOnly() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isMobile') - ->will($this->returnValue(true)); + ->willReturn(true); $provider = new JenssegersAgent(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -296,13 +285,23 @@ public function testDeviceOnly() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser() + { + $parser = self::createMock('Jenssegers\Agent\Agent'); + + return $parser; + } } diff --git a/tests/unit/Provider/PiwikDeviceDetectorTest.php b/tests/unit/Provider/PiwikDeviceDetectorTest.php index 436d641..fc3a3ac 100644 --- a/tests/unit/Provider/PiwikDeviceDetectorTest.php +++ b/tests/unit/Provider/PiwikDeviceDetectorTest.php @@ -1,30 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\PiwikDeviceDetector + * @covers \UserAgentParser\Provider\PiwikDeviceDetector + * + * @internal */ class PiwikDeviceDetectorTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser() - { - $parser = self::createMock('DeviceDetector\DeviceDetector'); - - return $parser; - } - public function testGetName() { $provider = new PiwikDeviceDetector(); @@ -65,34 +56,33 @@ public function testDetectionCapabilities() $provider = new PiwikDeviceDetector(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => true, + 'name' => true, + 'type' => true, ], ], $provider->getDetectionCapabilities()); } @@ -101,16 +91,12 @@ public function testIsRealResult() { $provider = new PiwikDeviceDetector(); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'UNK'); $this->assertIsRealResult($provider, true, 'UNK something'); $this->assertIsRealResult($provider, true, 'something UNK'); - /* - * bot name - */ + // bot name $this->assertIsRealResult($provider, false, 'Bot', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'Bot something', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'something Bot', 'bot', 'name'); @@ -152,9 +138,9 @@ public function testParseNoResultFoundExceptionDefaultValue() $parser = $this->getParser(); $parser->expects($this->any()) ->method('getClient') - ->will($this->returnValue([ - 'name' => 'UNK', - ])); + ->willReturn([ + 'name' => 'UNK', + ]); $provider = new PiwikDeviceDetector($parser); @@ -169,13 +155,13 @@ public function testProviderNameAndVersionIsInResult() $parser = $this->getParser(); $parser->expects($this->any()) ->method('isBot') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getBot') - ->will($this->returnValue([ - 'name' => 'Hatena RSS', - 'category' => 'something', - ])); + ->willReturn([ + 'name' => 'Hatena RSS', + 'category' => 'something', + ]); $provider = new PiwikDeviceDetector($parser); @@ -186,20 +172,20 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isBot') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getBot') - ->will($this->returnValue([ - 'name' => 'Hatena RSS', - 'category' => 'something', - ])); + ->willReturn([ + 'name' => 'Hatena RSS', + 'category' => 'something', + ]); $provider = new PiwikDeviceDetector($parser); @@ -208,8 +194,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Hatena RSS', - 'type' => 'something', + 'name' => 'Hatena RSS', + 'type' => 'something', ], ]; @@ -217,19 +203,19 @@ public function testParseBot() } /** - * Bot - name default + * Bot - name default. */ public function testParseBotNameDefault() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isBot') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getBot') - ->will($this->returnValue([ - 'name' => 'Bot', - ])); + ->willReturn([ + 'name' => 'Bot', + ]); $provider = new PiwikDeviceDetector($parser); @@ -238,8 +224,8 @@ public function testParseBotNameDefault() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -247,19 +233,19 @@ public function testParseBotNameDefault() } /** - * Bot - name default + * Bot - name default. */ public function testParseBotNameDefault2() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isBot') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getBot') - ->will($this->returnValue([ - 'name' => 'Generic Bot', - ])); + ->willReturn([ + 'name' => 'Generic Bot', + ]); $provider = new PiwikDeviceDetector($parser); @@ -268,8 +254,8 @@ public function testParseBotNameDefault2() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -277,21 +263,21 @@ public function testParseBotNameDefault2() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('getClient') - ->will($this->returnValue([ - 'name' => 'Firefox', - 'version' => '3.0', - 'engine' => 'WebKit', - ])); + ->willReturn([ + 'name' => 'Firefox', + 'version' => '3.0', + 'engine' => 'WebKit', + ]); $parser->expects($this->any()) ->method('getOs') - ->will($this->returnValue([])); + ->willReturn([]); $provider = new PiwikDeviceDetector($parser); @@ -299,7 +285,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 0, @@ -312,7 +298,7 @@ public function testParseBrowser() ], 'renderingEngine' => [ - 'name' => 'WebKit', + 'name' => 'WebKit', 'version' => [ 'major' => null, 'minor' => null, @@ -329,22 +315,22 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('getClient') - ->will($this->returnValue([ - 'engine' => DeviceDetector::UNKNOWN, - ])); + ->willReturn([ + 'engine' => DeviceDetector::UNKNOWN, + ]); $parser->expects($this->any()) ->method('getOs') - ->will($this->returnValue([ - 'name' => 'Windows', - 'version' => '7.0', - ])); + ->willReturn([ + 'name' => 'Windows', + 'version' => '7.0', + ]); $provider = new PiwikDeviceDetector($parser); @@ -352,7 +338,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -369,39 +355,39 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('getClient') - ->will($this->returnValue([])); + ->willReturn([]); $parser->expects($this->any()) ->method('getOs') - ->will($this->returnValue([])); + ->willReturn([]); $parser->expects($this->any()) ->method('getDevice') - ->will($this->returnValue(1)); + ->willReturn(1); $parser->expects($this->any()) ->method('getModel') - ->will($this->returnValue('iPhone')); + ->willReturn('iPhone'); $parser->expects($this->any()) ->method('getBrandName') - ->will($this->returnValue('Apple')); + ->willReturn('Apple'); $parser->expects($this->any()) ->method('getDeviceName') - ->will($this->returnValue('smartphone')); + ->willReturn('smartphone'); $parser->expects($this->any()) ->method('isMobile') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('isTouchEnabled') - ->will($this->returnValue(true)); + ->willReturn(true); $provider = new PiwikDeviceDetector($parser); @@ -411,13 +397,23 @@ public function testParseDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'smartphone', + 'type' => 'smartphone', 'isMobile' => true, - 'isTouch' => true, + 'isTouch' => true, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser() + { + $parser = self::createMock('DeviceDetector\DeviceDetector'); + + return $parser; + } } diff --git a/tests/unit/Provider/RequiredProviderTestInterface.php b/tests/unit/Provider/RequiredProviderTestInterface.php index c59c58d..deb16ed 100644 --- a/tests/unit/Provider/RequiredProviderTestInterface.php +++ b/tests/unit/Provider/RequiredProviderTestInterface.php @@ -1,8 +1,9 @@ * @license MIT diff --git a/tests/unit/Provider/SinergiBrowserDetectorTest.php b/tests/unit/Provider/SinergiBrowserDetectorTest.php index 50df168..dd553a5 100644 --- a/tests/unit/Provider/SinergiBrowserDetectorTest.php +++ b/tests/unit/Provider/SinergiBrowserDetectorTest.php @@ -1,51 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\SinergiBrowserDetector + * @covers \UserAgentParser\Provider\SinergiBrowserDetector + * + * @internal */ class SinergiBrowserDetectorTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getBrowserParser() - { - $parser = self::createMock('Sinergi\BrowserDetector\Browser'); - - return $parser; - } - - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getOsParser() - { - $parser = self::createMock('Sinergi\BrowserDetector\Os'); - - return $parser; - } - - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getDeviceParser() - { - $parser = self::createMock('Sinergi\BrowserDetector\Device'); - - return $parser; - } - public function testGetName() { $provider = new SinergiBrowserDetector(); @@ -86,34 +56,33 @@ public function testDetectionCapabilities() $provider = new SinergiBrowserDetector(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => false, - 'type' => false, + 'model' => true, + 'brand' => false, + 'type' => false, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -122,16 +91,12 @@ public function testIsRealResult() { $provider = new SinergiBrowserDetector(); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'unknown'); $this->assertIsRealResult($provider, true, 'unknown something'); $this->assertIsRealResult($provider, true, 'something unknown'); - /* - * device model - */ + // device model $this->assertIsRealResult($provider, false, 'Windows Phone', 'device', 'model'); $this->assertIsRealResult($provider, true, 'Windows Phone something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something Windows Phone', 'device', 'model'); @@ -153,8 +118,8 @@ public function testParseNoResultFoundException() { $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('browserParser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); $property->setValue($provider, $this->getBrowserParser()); @@ -177,15 +142,15 @@ public function testParseNoResultFoundExceptionDefaultValue() $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(false)); + ->willReturn(false); $browserParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('unknown')); + ->willReturn('unknown'); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('browserParser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); $property->setValue($provider, $browserParser); @@ -208,16 +173,16 @@ public function testParseNoResultFoundExceptionDefaultValue2() $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(false)); + ->willReturn(false); $deviceParser = $this->getDeviceParser(); $deviceParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('Windows Phone')); + ->willReturn('Windows Phone'); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('browserParser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); $property->setValue($provider, $browserParser); @@ -240,12 +205,12 @@ public function testProviderNameAndVersionIsInResult() $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(true)); + ->willReturn(true); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('browserParser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); $property->setValue($provider, $browserParser); @@ -264,19 +229,19 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(true)); + ->willReturn(true); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('browserParser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); $property->setValue($provider, $browserParser); @@ -293,8 +258,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -302,25 +267,25 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(false)); + ->willReturn(false); $browserParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('Chrome')); + ->willReturn('Chrome'); $browserParser->expects($this->any()) ->method('getVersion') - ->will($this->returnValue('28.0.1468')); + ->willReturn('28.0.1468'); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('browserParser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); $property->setValue($provider, $browserParser); @@ -336,7 +301,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Chrome', + 'name' => 'Chrome', 'version' => [ 'major' => 28, 'minor' => 0, @@ -353,21 +318,21 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { $osParser = $this->getOsParser(); $osParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('Windows')); + ->willReturn('Windows'); $osParser->expects($this->any()) ->method('getVersion') - ->will($this->returnValue('7.0.1')); + ->willReturn('7.0.1'); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); + $reflection = new ReflectionClass($provider); $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); @@ -385,7 +350,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -402,25 +367,25 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { $osParser = $this->getOsParser(); $osParser->expects($this->any()) ->method('getName') - ->will($this->returnValue(\Sinergi\BrowserDetector\Browser::UNKNOWN)); + ->willReturn(\Sinergi\BrowserDetector\Browser::UNKNOWN); $osParser->expects($this->any()) ->method('isMobile') - ->will($this->returnValue(true)); + ->willReturn(true); $deviceParser = $this->getDeviceParser(); $deviceParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('iPad')); + ->willReturn('iPad'); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); + $reflection = new ReflectionClass($provider); $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); @@ -440,10 +405,10 @@ public function testParseDevice() 'device' => [ 'model' => 'iPad', 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -451,26 +416,26 @@ public function testParseDevice() } /** - * Device - name default + * Device - name default. */ public function testParseDeviceDefaultValue() { $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) ->method('isRobot') - ->will($this->returnValue(false)); + ->willReturn(false); $browserParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('Chrome')); + ->willReturn('Chrome'); $deviceParser = $this->getDeviceParser(); $deviceParser->expects($this->any()) ->method('getName') - ->will($this->returnValue('Windows Phone')); + ->willReturn('Windows Phone'); $provider = new SinergiBrowserDetector(); - $reflection = new \ReflectionClass($provider); + $reflection = new ReflectionClass($provider); $property = $reflection->getProperty('browserParser'); $property->setAccessible(true); @@ -488,7 +453,7 @@ public function testParseDeviceDefaultValue() $expectedResult = [ 'browser' => [ - 'name' => 'Chrome', + 'name' => 'Chrome', 'version' => [ 'major' => null, 'minor' => null, @@ -503,13 +468,43 @@ public function testParseDeviceDefaultValue() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getBrowserParser() + { + $parser = self::createMock('Sinergi\BrowserDetector\Browser'); + + return $parser; + } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getOsParser() + { + $parser = self::createMock('Sinergi\BrowserDetector\Os'); + + return $parser; + } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getDeviceParser() + { + $parser = self::createMock('Sinergi\BrowserDetector\Device'); + + return $parser; + } } diff --git a/tests/unit/Provider/UAParserTest.php b/tests/unit/Provider/UAParserTest.php index 3819f28..67a8fe7 100644 --- a/tests/unit/Provider/UAParserTest.php +++ b/tests/unit/Provider/UAParserTest.php @@ -1,50 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\UAParser + * @covers \UserAgentParser\Provider\UAParser + * + * @internal */ class UAParserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \UAParser\Result\Client - */ - private function getResultMock() - { - $ua = new Result\UserAgent(); - $os = new Result\OperatingSystem(); - $device = new Result\Device(); - - $client = new Result\Client(''); - $client->ua = $ua; - $client->os = $os; - $client->device = $device; - - return $client; - } - - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser($returnValue = null) - { - $parser = self::createMock('UAParser\Parser'); - $parser->expects($this->any()) - ->method('parse') - ->will($this->returnValue($returnValue)); - - return $parser; - } - public function testGetName() { $provider = new UAParser(); @@ -85,34 +56,33 @@ public function testDetectionCapabilities() $provider = new UAParser(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => false, + 'model' => true, + 'brand' => true, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -121,16 +91,12 @@ public function testIsRealResult() { $provider = new UAParser(); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'Other'); $this->assertIsRealResult($provider, true, 'Other something'); $this->assertIsRealResult($provider, true, 'something Other'); - /* - * device brand - */ + // device brand $this->assertIsRealResult($provider, false, 'Generic', 'device', 'brand'); $this->assertIsRealResult($provider, false, 'Generic something', 'device', 'brand'); $this->assertIsRealResult($provider, true, 'something Generic', 'device', 'brand'); @@ -139,9 +105,7 @@ public function testIsRealResult() $this->assertIsRealResult($provider, true, 'unknown something', 'device', 'brand'); $this->assertIsRealResult($provider, true, 'something unknown', 'device', 'brand'); - /* - * device model - */ + // device model $this->assertIsRealResult($provider, false, 'generic', 'device', 'model'); $this->assertIsRealResult($provider, true, 'generic something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something generic', 'device', 'model'); @@ -178,9 +142,7 @@ public function testIsRealResult() $this->assertIsRealResult($provider, true, 'Android something', 'device', 'model'); $this->assertIsRealResult($provider, true, 'something Android', 'device', 'model'); - /* - * bot name - */ + // bot name $this->assertIsRealResult($provider, false, 'Other', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'Other something', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'something Other', 'bot', 'name'); @@ -231,7 +193,7 @@ public function testParseNoResultFoundException() */ public function testParseNoResultFoundExceptionDefaultValue() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->ua->family = 'Other'; $parser = $this->getParser($result); @@ -246,7 +208,7 @@ public function testParseNoResultFoundExceptionDefaultValue() */ public function testParseNoResultFoundExceptionDefaultValueDeviceModel() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->device->model = 'Smartphone'; $parser = $this->getParser($result); @@ -261,9 +223,9 @@ public function testParseNoResultFoundExceptionDefaultValueDeviceModel() */ public function testProviderNameAndVersionIsInResult() { - $result = $this->getResultMock(); - $result->device->family = 'Spider'; - $result->ua->family = 'Googlebot'; + $result = $this->getResultMock(); + $result->device->family = 'Spider'; + $result->ua->family = 'Googlebot'; $parser = $this->getParser($result); @@ -276,13 +238,13 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->device->family = 'Spider'; - $result->ua->family = 'Googlebot'; + $result->ua->family = 'Googlebot'; $parser = $this->getParser($result); @@ -293,8 +255,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -302,13 +264,13 @@ public function testParseBot() } /** - * Bot - default value + * Bot - default value. */ public function testParseBotDefaultValue() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->device->family = 'Spider'; - $result->ua->family = 'Other'; + $result->ua->family = 'Other'; $parser = $this->getParser($result); @@ -319,8 +281,8 @@ public function testParseBotDefaultValue() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -328,15 +290,15 @@ public function testParseBotDefaultValue() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->ua->family = 'Firefox'; - $result->ua->major = 3; - $result->ua->minor = 2; - $result->ua->patch = 1; + $result->ua->major = 3; + $result->ua->minor = 2; + $result->ua->patch = 1; $parser = $this->getParser($result); @@ -346,7 +308,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -363,15 +325,15 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->os->family = 'Windows'; - $result->os->major = 7; - $result->os->minor = 0; - $result->os->patch = 1; + $result->os->major = 7; + $result->os->minor = 0; + $result->os->patch = 1; $parser = $this->getParser($result); @@ -381,7 +343,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -398,11 +360,11 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->device->model = 'iPhone'; $result->device->brand = 'Apple'; @@ -416,10 +378,10 @@ public function testParseDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -427,13 +389,13 @@ public function testParseDevice() } /** - * Device - default value + * Device - default value. */ public function testParseDeviceDefaultValue() { - $result = $this->getResultMock(); + $result = $this->getResultMock(); $result->os->family = 'Windows'; - $result->os->major = 7; + $result->os->major = 7; $result->device->model = 'Feature Phone'; $result->device->brand = 'Generic'; @@ -446,7 +408,7 @@ public function testParseDeviceDefaultValue() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => null, @@ -461,13 +423,45 @@ public function testParseDeviceDefaultValue() 'device' => [ 'model' => null, 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return \UAParser\Result\Client + */ + private function getResultMock() + { + $ua = new Result\UserAgent(); + $os = new Result\OperatingSystem(); + $device = new Result\Device(); + + $client = new Result\Client(''); + $client->ua = $ua; + $client->os = $os; + $client->device = $device; + + return $client; + } + + /** + * @param null|mixed $returnValue + * + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser($returnValue = null) + { + $parser = self::createMock('UAParser\Parser'); + $parser->expects($this->any()) + ->method('parse') + ->willReturn($returnValue); + + return $parser; + } } diff --git a/tests/unit/Provider/WhichBrowserTest.php b/tests/unit/Provider/WhichBrowserTest.php index 5a4b1d6..8b14e95 100644 --- a/tests/unit/Provider/WhichBrowserTest.php +++ b/tests/unit/Provider/WhichBrowserTest.php @@ -1,34 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\WhichBrowser + * @covers \UserAgentParser\Provider\WhichBrowser + * + * @internal */ class WhichBrowserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser() - { - $parser = self::createMock('WhichBrowser\Parser'); - - $parser->browser = new \WhichBrowser\Model\Browser(); - $parser->engine = new \WhichBrowser\Model\Engine(); - $parser->os = new \WhichBrowser\Model\Os(); - $parser->device = new \WhichBrowser\Model\Device(); - - return $parser; - } - public function testGetName() { $provider = new WhichBrowser(); @@ -69,34 +56,33 @@ public function testDetectionCapabilities() $provider = new WhichBrowser(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => true, + 'model' => true, + 'brand' => true, + 'type' => true, 'isMobile' => true, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -105,9 +91,7 @@ public function testIsRealResult() { $provider = new WhichBrowser(); - /* - * general - */ + // general $this->assertIsRealResult($provider, true, 'something'); } @@ -127,8 +111,8 @@ public function testParseNoResultFoundException() $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -143,19 +127,19 @@ public function testProviderNameAndVersionIsInResult() $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getType') - ->will($this->returnValue('bot')); + ->willReturn('bot'); $parser->browser = new \WhichBrowser\Model\Browser([ 'name' => 'Googlebot', ]); $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -166,26 +150,26 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getType') - ->will($this->returnValue('bot')); + ->willReturn('bot'); $parser->browser = new \WhichBrowser\Model\Browser([ 'name' => 'Googlebot', ]); $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -194,8 +178,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -203,17 +187,17 @@ public function testParseBot() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->browser = new \WhichBrowser\Model\Browser([ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => new \WhichBrowser\Model\Version([ 'value' => '3.2.1', ]), @@ -221,8 +205,8 @@ public function testParseBrowser() $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -230,7 +214,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -247,17 +231,17 @@ public function testParseBrowser() } /** - * Browser only "using" + * Browser only "using". */ public function testParseBrowserUsing() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $using = new \WhichBrowser\Model\Using([ - 'name' => 'Another', + 'name' => 'Another', 'version' => new \WhichBrowser\Model\Version([ 'value' => '4.7.3', ]), @@ -269,8 +253,8 @@ public function testParseBrowserUsing() $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -278,7 +262,7 @@ public function testParseBrowserUsing() $expectedResult = [ 'browser' => [ - 'name' => 'Another', + 'name' => 'Another', 'version' => [ 'major' => 4, 'minor' => 7, @@ -295,17 +279,17 @@ public function testParseBrowserUsing() } /** - * Rendering engine only + * Rendering engine only. */ public function testParseRenderingEngine() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->engine = new \WhichBrowser\Model\Engine([ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => new \WhichBrowser\Model\Version([ 'value' => '3.2.1', ]), @@ -313,8 +297,8 @@ public function testParseRenderingEngine() $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -322,7 +306,7 @@ public function testParseRenderingEngine() $expectedResult = [ 'renderingEngine' => [ - 'name' => 'Webkit', + 'name' => 'Webkit', 'version' => [ 'major' => 3, 'minor' => 2, @@ -339,17 +323,17 @@ public function testParseRenderingEngine() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->os = new \WhichBrowser\Model\Os([ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => new \WhichBrowser\Model\Version([ 'value' => '7.0.1', ]), @@ -357,8 +341,8 @@ public function testParseOperatingSystem() $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -366,7 +350,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -383,36 +367,36 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { $parser = $this->getParser(); $parser->expects($this->any()) ->method('isDetected') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->expects($this->any()) ->method('getType') - ->will($this->returnValue('watch')); + ->willReturn('watch'); $parser->expects($this->any()) ->method('isMobile') - ->will($this->returnValue(true)); + ->willReturn(true); $parser->device = new \WhichBrowser\Model\Device([ - 'identified' => true, - 'model' => 'iPhone', + 'identified' => true, + 'model' => 'iPhone', 'manufacturer' => 'Apple', - 'type' => 'watch', + 'type' => 'watch', ]); $parser->expects($this->any()) ->method('isType') - ->will($this->returnValue(true)); + ->willReturn(true); $provider = new WhichBrowser(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -422,13 +406,28 @@ public function testParseDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => 'watch', + 'type' => 'watch', 'isMobile' => true, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser() + { + $parser = self::createMock('WhichBrowser\Parser'); + + $parser->browser = new \WhichBrowser\Model\Browser(); + $parser->engine = new \WhichBrowser\Model\Engine(); + $parser->os = new \WhichBrowser\Model\Os(); + $parser->device = new \WhichBrowser\Model\Device(); + + return $parser; + } } diff --git a/tests/unit/Provider/WootheeTest.php b/tests/unit/Provider/WootheeTest.php index 6d2837f..d37bc0d 100644 --- a/tests/unit/Provider/WootheeTest.php +++ b/tests/unit/Provider/WootheeTest.php @@ -1,32 +1,21 @@ * @license MIT * - * @covers UserAgentParser\Provider\Woothee + * @covers \UserAgentParser\Provider\Woothee + * + * @internal */ class WootheeTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser(array $returnValue = []) - { - $parser = self::createMock('Woothee\Classifier'); - $parser->expects($this->any()) - ->method('parse') - ->will($this->returnValue($returnValue)); - - return $parser; - } - public function testGetName() { $provider = new Woothee(); @@ -67,34 +56,33 @@ public function testDetectionCapabilities() $provider = new Woothee(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'device' => [ - 'model' => false, - 'brand' => false, - 'type' => true, + 'model' => false, + 'brand' => false, + 'type' => true, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => true, - 'name' => true, - 'type' => false, + 'name' => true, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -103,23 +91,17 @@ public function testIsRealResult() { $provider = new Woothee(); - /* - * general - */ + // general $this->assertIsRealResult($provider, false, 'UNKNOWN'); $this->assertIsRealResult($provider, true, 'UNKNOWN something'); $this->assertIsRealResult($provider, true, 'something UNKNOWN'); - /* - * device type - */ + // device type $this->assertIsRealResult($provider, false, 'misc', 'device', 'type'); $this->assertIsRealResult($provider, true, 'misc something', 'device', 'type'); $this->assertIsRealResult($provider, true, 'something misc', 'device', 'type'); - /* - * bot name - */ + // bot name $this->assertIsRealResult($provider, false, 'misc crawler', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'misc crawler something', 'bot', 'name'); $this->assertIsRealResult($provider, true, 'something misc crawler', 'bot', 'name'); @@ -141,8 +123,8 @@ public function testParseNoResultFoundException() $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -160,8 +142,8 @@ public function testParseNoResultFoundExceptionDefaultBrowserName() $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -179,8 +161,8 @@ public function testParseNoResultFoundExceptionDefaultDeviceType() $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -194,13 +176,13 @@ public function testProviderNameAndVersionIsInResult() { $parser = $this->getParser([ 'category' => \Woothee\DataSet::DATASET_CATEGORY_CRAWLER, - 'name' => 'Googlebot', + 'name' => 'Googlebot', ]); $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -211,19 +193,19 @@ public function testProviderNameAndVersionIsInResult() } /** - * Bot + * Bot. */ public function testParseBot() { $parser = $this->getParser([ 'category' => \Woothee\DataSet::DATASET_CATEGORY_CRAWLER, - 'name' => 'Googlebot', + 'name' => 'Googlebot', ]); $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -232,8 +214,8 @@ public function testParseBot() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => 'Googlebot', - 'type' => null, + 'name' => 'Googlebot', + 'type' => null, ], ]; @@ -241,19 +223,19 @@ public function testParseBot() } /** - * Bot + * Bot. */ public function testParseBotDefaultValue() { $parser = $this->getParser([ 'category' => \Woothee\DataSet::DATASET_CATEGORY_CRAWLER, - 'name' => 'misc crawler', + 'name' => 'misc crawler', ]); $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -262,8 +244,8 @@ public function testParseBotDefaultValue() $expectedResult = [ 'bot' => [ 'isBot' => true, - 'name' => null, - 'type' => null, + 'name' => null, + 'type' => null, ], ]; @@ -271,19 +253,19 @@ public function testParseBotDefaultValue() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $parser = $this->getParser([ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => '3.0.1', ]); $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -291,7 +273,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 0, @@ -308,7 +290,7 @@ public function testParseBrowser() } /** - * Device only + * Device only. */ public function testParseDevice() { @@ -318,8 +300,8 @@ public function testParseDevice() $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -329,10 +311,10 @@ public function testParseDevice() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'smartphone', + 'type' => 'smartphone', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -340,19 +322,19 @@ public function testParseDevice() } /** - * Device only + * Device only. */ public function testParseDeviceMobilephone() { $parser = $this->getParser([ 'category' => \Woothee\DataSet::DATASET_CATEGORY_MOBILEPHONE, - 'name' => \Woothee\DataSet::VALUE_UNKNOWN, + 'name' => \Woothee\DataSet::VALUE_UNKNOWN, ]); $provider = new Woothee(); - $reflection = new \ReflectionClass($provider); - $property = $reflection->getProperty('parser'); + $reflection = new ReflectionClass($provider); + $property = $reflection->getProperty('parser'); $property->setAccessible(true); $property->setValue($provider, $parser); @@ -360,7 +342,7 @@ public function testParseDeviceMobilephone() $expectedResult = [ 'browser' => [ - 'name' => null, + 'name' => null, 'version' => [ 'major' => null, 'minor' => null, @@ -375,13 +357,26 @@ public function testParseDeviceMobilephone() 'device' => [ 'model' => null, 'brand' => null, - 'type' => 'mobilephone', + 'type' => 'mobilephone', 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser(array $returnValue = []) + { + $parser = self::createMock('Woothee\Classifier'); + $parser->expects($this->any()) + ->method('parse') + ->willReturn($returnValue); + + return $parser; + } } diff --git a/tests/unit/Provider/ZsxsoftTest.php b/tests/unit/Provider/ZsxsoftTest.php index ba57014..4a3a640 100644 --- a/tests/unit/Provider/ZsxsoftTest.php +++ b/tests/unit/Provider/ZsxsoftTest.php @@ -1,47 +1,20 @@ * @license MIT * - * @covers UserAgentParser\Provider\Zsxsoft + * @covers \UserAgentParser\Provider\Zsxsoft + * + * @internal */ class ZsxsoftTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - /** - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getParser($returnValue = null) - { - $parser = $this->getMockBuilder('UserAgent'); - $parser->disableOriginalConstructor() - ->disableOriginalClone() - ->disableArgumentCloning() - ->disallowMockingUnknownTypes() - ->setMethods([ - 'analyze', - ]); - $parser = $parser->getMock(); - - if ($returnValue === null) { - $parser->data = [ - 'browser' => [], - 'os' => [], - 'device' => [], - 'platform' => [], - ]; - } else { - $parser->data = $returnValue; - } - - return $parser; - } - public function testGetName() { $provider = new Zsxsoft(); @@ -82,34 +55,33 @@ public function testDetectionCapabilities() $provider = new Zsxsoft(); $this->assertEquals([ - 'browser' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'renderingEngine' => [ - 'name' => false, + 'name' => false, 'version' => false, ], 'operatingSystem' => [ - 'name' => true, + 'name' => true, 'version' => true, ], 'device' => [ - 'model' => true, - 'brand' => true, - 'type' => false, + 'model' => true, + 'brand' => true, + 'type' => false, 'isMobile' => false, - 'isTouch' => false, + 'isTouch' => false, ], 'bot' => [ 'isBot' => false, - 'name' => false, - 'type' => false, + 'name' => false, + 'type' => false, ], ], $provider->getDetectionCapabilities()); } @@ -161,11 +133,11 @@ public function testParseNoResultFoundExceptionDefaultBrowserName() { $result = [ 'browser' => [ - 'name' => 'Mozilla Compatible', + 'name' => 'Mozilla Compatible', 'version' => '3.2.1', ], - 'os' => [], - 'device' => [], + 'os' => [], + 'device' => [], 'platform' => [], ]; @@ -181,8 +153,8 @@ public function testParseNoResultFoundExceptionDefaultDeviceModel() { $result = [ 'browser' => [], - 'os' => [], - 'device' => [ + 'os' => [], + 'device' => [ 'model' => 'Android', ], 'platform' => [], @@ -200,11 +172,11 @@ public function testProviderNameAndVersionIsInResult() { $result = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => '3.2.1', ], - 'os' => [], - 'device' => [], + 'os' => [], + 'device' => [], 'platform' => [], ]; @@ -217,17 +189,17 @@ public function testProviderNameAndVersionIsInResult() } /** - * Browser only + * Browser only. */ public function testParseBrowser() { $result = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => '3.2.1', ], - 'os' => [], - 'device' => [], + 'os' => [], + 'device' => [], 'platform' => [], ]; @@ -237,7 +209,7 @@ public function testParseBrowser() $expectedResult = [ 'browser' => [ - 'name' => 'Firefox', + 'name' => 'Firefox', 'version' => [ 'major' => 3, 'minor' => 2, @@ -254,17 +226,17 @@ public function testParseBrowser() } /** - * OS only + * OS only. */ public function testParseOperatingSystem() { $result = [ 'browser' => [], - 'os' => [ - 'name' => 'Windows', + 'os' => [ + 'name' => 'Windows', 'version' => '7.0.1', ], - 'device' => [], + 'device' => [], 'platform' => [], ]; @@ -274,7 +246,7 @@ public function testParseOperatingSystem() $expectedResult = [ 'operatingSystem' => [ - 'name' => 'Windows', + 'name' => 'Windows', 'version' => [ 'major' => 7, 'minor' => 0, @@ -291,14 +263,14 @@ public function testParseOperatingSystem() } /** - * Device only + * Device only. */ public function testParseDevice() { $result = [ 'browser' => [], - 'os' => [], - 'device' => [ + 'os' => [], + 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', ], @@ -313,10 +285,10 @@ public function testParseDevice() 'device' => [ 'model' => 'iPhone', 'brand' => 'Apple', - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; @@ -324,14 +296,14 @@ public function testParseDevice() } /** - * Device model only + * Device model only. */ public function testParseDeviceModelOnly() { $result = [ 'browser' => [], - 'os' => [], - 'device' => [ + 'os' => [], + 'device' => [ 'model' => 'One+', ], 'platform' => [], @@ -345,13 +317,44 @@ public function testParseDeviceModelOnly() 'device' => [ 'model' => 'One+', 'brand' => null, - 'type' => null, + 'type' => null, 'isMobile' => null, - 'isTouch' => null, + 'isTouch' => null, ], ]; $this->assertProviderResult($result, $expectedResult); } + + /** + * @param null|mixed $returnValue + * + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function getParser($returnValue = null) + { + $parser = $this->getMockBuilder('UserAgent'); + $parser->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning() + ->disallowMockingUnknownTypes() + ->setMethods([ + 'analyze', + ]); + $parser = $parser->getMock(); + + if ($returnValue === null) { + $parser->data = [ + 'browser' => [], + 'os' => [], + 'device' => [], + 'platform' => [], + ]; + } else { + $parser->data = $returnValue; + } + + return $parser; + } } From aac0a133e86113e64dddce3b1d47d6309a50baae Mon Sep 17 00:00:00 2001 From: Christopher Fuchs Date: Thu, 7 Jan 2021 11:19:00 +0100 Subject: [PATCH 06/10] Fixed up tests --- phpunit.xml | 11 +---------- .../integration/Provider/AbstractProviderTestCase.php | 4 ++-- .../Provider/Http/AbstractHttpProviderTestCase.php | 2 +- tests/unit/Model/BotTest.php | 4 ++-- tests/unit/Model/BrowserTest.php | 4 ++-- tests/unit/Model/DeviceTest.php | 4 ++-- tests/unit/Model/OperatingSystemTest.php | 4 ++-- tests/unit/Model/RenderingEngineTest.php | 4 ++-- tests/unit/Model/UserAgentTest.php | 4 ++-- tests/unit/Model/VersionTest.php | 4 ++-- tests/unit/Provider/AbstractBrowscapTest.php | 2 +- tests/unit/Provider/AbstractProviderTestCase.php | 4 ++-- tests/unit/Provider/ChainTest.php | 6 +++--- tests/unit/Provider/DonatjUAParserTest.php | 2 +- tests/unit/Provider/EndorphinTest.php | 2 +- tests/unit/Provider/HandsetDetectionTest.php | 2 +- tests/unit/Provider/JenssegersAgentTest.php | 2 +- tests/unit/Provider/PiwikDeviceDetectorTest.php | 2 +- tests/unit/Provider/SinergiBrowserDetectorTest.php | 2 +- tests/unit/Provider/UAParserTest.php | 2 +- tests/unit/Provider/WhichBrowserTest.php | 2 +- tests/unit/Provider/WootheeTest.php | 2 +- tests/unit/Provider/ZsxsoftTest.php | 2 +- 23 files changed, 34 insertions(+), 43 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 49a7f21..0476e7e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,8 +8,7 @@ stopOnFailure="false" processIsolation="false" backupGlobals="false" - syntaxCheck="true" -> +> tests/unit @@ -20,14 +19,6 @@ - - - src - - - - - diff --git a/tests/integration/Provider/AbstractProviderTestCase.php b/tests/integration/Provider/AbstractProviderTestCase.php index 3cf9899..e3f5bc6 100644 --- a/tests/integration/Provider/AbstractProviderTestCase.php +++ b/tests/integration/Provider/AbstractProviderTestCase.php @@ -2,12 +2,12 @@ namespace UserAgentParserTest\Integration\Provider; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * @author Martin Keckeis * @license MIT */ -abstract class AbstractProviderTestCase extends PHPUnit_Framework_TestCase +abstract class AbstractProviderTestCase extends TestCase { } diff --git a/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php b/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php index 8a7d1f6..113ef2c 100644 --- a/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php +++ b/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php @@ -11,7 +11,7 @@ abstract class AbstractHttpProviderTestCase extends AbstractProviderTestCase { private $client; - protected function setUp() + protected function setUp(): void { // move tests/credentials.php.dist to tests/credentials.php if (!\defined('CREDENTIALS_FILE_LOADED') && file_exists('tests/credentials.php')) { diff --git a/tests/unit/Model/BotTest.php b/tests/unit/Model/BotTest.php index 96850f2..4b3ea90 100644 --- a/tests/unit/Model/BotTest.php +++ b/tests/unit/Model/BotTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\Bot; /** @@ -13,7 +13,7 @@ * * @internal */ -class BotTest extends PHPUnit_Framework_TestCase +class BotTest extends TestCase { public function testIsBot() { diff --git a/tests/unit/Model/BrowserTest.php b/tests/unit/Model/BrowserTest.php index 7a89f7b..22854fc 100644 --- a/tests/unit/Model/BrowserTest.php +++ b/tests/unit/Model/BrowserTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\Browser; use UserAgentParser\Model\Version; @@ -14,7 +14,7 @@ * * @internal */ -class BrowserTest extends PHPUnit_Framework_TestCase +class BrowserTest extends TestCase { public function testName() { diff --git a/tests/unit/Model/DeviceTest.php b/tests/unit/Model/DeviceTest.php index 30a5f65..7c1201b 100644 --- a/tests/unit/Model/DeviceTest.php +++ b/tests/unit/Model/DeviceTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\Device; /** @@ -13,7 +13,7 @@ * * @internal */ -class DeviceTest extends PHPUnit_Framework_TestCase +class DeviceTest extends TestCase { public function testModel() { diff --git a/tests/unit/Model/OperatingSystemTest.php b/tests/unit/Model/OperatingSystemTest.php index 5190a00..9743768 100644 --- a/tests/unit/Model/OperatingSystemTest.php +++ b/tests/unit/Model/OperatingSystemTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\OperatingSystem; use UserAgentParser\Model\Version; @@ -14,7 +14,7 @@ * * @internal */ -class OperatingSystemTest extends PHPUnit_Framework_TestCase +class OperatingSystemTest extends TestCase { public function testName() { diff --git a/tests/unit/Model/RenderingEngineTest.php b/tests/unit/Model/RenderingEngineTest.php index 1bac038..5d4d45a 100644 --- a/tests/unit/Model/RenderingEngineTest.php +++ b/tests/unit/Model/RenderingEngineTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\RenderingEngine; use UserAgentParser\Model\Version; @@ -14,7 +14,7 @@ * * @internal */ -class RenderingEngineTest extends PHPUnit_Framework_TestCase +class RenderingEngineTest extends TestCase { public function testName() { diff --git a/tests/unit/Model/UserAgentTest.php b/tests/unit/Model/UserAgentTest.php index e2b1f20..4a01956 100644 --- a/tests/unit/Model/UserAgentTest.php +++ b/tests/unit/Model/UserAgentTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\UserAgent; /** @@ -13,7 +13,7 @@ * * @internal */ -class UserAgentTest extends PHPUnit_Framework_TestCase +class UserAgentTest extends TestCase { public function testBrowser() { diff --git a/tests/unit/Model/VersionTest.php b/tests/unit/Model/VersionTest.php index f93a4b5..8ebcd63 100644 --- a/tests/unit/Model/VersionTest.php +++ b/tests/unit/Model/VersionTest.php @@ -2,7 +2,7 @@ namespace UserAgentParserTest; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use UserAgentParser\Model\Version; /** @@ -13,7 +13,7 @@ * * @internal */ -class VersionTest extends PHPUnit_Framework_TestCase +class VersionTest extends TestCase { public function testMajorMinorPatch() { diff --git a/tests/unit/Provider/AbstractBrowscapTest.php b/tests/unit/Provider/AbstractBrowscapTest.php index 46e6928..430479d 100644 --- a/tests/unit/Provider/AbstractBrowscapTest.php +++ b/tests/unit/Provider/AbstractBrowscapTest.php @@ -273,7 +273,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('Browscap', $result->getProviderName()); - $this->assertRegExp('/\d{1,}$/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}$/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/AbstractProviderTestCase.php b/tests/unit/Provider/AbstractProviderTestCase.php index a094783..c8f866c 100644 --- a/tests/unit/Provider/AbstractProviderTestCase.php +++ b/tests/unit/Provider/AbstractProviderTestCase.php @@ -5,7 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use ReflectionClass; use UserAgentParser\Model\UserAgent; use UserAgentParser\Provider\AbstractProvider; @@ -14,7 +14,7 @@ * @author Martin Keckeis * @license MIT */ -abstract class AbstractProviderTestCase extends PHPUnit_Framework_TestCase +abstract class AbstractProviderTestCase extends TestCase { protected function assertProviderResult($result, array $expectedResult) { diff --git a/tests/unit/Provider/ChainTest.php b/tests/unit/Provider/ChainTest.php index f7f4b2e..363e331 100644 --- a/tests/unit/Provider/ChainTest.php +++ b/tests/unit/Provider/ChainTest.php @@ -20,14 +20,14 @@ class ChainTest extends AbstractProviderTestCase implements RequiredProviderTest */ private $provider; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); @@ -206,6 +206,6 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('SomeProvider', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } } diff --git a/tests/unit/Provider/DonatjUAParserTest.php b/tests/unit/Provider/DonatjUAParserTest.php index 4ee31ef..7151a3d 100644 --- a/tests/unit/Provider/DonatjUAParserTest.php +++ b/tests/unit/Provider/DonatjUAParserTest.php @@ -158,7 +158,7 @@ public function testProviderNameAndVersionIsInResult() self::$version = null; $this->assertEquals('DonatjUAParser', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/EndorphinTest.php b/tests/unit/Provider/EndorphinTest.php index 0122d61..3a90019 100644 --- a/tests/unit/Provider/EndorphinTest.php +++ b/tests/unit/Provider/EndorphinTest.php @@ -142,7 +142,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('Endorphin', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/HandsetDetectionTest.php b/tests/unit/Provider/HandsetDetectionTest.php index b31c8b5..542a5b0 100644 --- a/tests/unit/Provider/HandsetDetectionTest.php +++ b/tests/unit/Provider/HandsetDetectionTest.php @@ -179,7 +179,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('HandsetDetection', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/JenssegersAgentTest.php b/tests/unit/Provider/JenssegersAgentTest.php index 202f196..8fc777b 100644 --- a/tests/unit/Provider/JenssegersAgentTest.php +++ b/tests/unit/Provider/JenssegersAgentTest.php @@ -145,7 +145,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('JenssegersAgent', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/PiwikDeviceDetectorTest.php b/tests/unit/Provider/PiwikDeviceDetectorTest.php index fc3a3ac..438f86c 100644 --- a/tests/unit/Provider/PiwikDeviceDetectorTest.php +++ b/tests/unit/Provider/PiwikDeviceDetectorTest.php @@ -168,7 +168,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('PiwikDeviceDetector', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/SinergiBrowserDetectorTest.php b/tests/unit/Provider/SinergiBrowserDetectorTest.php index dd553a5..673ada0 100644 --- a/tests/unit/Provider/SinergiBrowserDetectorTest.php +++ b/tests/unit/Provider/SinergiBrowserDetectorTest.php @@ -225,7 +225,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('SinergiBrowserDetector', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/UAParserTest.php b/tests/unit/Provider/UAParserTest.php index 67a8fe7..086bafa 100644 --- a/tests/unit/Provider/UAParserTest.php +++ b/tests/unit/Provider/UAParserTest.php @@ -234,7 +234,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('UAParser', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/WhichBrowserTest.php b/tests/unit/Provider/WhichBrowserTest.php index 8b14e95..f430715 100644 --- a/tests/unit/Provider/WhichBrowserTest.php +++ b/tests/unit/Provider/WhichBrowserTest.php @@ -146,7 +146,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('WhichBrowser', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/WootheeTest.php b/tests/unit/Provider/WootheeTest.php index d37bc0d..c0420c9 100644 --- a/tests/unit/Provider/WootheeTest.php +++ b/tests/unit/Provider/WootheeTest.php @@ -189,7 +189,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('Woothee', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** diff --git a/tests/unit/Provider/ZsxsoftTest.php b/tests/unit/Provider/ZsxsoftTest.php index 4a3a640..d5f71b4 100644 --- a/tests/unit/Provider/ZsxsoftTest.php +++ b/tests/unit/Provider/ZsxsoftTest.php @@ -185,7 +185,7 @@ public function testProviderNameAndVersionIsInResult() $result = $provider->parse('A real user agent...'); $this->assertEquals('Zsxsoft', $result->getProviderName()); - $this->assertRegExp('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); + $this->assertMatchesRegularExpression('/\d{1,}\.\d{1,}/', $result->getProviderVersion()); } /** From e4f8945bea24e2fe7623ba1abf74b366bb3a1e96 Mon Sep 17 00:00:00 2001 From: "Pavel S. Pobegov" Date: Mon, 28 Nov 2022 17:28:31 +0100 Subject: [PATCH 07/10] Added compatibility for PHP 8.1 Will no longer throw deprecation errors --- src/Model/Version.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model/Version.php b/src/Model/Version.php index 5b4c927..79617c4 100644 --- a/src/Model/Version.php +++ b/src/Model/Version.php @@ -140,7 +140,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._]/', '', (string)$complete); if ($left === '') { $complete = null; } @@ -226,7 +226,7 @@ private function getCompleteParts($complete) ]; // only digits - preg_match('/\\d+(?:[._]*\\d*)*/', $complete, $result); + preg_match('/\\d+(?:[._]*\\d*)*/', (string)$complete, $result); if (\count($result) > 0) { $parts = preg_split('/[._]/', $result[0]); @@ -242,7 +242,7 @@ private function getCompleteParts($complete) } // grab alias - $result = preg_split('/\\d+(?:[._]*\\d*)*/', $complete); + $result = preg_split('/\\d+(?:[._]*\\d*)*/', (string)$complete); foreach ($result as $row) { $row = trim($row); From f17f5af53ca83737827297aa7f50880748104630 Mon Sep 17 00:00:00 2001 From: "Pavel S. Pobegov" Date: Mon, 28 Nov 2022 17:31:45 +0100 Subject: [PATCH 08/10] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bddc26e..be0dd73 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "ready2order/user-agent-parser", + "name": "pobegov/user-agent-parser", "description": "UserAgent parsing done right http://useragent.mkf.solutions/", "keywords": [ From b6adac4db2404f1e75b750aaea889746187e6878 Mon Sep 17 00:00:00 2001 From: "Pavel S. Pobegov" Date: Mon, 28 Nov 2022 17:38:58 +0100 Subject: [PATCH 09/10] Revert "Update composer.json" This reverts commit f17f5af53ca83737827297aa7f50880748104630. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index be0dd73..bddc26e 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "pobegov/user-agent-parser", + "name": "ready2order/user-agent-parser", "description": "UserAgent parsing done right http://useragent.mkf.solutions/", "keywords": [ From 20ebbeef2d09482ec15175cc8edef7822685f274 Mon Sep 17 00:00:00 2001 From: Christopher Fuchs Date: Mon, 21 Oct 2024 21:36:43 +0200 Subject: [PATCH 10/10] Fixed php warnings and ran linter --- composer.json | 32 ++++++++----------- src/Model/Version.php | 6 ++-- src/Provider/Http/AbstractHttpProvider.php | 2 +- src/Provider/Http/DeviceAtlasCom.php | 2 +- src/Provider/Http/FiftyOneDegreesCom.php | 2 +- src/Provider/Http/NeutrinoApiCom.php | 2 +- src/Provider/Http/UdgerCom.php | 2 +- src/Provider/Http/UserAgentApiCom.php | 2 +- .../Http/AbstractHttpProviderTestCase.php | 4 +-- .../Provider/JenssegersAgentTest.php | 2 +- tests/unit/Provider/DonatjUAParserTest.php | 4 +-- 11 files changed, 27 insertions(+), 33 deletions(-) diff --git a/composer.json b/composer.json index bddc26e..69eb489 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,5 @@ { "name": "ready2order/user-agent-parser", - "description": "UserAgent parsing done right http://useragent.mkf.solutions/", "keywords": [ "UA", @@ -9,13 +8,11 @@ "User agent", "User agent parser", "User agent detection", - "UserAgent", + "UserAgent", "UserAgentParser", - "Sniffing", - "Parser", + "Parser", "Detection", - "Browser", "Engine", "Rendering engine", @@ -26,8 +23,7 @@ "mobile detection", "mobile detector", "mobile device detection", - "bot detection", - + "bot detection", "get_browser", "browscap", "donatj", @@ -38,7 +34,6 @@ "whichbrowser", "woothee", "wurfl", - "DeviceAtlas", "NeutrinoApiCom", "UdgerCom", @@ -46,7 +41,6 @@ "UserAgentStringCom", "WhatIsMyBrowserCom" ], - "license": "MIT", "authors": [ { @@ -54,26 +48,22 @@ "email": "martin.keckeis1@gmail.com" } ], - "autoload": { "psr-4": { - "UserAgentParser\\": "src" + "UserAgentParser\\": "src" } }, - "autoload-dev": { "psr-4": { - "UserAgentParserTest\\Unit\\": "tests/unit", - "UserAgentParserTest\\Integration\\": "tests/integration" + "UserAgentParserTest\\Unit\\": "tests/unit", + "UserAgentParserTest\\Integration\\": "tests/integration" } }, - "require": { "php": "^7.4|^8.0", - "guzzlehttp/guzzle": "^6.1", + "guzzlehttp/guzzle": "^7.9", "composer-runtime-api": "^2.0" }, - "conflict": { "browscap/browscap-php": "^5.0", "donatj/phpuseragentparser": "<0.5,>=1", @@ -87,7 +77,6 @@ "mimmi20/wurfl": "<1.6.4,>=2", "zsxsoft/php-useragent": "<1.2,>=2" }, - "suggest": { "browscap/browscap-php": "Needed to use Provider\\BrowscapPhp", "donatj/phpuseragentparser": "Needed to use Provider\\DonatjUAParser", @@ -102,7 +91,6 @@ "mimmi20/wurfl": "Needed to use Provider\\Wurfl", "zsxsoft/php-useragent": "Needed to use Provider\\Zsxsoft" }, - "require-dev": { "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^2.17.3", @@ -119,5 +107,11 @@ "woothee/woothee": "^1.2", "mimmi20/wurfl": "^1.7.1.1", "zsxsoft/php-useragent": ">=1.2,<1.4" + }, + "config": { + "preferred-install": "dist", + "platform": { + "php": "7.4.0" + } } } diff --git a/src/Model/Version.php b/src/Model/Version.php index 79617c4..ae3a180 100644 --- a/src/Model/Version.php +++ b/src/Model/Version.php @@ -140,7 +140,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._]/', '', (string)$complete); + $left = preg_replace('/[0._]/', '', (string) $complete); if ($left === '') { $complete = null; } @@ -226,7 +226,7 @@ private function getCompleteParts($complete) ]; // only digits - preg_match('/\\d+(?:[._]*\\d*)*/', (string)$complete, $result); + preg_match('/\\d+(?:[._]*\\d*)*/', (string) $complete, $result); if (\count($result) > 0) { $parts = preg_split('/[._]/', $result[0]); @@ -242,7 +242,7 @@ private function getCompleteParts($complete) } // grab alias - $result = preg_split('/\\d+(?:[._]*\\d*)*/', (string)$complete); + $result = preg_split('/\\d+(?:[._]*\\d*)*/', (string) $complete); foreach ($result as $row) { $row = trim($row); diff --git a/src/Provider/Http/AbstractHttpProvider.php b/src/Provider/Http/AbstractHttpProvider.php index e09093f..77e2505 100644 --- a/src/Provider/Http/AbstractHttpProvider.php +++ b/src/Provider/Http/AbstractHttpProvider.php @@ -46,7 +46,7 @@ protected function getResponse(RequestInterface $request) // @var $response \GuzzleHttp\Psr7\Response $response = $this->getClient()->send($request); } catch (GuzzleHttpException $ex) { - throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '"', null, $ex); + throw new Exception\RequestException('Could not get valid response from "' . $request->getUri() . '"', 0, $ex); } if ($response->getStatusCode() !== 200) { diff --git a/src/Provider/Http/DeviceAtlasCom.php b/src/Provider/Http/DeviceAtlasCom.php index 529312f..484075a 100644 --- a/src/Provider/Http/DeviceAtlasCom.php +++ b/src/Provider/Http/DeviceAtlasCom.php @@ -122,7 +122,7 @@ protected function getResult($userAgent, array $headers) $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { - throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), null, $ex); + throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), 0, $ex); } throw $ex; diff --git a/src/Provider/Http/FiftyOneDegreesCom.php b/src/Provider/Http/FiftyOneDegreesCom.php index 4d5a0f9..1169889 100644 --- a/src/Provider/Http/FiftyOneDegreesCom.php +++ b/src/Provider/Http/FiftyOneDegreesCom.php @@ -141,7 +141,7 @@ protected function getResult($userAgent, array $headers) $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { - throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), null, $ex); + throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), 0, $ex); } throw $ex; diff --git a/src/Provider/Http/NeutrinoApiCom.php b/src/Provider/Http/NeutrinoApiCom.php index 9105dfa..cfc0bd4 100644 --- a/src/Provider/Http/NeutrinoApiCom.php +++ b/src/Provider/Http/NeutrinoApiCom.php @@ -168,7 +168,7 @@ protected function getResult($userAgent, array $headers) $prevEx = $ex->getPrevious(); if ($prevEx->hasResponse() === true && $prevEx->getResponse()->getStatusCode() === 403) { - throw new Exception\InvalidCredentialsException('Your API userId "' . $this->apiUserId . '" and key "' . $this->apiKey . '" is not valid for ' . $this->getName(), null, $ex); + throw new Exception\InvalidCredentialsException('Your API userId "' . $this->apiUserId . '" and key "' . $this->apiKey . '" is not valid for ' . $this->getName(), 0, $ex); } throw $ex; diff --git a/src/Provider/Http/UdgerCom.php b/src/Provider/Http/UdgerCom.php index 659c2db..fd5b163 100644 --- a/src/Provider/Http/UdgerCom.php +++ b/src/Provider/Http/UdgerCom.php @@ -127,7 +127,7 @@ protected function getResult($userAgent, array $headers) 'uastrig' => $userAgent, ]; - $body = http_build_query($params, null, '&'); + $body = http_build_query($params, '', '&'); $request = new Request('POST', self::$uri, [ 'Content-Type' => 'application/x-www-form-urlencoded', diff --git a/src/Provider/Http/UserAgentApiCom.php b/src/Provider/Http/UserAgentApiCom.php index 72f7c70..3676e2e 100644 --- a/src/Provider/Http/UserAgentApiCom.php +++ b/src/Provider/Http/UserAgentApiCom.php @@ -136,7 +136,7 @@ protected function getResult($userAgent, array $headers) // Error if (isset($content->error->code) && $content->error->code == 'key_invalid') { - throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), null, $ex); + throw new Exception\InvalidCredentialsException('Your API key "' . $this->apiKey . '" is not valid for ' . $this->getName(), 0, $ex); } if (isset($content->error->code) && $content->error->code == 'useragent_invalid') { diff --git a/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php b/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php index 113ef2c..f926ebf 100644 --- a/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php +++ b/tests/integration/Provider/Http/AbstractHttpProviderTestCase.php @@ -42,8 +42,8 @@ protected function getClient() 'timeout' => 5, 'curl' => [ - CURLOPT_SSL_VERIFYHOST => false, - CURLOPT_SSL_VERIFYPEER => false, + \CURLOPT_SSL_VERIFYHOST => false, + \CURLOPT_SSL_VERIFYPEER => false, ], ]); } diff --git a/tests/integration/Provider/JenssegersAgentTest.php b/tests/integration/Provider/JenssegersAgentTest.php index f01fa2d..3871d01 100644 --- a/tests/integration/Provider/JenssegersAgentTest.php +++ b/tests/integration/Provider/JenssegersAgentTest.php @@ -76,7 +76,7 @@ public function testRealResultBot() ], 'bot' => [ 'isBot' => true, - 'name' => 'Google', + 'name' => 'Googlebot', 'type' => null, ], ], $result->toArray()); diff --git a/tests/unit/Provider/DonatjUAParserTest.php b/tests/unit/Provider/DonatjUAParserTest.php index 7151a3d..d2a4222 100644 --- a/tests/unit/Provider/DonatjUAParserTest.php +++ b/tests/unit/Provider/DonatjUAParserTest.php @@ -35,9 +35,9 @@ function parse_user_agent($userAgent) */ class DonatjUAParserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public static $browser = null; + public static $browser; - public static $version = null; + public static $version; public function testGetName() {