Test Failed
Push — master ( 7969f2...0db1fe )
by Jeroen De
09:42
created

HookDefinitionTest::namesProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace ParserHooks\Tests;
4
5
use ParserHooks\HookDefinition;
6
7
/**
8
 * @covers ParserHooks\HookDefinition
9
 *
10
 * @group ParserHooks
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class HookDefinitionTest extends \PHPUnit_Framework_TestCase {
16
17
	public function namesProvider() {
18
		return $this->arrayWrap( array(
19
			'foo',
20
			'foo bar',
21
			array( 'foo' ),
22
			array( 'foobar' ),
23
			array( 'foo', 'bAr' ),
24
			array( 'foo', 'bar', 'baz BAH', 'BAR' ),
25
		) );
26
	}
27
28
	/**
29
	 * @dataProvider namesProvider
30
	 *
31
	 * @param string|string[] $names
32
	 */
33
	public function testGetNames( $names ) {
34
		$definition = new HookDefinition( $names );
35
		$obtainedNames = $definition->getNames();
36
37
		$this->assertInternalType( 'array', $obtainedNames );
38
		$this->assertContainsOnly( 'string', $obtainedNames );
39
		$this->assertEquals( (array)$names, $obtainedNames );
40
	}
41
42
	public function parametersProvider() {
43
		return $this->arrayWrap( array(
44
			array()
45
		) );
46
	}
47
48
	/**
49
	 * @dataProvider parametersProvider
50
	 *
51
	 * @param array $parameters
52
	 */
53
	public function testGetParameters( array $parameters ) {
54
		$definition = new HookDefinition( 'foo', $parameters );
55
56
		$this->assertEquals( $parameters, $definition->getParameters() );
57
	}
58
59
	public function defaultParametersProvider() {
60
		return $this->arrayWrap( array(
61
			'foo',
62
			'foo bar',
63
			array( 'foo' ),
64
			array( 'foobar' ),
65
			array( 'foo', 'bAr' ),
66
			array( 'foo', 'bar', 'baz BAH', 'BAR' ),
67
		) );
68
	}
69
70
	/**
71
	 * @dataProvider namesProvider
72
	 *
73
	 * @param string|string[] $defaultParameters
74
	 */
75
	public function testGetDefaultParameters( $defaultParameters ) {
76
		$definition = new HookDefinition( 'foo', array(), $defaultParameters );
77
		$obtainedDefaultParams = $definition->getDefaultParameters();
78
79
		$this->assertInternalType( 'array', $obtainedDefaultParams );
80
		$this->assertContainsOnly( 'string', $obtainedDefaultParams );
81
		$this->assertEquals( (array)$defaultParameters, $obtainedDefaultParams );
82
	}
83
84
	protected function arrayWrap( array $elements ) {
85
		return array_map(
86
			function( $element ) {
87
				return array( $element );
88
			},
89
			$elements
90
		);
91
	}
92
93
	public function testCannotConstructWithEmptyNameList() {
94
		$this->setExpectedException( 'InvalidArgumentException' );
95
		new HookDefinition( array() );
96
	}
97
98
	public function testCannotConstructWithNonStringName() {
99
		$this->setExpectedException( 'InvalidArgumentException' );
100
		new HookDefinition( 42 );
101
	}
102
103
	public function testCannotConstructWithNonStringNames() {
104
		$this->setExpectedException( 'InvalidArgumentException' );
105
		new HookDefinition( array( 'foo', 42, 'bar' ) );
106
	}
107
108
	public function testCannotConstructWithNonStringDefaultArg() {
109
		$this->setExpectedException( 'InvalidArgumentException' );
110
		new HookDefinition( 'foo', array(), 42 );
111
	}
112
113
	public function testCannotConstructWithNonStringDefaultArgs() {
114
		$this->setExpectedException( 'InvalidArgumentException' );
115
		new HookDefinition(
116
			'foo',
117
			array(),
118
			array( 'foo', 42, 'bar' )
119
		);
120
	}
121
122
}
123