Completed
Push — master ( 3e30e6...aad109 )
by mw
02:31
created

EmbeddedLinksReplacerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SEQL\Tests;
4
5
use SEQL\EmbeddedLinksReplacer;
6
7
/**
8
 * @covers \SEQL\EmbeddedLinksReplacer
9
 * @group semantic-external-query-lookup
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class EmbeddedLinksReplacerTest extends \PHPUnit_Framework_TestCase {
17
18
	private $querySource;
19
20
	protected function setUp() {
21
		$this->querySource = 'abc';
22
	}
23
24
	public function testCanConstruct() {
25
26
		$this->assertInstanceOf(
27
			'\SEQL\EmbeddedLinksReplacer',
28
			new EmbeddedLinksReplacer( $this->querySource )
29
		);
30
	}
31
32
	/**
33
	 * @dataProvider textProvider
34
	 */
35
	public function testReplace( $text, $expected ) {
36
37
		$instance = new EmbeddedLinksReplacer( $this->querySource );
38
39
		$this->assertEquals(
40
			$expected,
41
			$instance->replace( $text )
42
		);
43
	}
44
45
	public function textProvider() {
46
47
		#0
48
		$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...
49
			'Foo bar',
50
			'Foo bar'
51
		);
52
53
		#1
54
		$provider[] = array(
55
			'Foo [42] bar',
56
			'Foo [42] bar'
57
		);
58
59
		#2
60
		$provider[] = array(
61
			'Foo [42 1001] bar',
62
			'Foo [42 1001] bar'
63
		);
64
65
		#3
66
		$provider[] = array(
67
			'Foo [[42]] bar',
68
			'Foo [[abc:42|42]] bar'
69
		);
70
71
		#4
72
		$provider[] = array(
73
			'Foo [[42|1001]] bar',
74
			'Foo [[abc:42|1001]] bar'
75
		);
76
77
		// We can't guess the type of a remote annotation therefore it is turned
78
		// into an simple text value
79
80
		#5
81
		$provider[] = array(
82
			'Foo [[Has number::42]] bar',
83
			'Foo 42 bar'
84
		);
85
86
		#6
87
		$provider[] = array(
88
			'Foo [[Has number::42|1001]] bar',
89
			'Foo 1001 bar'
90
		);
91
92
		return $provider;
93
	}
94
95
}
96