Completed
Push — master ( 93a702...008e2c )
by Alexander
03:47
created

SauceLabsBrowserConfiguration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 17
Bugs 0 Features 1
Metric Value
wmc 8
c 17
b 0
f 1
lcom 2
cbo 4
dl 0
loc 71
ccs 24
cts 24
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHost() 0 4 1
A getAPIClient() 0 6 1
A onTestSetup() 0 16 3
A getDesiredCapabilities() 0 14 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\IAPIClient;
15
use aik099\PHPUnit\APIClient\SauceLabsAPIClient;
16
use aik099\PHPUnit\Event\TestEvent;
17
use WebDriver\SauceLabs\SauceRest;
18
19
/**
20
 * Browser configuration tailored to use with "Sauce Labs" service.
21
 *
22
 * @link https://saucelabs.com/php
23
 */
24
class SauceLabsBrowserConfiguration extends ApiBrowserConfiguration
25
{
26
	const TYPE = 'saucelabs';
27
28
	/**
29
	 * Returns API class for service interaction.
30
	 *
31
	 * @return IAPIClient
32
	 */
33 2
	public function getAPIClient()
34
	{
35 2
		$sauce_rest = new SauceRest($this->getApiUsername(), $this->getApiKey());
36
37 2
		return new SauceLabsAPIClient($sauce_rest);
38
	}
39
40
	/**
41
	 * Hook, called from "BrowserTestCase::setUp" method.
42
	 *
43
	 * @param TestEvent $event Test event.
44
	 *
45
	 * @return void
46
	 */
47 16
	public function onTestSetup(TestEvent $event)
48
	{
49 16
		if ( !$event->validateSubscriber($this->getTestCase()) ) {
50 6
			return;
51
		}
52
53 16
		parent::onTestSetup($event);
54
55 16
		$desired_capabilities = $this->getDesiredCapabilities();
56
57 16
		if ( getenv('PHPUNIT_MINK_TUNNEL_ID') ) {
58 1
			$desired_capabilities['tunnel-identifier'] = getenv('PHPUNIT_MINK_TUNNEL_ID');
59 1
		}
60
61 16
		$this->setDesiredCapabilities($desired_capabilities);
62 16
	}
63
64
	/**
65
	 * Returns hostname from browser configuration.
66
	 *
67
	 * @return string
68
	 */
69 11
	public function getHost()
70
	{
71 11
		return $this->getApiUsername() . ':' . $this->getApiKey() . '@ondemand.saucelabs.com';
72
	}
73
74
	/**
75
	 * Returns desired capabilities from browser configuration.
76
	 *
77
	 * @return array
78
	 */
79 19
	public function getDesiredCapabilities()
80
	{
81 19
		$capabilities = parent::getDesiredCapabilities();
82
83 19
		if ( !isset($capabilities['platform']) ) {
84 17
			$capabilities['platform'] = 'Windows 7';
85 17
		}
86
87 19
		if ( !isset($capabilities['version']) ) {
88 10
			$capabilities['version'] = '';
89 10
		}
90
91 19
		return $capabilities;
92
	}
93
94
}
95