HookDefinitionTest::namesProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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