Completed
Push — master ( 2e888f...d062b4 )
by mw
03:13
created

JsonResponseParserTest::resultProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 63
rs 9.4348
cc 1
eloc 37
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SEQL\ByAskApiHttpRequest\Tests;
4
5
use SEQL\ByAskApiHttpRequest\JsonResponseParser;
6
use SMW\DIProperty;
7
8
/**
9
 * @covers \SEQL\ByAskApiHttpRequest\JsonResponseParser
10
 * @group semantic-external-query-lookup
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class JsonResponseParserTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$dataValueDeserializer = $this->getMockBuilder( '\SEQL\DataValueDeserializer' )
22
			->disableOriginalConstructor()
23
			->getMock();
24
25
		$this->assertInstanceOf(
26
			'\SEQL\ByAskApiHttpRequest\JsonResponseParser',
27
			new JsonResponseParser( $dataValueDeserializer )
28
		);
29
	}
30
31
	/**
32
	 * @dataProvider resultProvider
33
	 */
34
	public function testDoParse( $result, $rawResponseResult, $hasFurtherResults, $property ) {
35
36
		$dataValueDeserializer = $this->getMockBuilder( '\SEQL\DataValueDeserializer' )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$instance = new JsonResponseParser( $dataValueDeserializer );
41
42
		$instance->doParse( $result );
43
44
		$this->assertEquals(
45
			$rawResponseResult,
46
			$instance->getRawResponseResult()
47
		);
48
49
		$this->assertEquals(
50
			$hasFurtherResults,
51
			$instance->hasFurtherResults()
52
		);
53
54
		if ( $property !== null ) {
55
			$this->assertEquals(
56
				$property,
57
				$instance->findPropertyFromInMemoryExternalRepositoryCache( $property )
58
			);
59
		}
60
	}
61
62
	public function resultProvider() {
63
64
		#0
65
		$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...
66
			array( 'query' => array() ),
67
			array(),
68
			false,
69
			null
70
		);
71
72
		#1
73
		$provider[] = array(
74
			array(
75
				'query-continue-offset' => 3,
76
				'query' => array()
77
			),
78
			array(),
79
			true,
80
			null
81
		);
82
83
		#2
84
		$provider[] = array(
85
			array(
86
				'query-continue-offset' => 3,
87
				'query' => array(
88
					'printrequests' => array(
89
						array( 'label' => 'Category', 'mode' => 0 )
90
					)
91
				)
92
			),
93
			array(
94
				'printrequests' => array(
95
					array( 'label' => 'Category', 'mode' => 0 )
96
				)
97
			),
98
			true,
99
			new DIProperty( '_INST' )
100
		);
101
102
		#3
103
		$provider[] = array(
104
			array(
105
				'query' => array(
106
					'printrequests' => array(
107
						array( 'label' => 'Category', 'mode' => 0 )
108
					),
109
				'results' => array()
110
				),
111
			),
112
			array(
113
				'printrequests' => array(
114
					array( 'label' => 'Category', 'mode' => 0 )
115
				),
116
				'results' => array()
117
			),
118
			false,
119
			null
120
		);
121
122
123
		return $provider;
124
	}
125
126
}
127