-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from ThaDafinser/feature/integration
http integration test + fix hhvm
- Loading branch information
Showing
17 changed files
with
975 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\CurlHandler; | ||
use GuzzleHttp\HandlerStack; | ||
|
||
$handler = new CurlHandler(); | ||
$stack = HandlerStack::create($handler); | ||
|
||
$client = new Client([ | ||
'handler' => $stack, | ||
|
||
'timeout' => 10, | ||
|
||
'curl' => [ | ||
CURLOPT_PROXY => 'YOUR_PROXY', | ||
CURLOPT_PROXYUSERPWD => '...', | ||
CURLOPT_PROXYAUTH => CURLAUTH_NTLM, | ||
CURLOPT_PROXYTYPE => CURLPROXY_HTTP, | ||
|
||
CURLOPT_SSL_VERIFYHOST => false, | ||
CURLOPT_SSL_VERIFYPEER => false | ||
] | ||
]); | ||
|
||
return $client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
define('CREDENTIALS_FILE_LOADED', true); | ||
|
||
define('CREDENTIALS_DEVICE_ATLAS_COM_KEY', '...'); | ||
|
||
define('CREDENTIALS_NEUTRINO_API_COM_USER_ID', '...'); | ||
define('CREDENTIALS_NEUTRINO_API_COM_KEY', '...'); | ||
|
||
define('CREDENTIALS_UDGER_COM_KEY', '...'); | ||
|
||
define('CREDENTIALS_USER_AGENT_API_COM_KEY', '...'); | ||
|
||
define('CREDENTIALS_WHAT_IS_MY_BROWSER_COM_KEY', '...'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/integration/Provider/Http/AbstractHttpProviderTestCase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace UserAgentParserTest\Integration\Provider\Http; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\CurlHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use UserAgentParserTest\Integration\Provider\AbstractProviderTestCase; | ||
|
||
abstract class AbstractHttpProviderTestCase extends AbstractProviderTestCase | ||
{ | ||
private $client; | ||
|
||
public function setUp() | ||
{ | ||
/* | ||
* move tests/credentials.php.dist to tests/credentials.php | ||
*/ | ||
if (! defined('CREDENTIALS_FILE_LOADED') && file_exists('tests/credentials.php')) { | ||
include 'tests/credentials.php'; | ||
} | ||
|
||
/* | ||
* 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'; | ||
|
||
if ($client instanceof Client) { | ||
$this->client = $client; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @return Client | ||
*/ | ||
protected function getClient() | ||
{ | ||
if ($this->client === null) { | ||
$handler = new CurlHandler(); | ||
$stack = HandlerStack::create($handler); | ||
|
||
$this->client = new Client([ | ||
'handler' => $stack, | ||
'timeout' => 5, | ||
|
||
'curl' => [ | ||
CURLOPT_SSL_VERIFYHOST => false, | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
], | ||
]); | ||
} | ||
|
||
return $this->client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
namespace UserAgentParserTest\Integration\Provider\Http; | ||
|
||
use UserAgentParser\Provider\Http\DeviceAtlasCom; | ||
|
||
/** | ||
* @coversNothing | ||
*/ | ||
class DeviceAtlasComTest extends AbstractHttpProviderTestCase | ||
{ | ||
/** | ||
* @expectedException \UserAgentParser\Exception\InvalidCredentialsException | ||
* @expectedExceptionMessage Your API key "invalid_api_key" is not valid for DeviceAtlasCom | ||
*/ | ||
public function testInvalidCredentials() | ||
{ | ||
$provider = new DeviceAtlasCom($this->getClient(), 'invalid_api_key'); | ||
|
||
$result = $provider->parse('...'); | ||
} | ||
|
||
/** | ||
* @expectedException \UserAgentParser\Exception\NoResultFoundException | ||
*/ | ||
public function testNoResultFound() | ||
{ | ||
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); | ||
|
||
$result = $provider->parse('...'); | ||
} | ||
|
||
public function testRealResultDevice() | ||
{ | ||
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); | ||
|
||
$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', | ||
'version' => [ | ||
'major' => 5, | ||
'minor' => 1, | ||
'patch' => null, | ||
|
||
'alias' => null, | ||
|
||
'complete' => '5.1', | ||
], | ||
], | ||
'renderingEngine' => [ | ||
'name' => 'WebKit', | ||
'version' => [ | ||
'major' => null, | ||
'minor' => null, | ||
'patch' => null, | ||
|
||
'alias' => null, | ||
|
||
'complete' => null, | ||
], | ||
], | ||
'operatingSystem' => [ | ||
'name' => 'iOS', | ||
'version' => [ | ||
'major' => 5, | ||
'minor' => 0, | ||
'patch' => null, | ||
|
||
'alias' => '_', | ||
|
||
'complete' => '5_0', | ||
], | ||
], | ||
'device' => [ | ||
'model' => null, | ||
'brand' => null, | ||
'type' => 'Mobile Phone', | ||
|
||
'isMobile' => null, | ||
'isTouch' => null, | ||
], | ||
'bot' => [ | ||
'isBot' => null, | ||
'name' => null, | ||
'type' => null, | ||
], | ||
], $result->toArray()); | ||
|
||
/* | ||
* Test the raw result | ||
*/ | ||
$rawResult = $result->getProviderResultRaw(); | ||
|
||
$this->assertInstanceOf('stdClass', $rawResult); | ||
$this->assertCount(6, (array) $rawResult); | ||
|
||
$this->assertObjectHasAttribute('browserVersion', $rawResult); | ||
$this->assertObjectHasAttribute('osVersion', $rawResult); | ||
$this->assertObjectHasAttribute('browserName', $rawResult); | ||
$this->assertObjectHasAttribute('primaryHardwareType', $rawResult); | ||
$this->assertObjectHasAttribute('browserRenderingEngine', $rawResult); | ||
$this->assertObjectHasAttribute('osName', $rawResult); | ||
} | ||
} |
Oops, something went wrong.