Failed Conditions
Push — master ( 886274...2e4c65 )
by Alexander
03:16
created

BrowserStackBrowserConfiguration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 96.55%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 4
dl 0
loc 76
ccs 28
cts 29
cp 0.9655
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAPIClient() 0 8 1
A getHost() 0 4 1
A getDesiredCapabilities() 0 15 3
A onTestSetup() 0 17 3
1
<?php
2
/**
3
 * This file is part of the phpunit-mink library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/aik099/phpunit-mink
9
 */
10
11
namespace aik099\PHPUnit\BrowserConfiguration;
12
13
14
use aik099\PHPUnit\APIClient\BrowserStackAPIClient;
15
use aik099\PHPUnit\APIClient\IAPIClient;
16
use aik099\PHPUnit\Event\TestEvent;
17
use WebDriver\ServiceFactory;
18
19
/**
20
 * Browser configuration tailored to use with "BrowserStack" service.
21
 *
22
 * @link https://www.browserstack.com/automate
23
 */
24
class BrowserStackBrowserConfiguration extends ApiBrowserConfiguration
25
{
26
	const TYPE = 'browserstack';
27
28
	/**
29
	 * Returns API class for service interaction.
30
	 *
31
	 * @return IAPIClient
32
	 */
33 1
	public function getAPIClient()
34
	{
35 1
		return new BrowserStackAPIClient(
36 1
			$this->getApiUsername(),
37 1
			$this->getApiKey(),
38 1
			ServiceFactory::getInstance()->getService('service.curl')
39 1
		);
40
	}
41
42
	/**
43
	 * Hook, called from "BrowserTestCase::setUp" method.
44
	 *
45
	 * @param TestEvent $event Test event.
46
	 *
47
	 * @return void
48
	 */
49 8
	public function onTestSetup(TestEvent $event)
50
	{
51 8
		if ( !$event->validateSubscriber($this->getTestCase()) ) {
52
			return;
53
		}
54
55 8
		parent::onTestSetup($event);
56
57 8
		$desired_capabilities = $this->getDesiredCapabilities();
58
59 8
		if ( getenv('PHPUNIT_MINK_TUNNEL_ID') ) {
60 1
			$desired_capabilities['browserstack.local'] = 'true';
61 1
			$desired_capabilities['browserstack.localIdentifier'] = getenv('PHPUNIT_MINK_TUNNEL_ID');
62 1
		}
63
64 8
		$this->setDesiredCapabilities($desired_capabilities);
65 8
	}
66
67
	/**
68
	 * Returns hostname from browser configuration.
69
	 *
70
	 * @return string
71
	 */
72 7
	public function getHost()
73
	{
74 7
		return $this->getApiUsername() . ':' . $this->getApiKey() . '@hub.browserstack.com';
75
	}
76
77
	/**
78
	 * Returns desired capabilities from browser configuration.
79
	 *
80
	 * @return array
81
	 * @link   http://www.browserstack.com/automate/capabilities
82
	 */
83 11
	public function getDesiredCapabilities()
84
	{
85 11
		$capabilities = parent::getDesiredCapabilities();
86
87 11
		if ( !isset($capabilities['os']) ) {
88 10
			$capabilities['os'] = 'Windows';
89 9
			$capabilities['os_version'] = '7';
90 9
		}
91
92 11
		if ( !isset($capabilities['acceptSslCerts']) ) {
93 9
			$capabilities['acceptSslCerts'] = 'true';
94 9
		}
95
96 11
		return $capabilities;
97
	}
98
99
}
100