Completed
Pull Request — master (#100)
by Michał
01:35
created

BrowserTestSuite::setBrowserFromConfiguration()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 7
cts 8
cp 0.875
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 6
nop 2
crap 4.0312
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
use PHPUnit\Framework\DataProviderTestSuite;
16
17
/**
18
 * Test Suite class for a set of tests from a single Test Case Class executed with a particular browser.
19
 */
20
class BrowserTestSuite extends AbstractTestSuite
21
{
22
23
	/**
24
	 * Generates suite name by the browser configuration.
25
	 *
26
	 * @param array $browser Browser configuration.
27
	 *
28
	 * @return string
29
	 */
30 8
	public function nameFromBrowser(array $browser)
31
	{
32 8
		$try_settings = array('alias', 'browserName', 'name');
33
34 8
		foreach ( $try_settings as $try_setting ) {
35 8
			if ( isset($browser[$try_setting]) ) {
36 8
				return $browser[$try_setting];
37
			}
38
		}
39
40 1
		return 'undefined';
41
	}
42
43
	/**
44
	 * Sets given browser to be used in each underlying test cases and test suites.
45
	 *
46
	 * @param array $browser Browser configuration.
47
	 * @param array $tests   Tests to process.
48
	 *
49
	 * @return self
50
	 */
51 3
	public function setBrowserFromConfiguration(array $browser, array $tests = null)
52
	{
53 3
		if ( !isset($tests) ) {
54 3
			$tests = $this->tests();
55
		}
56
57 3
		foreach ( $tests as $test ) {
58 3
			if ( $test instanceof DataProviderTestSuite ) {
59
				$this->setBrowserFromConfiguration($browser, $test->tests());
60
			}
61
			else {
62
				/* @var $test BrowserTestCase */
0 ignored issues
show
introduced by
Type comment must be in "/** @var ClassName $variable_name */" format
Loading history...
63 3
				$test->setBrowserFromConfiguration($browser);
64
			}
65
		}
66
67 3
		return $this;
68
	}
69
70
}
71