1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onoi\Remi\Tests\Integration\Ncbi; |
4
|
|
|
|
5
|
|
|
use Onoi\Remi\FilteredHttpResponseParserFactory; |
6
|
|
|
use Onoi\Remi\FilteredRecord; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @group semantic-cite |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 0.1 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class PubMedCannedResponseParserTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @dataProvider pmidFileProvider |
20
|
|
|
*/ |
21
|
|
|
public function testPMIDParser( $id, $httpJsonRequestFile, $httpXmlRequestFile, $expectedResultFile ) { |
22
|
|
|
|
23
|
|
|
list( $id, $httpRequest, $jsonContents, $xmlContents, $expected ) = $this->prepareFileContents( |
|
|
|
|
24
|
|
|
$id, |
25
|
|
|
$httpJsonRequestFile, |
26
|
|
|
$httpXmlRequestFile, |
27
|
|
|
$expectedResultFile |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$filteredHttpResponseParserFactory = new FilteredHttpResponseParserFactory( |
31
|
|
|
$httpRequest |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
$instance = $filteredHttpResponseParserFactory->newNcbiPubMedFilteredHttpResponseParser( |
35
|
|
|
new FilteredRecord() |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$this->assertEquals( |
39
|
|
|
$jsonContents . $xmlContents, |
40
|
|
|
$instance->getRawResponseById( $id ) |
|
|
|
|
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$instance->doFilterResponseById( $id ); |
44
|
|
|
|
45
|
|
|
$this->assertJsonStringEqualsJsonFile( |
46
|
|
|
$expectedResultFile, |
47
|
|
|
$instance->getFilteredRecord()->asJsonString() |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @dataProvider pmcidFileProvider |
53
|
|
|
*/ |
54
|
|
|
public function testPMCIDParser( $id, $httpJsonRequestFile, $httpXmlRequestFile, $expectedResultFile ) { |
55
|
|
|
|
56
|
|
|
list( $id, $httpRequest, $jsonContents, $xmlContents, $expected ) = $this->prepareFileContents( |
|
|
|
|
57
|
|
|
$id, |
58
|
|
|
$httpJsonRequestFile, |
59
|
|
|
$httpXmlRequestFile, |
60
|
|
|
$expectedResultFile |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$FilteredHttpResponseParserFactory = new FilteredHttpResponseParserFactory( |
64
|
|
|
$httpRequest |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$instance = $FilteredHttpResponseParserFactory->newNcbiPubMedCentralFilteredHttpResponseParser( |
68
|
|
|
new FilteredRecord() |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->assertEquals( |
72
|
|
|
$jsonContents . $xmlContents, |
73
|
|
|
$instance->getRawResponseById( $id ) |
|
|
|
|
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$instance->doFilterResponseById( $id ); |
77
|
|
|
|
78
|
|
|
$this->assertJsonStringEqualsJsonFile( |
79
|
|
|
$expectedResultFile, |
80
|
|
|
$instance->getFilteredRecord()->asJsonString() |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
private function prepareFileContents( $id, $httpJsonRequestFile, $httpXmlRequestFile, $expectedResultFile ) { |
85
|
|
|
|
86
|
|
|
$id = str_replace( array( 'PMID', 'PMC' ), '', $id ); |
87
|
|
|
|
88
|
|
|
$jsonContents = file_get_contents( $httpJsonRequestFile ); |
89
|
|
|
$xmlContents = file_get_contents( $httpXmlRequestFile ); |
90
|
|
|
|
91
|
|
|
$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' ) |
92
|
|
|
->disableOriginalConstructor() |
93
|
|
|
->getMock(); |
94
|
|
|
|
95
|
|
|
$httpRequest->expects( $this->any() ) |
96
|
|
|
->method( 'execute' ) |
97
|
|
|
->will( $this->onConsecutiveCalls( |
98
|
|
|
$jsonContents, $xmlContents, |
99
|
|
|
$jsonContents, $xmlContents ) ); |
100
|
|
|
|
101
|
|
|
$httpRequest->expects( $this->any() ) |
102
|
|
|
->method( 'getLastError' ) |
103
|
|
|
->will( $this->returnValue( '' ) ); |
104
|
|
|
|
105
|
|
|
return array( $id, $httpRequest, $jsonContents, $xmlContents, $expectedResultFile ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function pmidFileProvider() { |
109
|
|
|
|
110
|
|
|
$path = __DIR__ . '/Fixtures/'; |
111
|
|
|
$provider = array(); |
112
|
|
|
|
113
|
|
|
$provider[] = array( |
114
|
|
|
'PMID19782018', |
115
|
|
|
$path . 'PMID19782018.json', |
116
|
|
|
$path . 'PMID19782018.xml', |
117
|
|
|
$path . 'PMID19782018.expected' |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
return $provider; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function pmcidFileProvider() { |
124
|
|
|
|
125
|
|
|
$path = __DIR__ . '/Fixtures/'; |
126
|
|
|
$provider = array(); |
127
|
|
|
|
128
|
|
|
$provider[] = array( |
129
|
|
|
'PMC2286209', |
130
|
|
|
$path . 'PMC2286209.json', |
131
|
|
|
$path . 'PMC2286209.xml', |
132
|
|
|
$path . 'PMC2286209.expected' |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$provider[] = array( |
136
|
|
|
'PMC2776723', |
137
|
|
|
$path . 'PMC2776723.json', |
138
|
|
|
$path . 'PMC2776723.xml', |
139
|
|
|
$path . 'PMC2776723.expected' |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
$provider[] = array( |
143
|
|
|
'PMC5348191', |
144
|
|
|
$path . 'PMC5348191.json', |
145
|
|
|
$path . 'PMC5348191.xml', |
146
|
|
|
$path . 'PMC5348191.expected' |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
return $provider; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.