PubMedCannedResponseParserTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 137
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B testPMIDParser() 0 29 1
B testPMCIDParser() 0 29 1
A prepareFileContents() 0 23 1
A pmidFileProvider() 0 14 1
B pmcidFileProvider() 0 28 1
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(
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
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 )
0 ignored issues
show
Bug introduced by
The method getRawResponseById() does not exist on Onoi\Remi\ResponseParser. Did you maybe mean getRawResponse()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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(
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
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 )
0 ignored issues
show
Bug introduced by
The method getRawResponseById() does not exist on Onoi\Remi\ResponseParser. Did you maybe mean getRawResponse()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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