Skip to content

Commit

Permalink
Merge pull request #48 from ThaDafinser/hotfix/php7
Browse files Browse the repository at this point in the history
green build for php7 + hhvm
  • Loading branch information
ThaDafinser committed Jan 12, 2016
2 parents 502a918 + 04f36e8 commit df89564
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 145 deletions.
3 changes: 2 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
$finder = Symfony\CS\Finder\DefaultFinder::create();
$finder->in([
__DIR__ . '/src',
__DIR__ . '/tests'
__DIR__ . '/tests/integration',
__DIR__ . '/tests/unit'
]);

$config = Symfony\CS\Config\Config::create();
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ env:

matrix:
allow_failures:
- php: 7
- php: hhvm

before_script:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/ThaDafinser/UserAgentParser.svg)](https://travis-ci.org/ThaDafinser/UserAgentParser)
[![Code Coverage](https://scrutinizer-ci.com/g/ThaDafinser/UserAgentParser/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ThaDafinser/UserAgentParser/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ThaDafinser/UserAgentParser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ThaDafinser/UserAgentParser/?branch=master)
[![PHP 7 ready](http://php7ready.timesplinter.ch/ThaDafinser/UserAgentParser/badge.svg)](https://travis-ci.org/ThaDafinser/UserAgentParser)

[![Latest Stable Version](https://poser.pugx.org/thadafinser/user-agent-parser/v/stable)](https://packagist.org/packages/thadafinser/user-agent-parser)
[![Latest Unstable Version](https://poser.pugx.org/thadafinser/user-agent-parser/v/unstable)](https://packagist.org/packages/thadafinser/user-agent-parser)
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/PiwikDeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class PiwikDeviceDetector extends AbstractProvider
*/
public function __construct(DeviceDetector $parser = null)
{
if (! class_exists('DeviceDetector\Cache\StaticCache', true)) {
throw new PackageNotLoadedException('You need to install ' . $this->getHomepage() . ' to use this provider');
if ($parser === null && ! file_exists('vendor/' . $this->getPackageName() . '/composer.json')) {
throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}

$this->parser = $parser;
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/SinergiBrowserDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class SinergiBrowserDetector extends AbstractProvider
*/
public function __construct()
{
if (! class_exists('Sinergi\BrowserDetector\UserAgent', true)) {
throw new PackageNotLoadedException('You need to install ' . $this->getHomepage() . ' to use this provider');
if (! file_exists('vendor/' . $this->getPackageName() . '/composer.json')) {
throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Provider/UAParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class UAParser extends AbstractProvider
*/
public function __construct(Parser $parser = null)
{
if (! class_exists('UAParser\Parser', true)) {
throw new PackageNotLoadedException('You need to install ' . $this->getHomepage() . ' to use this provider');
if ($parser === null && ! file_exists('vendor/' . $this->getPackageName() . '/composer.json')) {
throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}

$this->parser = $parser;
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/WhichBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class WhichBrowser extends AbstractProvider
*/
public function __construct()
{
if (! class_exists('WhichBrowser\Parser', true)) {
throw new PackageNotLoadedException('You need to install ' . $this->getHomepage() . ' to use this provider');
if (! file_exists('vendor/' . $this->getPackageName() . '/composer.json')) {
throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Provider/Woothee.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class Woothee extends AbstractProvider
*/
public function __construct()
{
if (! class_exists('Woothee\Classifier', true)) {
throw new PackageNotLoadedException('You need to install ' . $this->getHomepage() . ' to use this provider');
if (! file_exists('vendor/' . $this->getPackageName() . '/composer.json')) {
throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}
}

Expand Down
33 changes: 0 additions & 33 deletions tests/unit/Provider/AbstractProviderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

abstract class AbstractProviderTestCase extends PHPUnit_Framework_TestCase
{
protected $autoloadFunctions = [];

protected $autoloadIsDisabled = false;

public function assertProviderResult($result, array $expectedResult)
{
$this->assertInstanceOf('UserAgentParser\Model\UserAgent', $result);
Expand All @@ -23,35 +19,6 @@ public function assertProviderResult($result, array $expectedResult)
$this->assertEquals($result->toArray(), $expectedResult);
}

protected function backupAutoload()
{
$this->autoloadFunctions = spl_autoload_functions();
}

protected function disableDefaultAutoload()
{
if ($this->autoloadIsDisabled === true) {
return;
}

foreach ($this->autoloadFunctions as $function) {
spl_autoload_unregister($function);
}

$this->autoloadIsDisabled = true;
}

protected function enableDefaultAutoload()
{
if ($this->autoloadIsDisabled !== true) {
return;
}

foreach ($this->autoloadFunctions as $function) {
spl_autoload_register($function);
}
}

/**
*
* @return Client
Expand Down
97 changes: 45 additions & 52 deletions tests/unit/Provider/PiwikDeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,20 @@ private function getParser()

public function testPackageNotLoadedException()
{
$this->backupAutoload();
$file = 'vendor/piwik/device-detector/composer.json';
$tempFile = 'vendor/piwik/device-detector/composer.json.tmp';

$autoloadFunction = function ($class) {
if ($class == 'DeviceDetector\Cache\StaticCache') {
$this->disableDefaultAutoload();
} else {
$this->enableDefaultAutoload();
}
};

spl_autoload_register($autoloadFunction, true, true);
rename($file, $tempFile);

try {
$provider = new PiwikDeviceDetector();
} catch (\Exception $ex) {
// we need to catch the exception, since we need to rename the file again!
}

$this->assertInstanceOf('UserAgentParser\Exception\PackageNotLoadedException', $ex);

spl_autoload_unregister($autoloadFunction);
$this->enableDefaultAutoload();
rename($tempFile, $file);
}

public function testName()
Expand Down Expand Up @@ -86,35 +79,35 @@ public function testDetectionCapabilities()

$this->assertEquals([

'browser' => [
'name' => true,
'version' => true,
],

'renderingEngine' => [
'name' => true,
'version' => false,
],

'operatingSystem' => [
'name' => true,
'version' => true,
],

'device' => [
'model' => true,
'brand' => true,
'type' => true,
'isMobile' => true,
'isTouch' => true,
],

'bot' => [
'isBot' => true,
'name' => true,
'type' => true,
],
], $provider->getDetectionCapabilities());
'browser' => [
'name' => true,
'version' => true,
],

'renderingEngine' => [
'name' => true,
'version' => false,
],

'operatingSystem' => [
'name' => true,
'version' => true,
],

'device' => [
'model' => true,
'brand' => true,
'type' => true,
'isMobile' => true,
'isTouch' => true,
],

'bot' => [
'isBot' => true,
'name' => true,
'type' => true,
],
], $provider->getDetectionCapabilities());
}

public function testParser()
Expand Down Expand Up @@ -197,9 +190,9 @@ public function testParseBrowser()
'browser' => [
'name' => 'Firefox',
'version' => [
'major' => 3,
'minor' => 0,
'patch' => null,
'major' => 3,
'minor' => 0,
'patch' => null,

'alias' => null,

Expand All @@ -210,9 +203,9 @@ public function testParseBrowser()
'renderingEngine' => [
'name' => 'WebKit',
'version' => [
'major' => null,
'minor' => null,
'patch' => null,
'major' => null,
'minor' => null,
'patch' => null,

'alias' => null,

Expand Down Expand Up @@ -250,9 +243,9 @@ public function testParseOperatingSystem()
'operatingSystem' => [
'name' => 'Windows',
'version' => [
'major' => 7,
'minor' => 0,
'patch' => null,
'major' => 7,
'minor' => 0,
'patch' => null,

'alias' => null,

Expand All @@ -274,8 +267,8 @@ public function testParseDevice()
->method('getClient')
->will($this->returnValue([]));
$parser->expects($this->any())
->method('getOs')
->will($this->returnValue([]));
->method('getOs')
->will($this->returnValue([]));

$parser->expects($this->any())
->method('getDevice')
Expand Down
17 changes: 5 additions & 12 deletions tests/unit/Provider/SinergiBrowserDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,20 @@ private function getDeviceParser()

public function testPackageNotLoadedException()
{
$this->backupAutoload();
$file = 'vendor/sinergi/browser-detector/composer.json';
$tempFile = 'vendor/sinergi/browser-detector/composer.json.tmp';

$autoloadFunction = function ($class) {
if ($class == 'Sinergi\BrowserDetector\UserAgent') {
$this->disableDefaultAutoload();
} else {
$this->enableDefaultAutoload();
}
};

spl_autoload_register($autoloadFunction, true, true);
rename($file, $tempFile);

try {
$provider = new SinergiBrowserDetector();
} catch (\Exception $ex) {
// we need to catch the exception, since we need to rename the file again!
}

$this->assertInstanceOf('UserAgentParser\Exception\PackageNotLoadedException', $ex);

$test = spl_autoload_unregister($autoloadFunction);
$this->enableDefaultAutoload();
rename($tempFile, $file);
}

public function testName()
Expand Down
17 changes: 5 additions & 12 deletions tests/unit/Provider/UAParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,20 @@ private function getParser($returnValue = null)

public function testPackageNotLoadedException()
{
$this->backupAutoload();
$file = 'vendor/ua-parser/uap-php/composer.json';
$tempFile = 'vendor/ua-parser/uap-php/composer.json.tmp';

$autoloadFunction = function ($class) {
if ($class == 'UAParser\Parser') {
$this->disableDefaultAutoload();
} else {
$this->enableDefaultAutoload();
}
};

spl_autoload_register($autoloadFunction, true, true);
rename($file, $tempFile);

try {
$provider = new UAParser();
} catch (\Exception $ex) {
// we need to catch the exception, since we need to rename the file again!
}

$this->assertInstanceOf('UserAgentParser\Exception\PackageNotLoadedException', $ex);

spl_autoload_unregister($autoloadFunction);
$this->enableDefaultAutoload();
rename($tempFile, $file);
}

public function testName()
Expand Down
17 changes: 5 additions & 12 deletions tests/unit/Provider/WhichBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,20 @@ private function getParser()

public function testPackageNotLoadedException()
{
$this->backupAutoload();
$file = 'vendor/whichbrowser/parser/composer.json';
$tempFile = 'vendor/whichbrowser/parser/composer.json.tmp';

$autoloadFunction = function ($class) {
if ($class == 'WhichBrowser\Parser') {
$this->disableDefaultAutoload();
} else {
$this->enableDefaultAutoload();
}
};

spl_autoload_register($autoloadFunction, true, true);
rename($file, $tempFile);

try {
$provider = new WhichBrowser();
} catch (\Exception $ex) {
// we need to catch the exception, since we need to rename the file again!
}

$this->assertInstanceOf('UserAgentParser\Exception\PackageNotLoadedException', $ex);

spl_autoload_unregister($autoloadFunction);
$this->enableDefaultAutoload();
rename($tempFile, $file);
}

public function testName()
Expand Down
Loading

0 comments on commit df89564

Please sign in to comment.