OptionsTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 76
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 7 1
A testAddOption() 0 15 1
A testInit() 0 8 1
A testUnregisteredKeyThrowsException() 0 7 1
A initProvider() 0 28 1
1
<?php
2
3
namespace SUC\Tests;
4
5
use SUC\Options;
6
7
/**
8
 * @covers \SUC\Options
9
 * @group summary-cards
10
 *
11
 * @license GNU GPL v2+
12
 * @since   1.0
13
 *
14
 * @author mwjames
15
 */
16
class OptionsTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$this->assertInstanceOf(
21
			'\SUC\Options',
22
			new Options()
23
		);
24
	}
25
26
	public function testAddOption() {
27
28
		$instance = new Options();
29
30
		$this->assertFalse(
31
			$instance->has( 'Foo' )
32
		);
33
34
		$instance->set( 'Foo', 42 );
35
36
		$this->assertEquals(
37
			42,
38
			$instance->get( 'Foo' )
39
		);
40
	}
41
42
	/**
43
	 * @dataProvider initProvider
44
	 */
45
	public function testInit( $name ) {
46
47
		$instance = Options::newFromGlobals();
48
49
		$this->assertTrue(
50
			$instance->has( $name )
51
		);
52
	}
53
54
	public function testUnregisteredKeyThrowsException() {
55
56
		$instance = new Options();
57
58
		$this->setExpectedException( 'InvalidArgumentException' );
59
		$instance->get( 'Foo' );
60
	}
61
62
	public function initProvider() {
63
64
		$provider[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$provider was never initialized. Although not strictly required by PHP, it is generally a good practice to add $provider = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
65
			'tooltipRequestCacheTTL'
66
		);
67
68
		$provider[] = array(
69
			'cachePrefix'
70
		);
71
72
		$provider[] = array(
73
			'enabledNamespaceWithTemplate'
74
		);
75
76
		$provider[] = array(
77
			'enabledForAnonUsers'
78
		);
79
80
		$provider[] = array(
81
			'backendParserCacheLifetime'
82
		);
83
84
		$provider[] = array(
85
			'backendParserCacheType'
86
		);
87
88
		return $provider;
89
	}
90
91
}
92