Completed
Push — master ( 36ba73...9ed582 )
by mw
04:36
created

testGetFormattedSciteFuncFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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