Completed
Pull Request — master (#100)
by Michał
01:35
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 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 51
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

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
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