Failed Conditions
Pull Request — master (#102)
by
unknown
03:22
created

BrowserTestSuite::nameFromBrowser()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 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\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 8
	public function nameFromBrowser(array $browser)
30
	{
31 8
		$try_settings = array('alias', 'browserName', 'name');
32
33 8
		foreach ( $try_settings as $try_setting ) {
34 8
			if ( isset($browser[$try_setting]) ) {
35 8
				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 3
	public function setBrowserFromConfiguration(array $browser, array $tests = null)
51
	{
52 3
		if ( !isset($tests) ) {
53 3
			$tests = $this->tests();
54
		}
55
56 3
		foreach ( $tests as $test ) {
57 3
			if ( $test instanceof \PHPUnit_Framework_TestSuite_DataProvider ) {
58
				$this->setBrowserFromConfiguration($browser, $test->tests());
59
			}
60
			else {
61
				/* @var $test BrowserTestCase */
0 ignored issues
show
introduced by
Type comment must be in "/** @var ClassName $variable_name */" format
Loading history...
62 3
				$test->setBrowserFromConfiguration($browser);
63
			}
64
		}
65
66 3
		return $this;
67
	}
68
69
}
70