Completed
Pull Request — master (#78)
by Christophe
03:11
created

BrowserTestSuite   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 51
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A nameFromBrowser() 0 12 3
A setBrowserFromConfiguration() 0 18 4
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\TestSuite;
12
13
14
use aik099\PHPUnit\BrowserTestCase;
15
16
/**
17
 * Test Suite class for a set of tests from a single Test Case Class executed with a particular browser.
18
 */
19
class BrowserTestSuite extends AbstractTestSuite
20
{
21
22
	/**
23
	 * Generates suite name by the browser configuration.
24
	 *
25
	 * @param array $browser Browser configuration.
26
	 *
27
	 * @return string
28
	 */
29 7
	public function nameFromBrowser(array $browser)
30
	{
31 7
		$try_settings = array('alias', 'browserName', 'name');
32
33 7
		foreach ( $try_settings as $try_setting ) {
34 7
			if ( isset($browser[$try_setting]) ) {
35 7
				return $browser[$try_setting];
36
			}
37
		}
38
39 1
		return 'undefined';
40
	}
41
42
	/**
43
	 * Sets given browser to be used in each underlying test cases and test suites.
44
	 *
45
	 * @param array $browser Browser configuration.
46
	 * @param array $tests   Tests to process.
47
	 *
48
	 * @return self
49
	 */
50 2
	public function setBrowserFromConfiguration(array $browser, array $tests = null)
51
	{
52 2
		if ( !isset($tests) ) {
53 2
			$tests = $this->tests();
54
		}
55
56 2
		foreach ( $tests as $test ) {
57 2
			if ( $test instanceof \PHPUnit_Framework_TestSuite_DataProvider ) {
58
				$this->setBrowserFromConfiguration($browser, $test->tests());
59
			}
60
			else {
61
				/* @var $test BrowserTestCase */
62 2
				$test->setBrowserFromConfiguration($browser);
63
			}
64
		}
65
66 2
		return $this;
67
	}
68
69
}
70