Completed
Pull Request — master (#94)
by mw
01:14
created

PreTextFormatterTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SCI\Tests;
4
5
use SCI\PreTextFormatter;
6
use Title;
7
use Parser;
8
use ParserOptions;
9
use SMW\Tests\PHPUnitCompat;
10
11
/**
12
 * @covers \SCI\PreTextFormatter
13
 * @group semantic-cite
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.4
17
 *
18
 * @author mwjames
19
 */
20
class PreTextFormatterTest extends \PHPUnit_Framework_TestCase {
21
22
	use PHPUnitCompat;
23
24
	const LF = "\n";
25
26
	public function testCanConstruct() {
27
28
		$this->assertInstanceOf(
29
			'\SCI\PreTextFormatter',
30
			new PreTextFormatter()
31
		);
32
	}
33
34
	/**
35
	 * @dataProvider parametersProvider
36
	 */
37
	public function testFormat( $params ) {
38
39
		$instance = new PreTextFormatter();
40
41
		$this->assertInternalType(
42
			'array',
43
			$instance->format( $params )
44
		);
45
	}
46
47
	/**
48
	 * @dataProvider parametersProvider
49
	 */
50
	public function testGetFormattedSciteFuncFrom( $params, $expected ) {
51
52
		$instance = new PreTextFormatter();
53
54
		$this->assertSame(
55
			$expected,
56
			$instance->getFormattedSciteFuncFrom( $params )
57
		);
58
	}
59
60
	public function parametersProvider() {
61
62
		$provider[] = [
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...
63
			[
64
				'Bar',
65
				'@Foobar'
66
			],
67
			"<pre>{{#scite:" . self::LF . " |Bar" . self::LF . "}}</pre>"
68
		];
69
70
		$provider[] = [
71
			[
72
				'Bar',
73
				'+sep=,',
74
				'@Foobar',
75
				'Foo'
76
			],
77
			"<pre>{{#scite:" . self::LF . " |Bar|+sep=," . self::LF . " |Foo" . self::LF . "}}</pre>"
78
		];
79
80
		return $provider;
81
	}
82
83
}
84