1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SEQL\ByHttpRequest\Tests; |
4
|
|
|
|
5
|
|
|
use SEQL\ByHttpRequest\QueryResult; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SEQL\ByHttpRequest\QueryResult |
10
|
|
|
* @group semantic-external-query-lookup |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class QueryResultTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $store; |
20
|
|
|
|
21
|
|
|
protected function setUp() { |
22
|
|
|
|
23
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMockForAbstractClass(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testCanConstruct() { |
29
|
|
|
|
30
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMock(); |
33
|
|
|
|
34
|
|
|
$printRequests = array(); |
35
|
|
|
$results = array(); |
36
|
|
|
|
37
|
|
|
$this->assertInstanceOf( |
38
|
|
|
'\SEQL\ByHttpRequest\QueryResult', |
39
|
|
|
new QueryResult( $printRequests, $query, $results, $this->store, false ) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetNext() { |
44
|
|
|
|
45
|
|
|
$jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) |
46
|
|
|
->disableOriginalConstructor() |
47
|
|
|
->getMock(); |
48
|
|
|
|
49
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
50
|
|
|
->disableOriginalConstructor() |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMock(); |
56
|
|
|
|
57
|
|
|
$printRequests = array( |
58
|
|
|
$printRequest |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$results = array( |
62
|
|
|
new DIWikiPage( 'Foo', NS_MAIN ) |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$instance = new QueryResult( $printRequests, $query, $results, $this->store, false ); |
66
|
|
|
$instance->setJsonResponseParser( $jsonResponseParser ); |
67
|
|
|
|
68
|
|
|
foreach ( $instance->getNext() as $result ) { |
69
|
|
|
$this->assertInstanceOf( |
70
|
|
|
'\SEQL\ByHttpRequest\CannedResultArray', |
71
|
|
|
$result |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testToArray() { |
77
|
|
|
|
78
|
|
|
$expected = array( |
79
|
|
|
'Foo' |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
83
|
|
|
->disableOriginalConstructor() |
84
|
|
|
->getMock(); |
85
|
|
|
|
86
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
|
|
|
|
87
|
|
|
->disableOriginalConstructor() |
88
|
|
|
->getMock(); |
89
|
|
|
|
90
|
|
|
$jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) |
91
|
|
|
->disableOriginalConstructor() |
92
|
|
|
->getMock(); |
93
|
|
|
|
94
|
|
|
$jsonResponseParser->expects( $this->exactly( 2 ) ) |
95
|
|
|
->method( 'getRawResponseResult' ) |
96
|
|
|
->will( $this->returnValue( $expected ) ); |
97
|
|
|
|
98
|
|
|
$printRequests = array(); |
99
|
|
|
$results = array(); |
100
|
|
|
|
101
|
|
|
$instance = new QueryResult( $printRequests, $query, $results, $this->store, false ); |
102
|
|
|
$instance->setJsonResponseParser( $jsonResponseParser ); |
103
|
|
|
|
104
|
|
|
$this->assertEquals( |
105
|
|
|
$expected, |
106
|
|
|
$instance->toArray() |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$this->assertEquals( |
110
|
|
|
$expected, |
111
|
|
|
$instance->serializeToArray() |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testGetLink() { |
116
|
|
|
|
117
|
|
|
$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) |
118
|
|
|
->disableOriginalConstructor() |
119
|
|
|
->getMock(); |
120
|
|
|
|
121
|
|
|
$printRequest->expects( $this->once() ) |
122
|
|
|
->method( 'getSerialisation' ) |
123
|
|
|
->will( $this->returnValue( '?ABC' ) ); |
124
|
|
|
|
125
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
126
|
|
|
->disableOriginalConstructor() |
127
|
|
|
->getMock(); |
128
|
|
|
|
129
|
|
|
$query->expects( $this->any() ) |
130
|
|
|
->method( 'getExtraPrintouts' ) |
131
|
|
|
->will( $this->returnValue( array( $printRequest ) ) ); |
132
|
|
|
|
133
|
|
|
$printRequests = array(); |
134
|
|
|
$results = array(); |
135
|
|
|
|
136
|
|
|
$instance = new QueryResult( $printRequests, $query, $results, $this->store, false ); |
137
|
|
|
$instance->setRemoteTargetUrl( 'http://example.org:8080' ); |
138
|
|
|
|
139
|
|
|
$this->assertInstanceOf( |
140
|
|
|
'\SMWInfolink', |
141
|
|
|
$instance->getLink() |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.