Completed
Push — master ( 0591cb...33c12c )
by
unknown
07:17
created

NcbiPubMedResponseParserTest::idProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SCI\Tests\FilteredMetadata;
4
5
use SCI\FilteredMetadata\NcbiPubMedResponseParser;
6
7
/**
8
 * @covers \SCI\FilteredMetadata\NcbiPubMedResponseParser
9
 * @group semantic-cite
10
 *
11
 * @license GNU GPL v2+
12
 * @since   1.0
13
 *
14
 * @author mwjames
15
 */
16
class NcbiPubMedResponseParserTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$ncbiPubMedFilteredHttpResponseParser = $this->getMockBuilder( '\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser' )
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$this->assertInstanceOf(
25
			'\Onoi\Remi\ResponseParser',
26
			new NcbiPubMedResponseParser( $ncbiPubMedFilteredHttpResponseParser )
27
		);
28
	}
29
30
	public function testInterfaceMethods() {
31
32
		$ncbiPubMedFilteredHttpResponseParser = $this->getMockBuilder( '\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser' )
33
			->disableOriginalConstructor()
34
			->getMock();
35
36
		$instance = new NcbiPubMedResponseParser( $ncbiPubMedFilteredHttpResponseParser );
37
38
		$this->assertNull(
39
			$instance->usesCache()
40
		);
41
42
		$this->assertNull(
43
			$instance->getMessages()
44
		);
45
46
		$this->assertNull(
47
			$instance->getFilteredRecord()
48
		);
49
50
		$this->assertNull(
51
			$instance->getRawResponse( 42 )
52
		);
53
	}
54
55
	/**
56
	 * @dataProvider idProvider
57
	 */
58
	public function testDoParseForId( $id, $type, $expects ) {
59
60
		$record = $this->getMockBuilder( '\SCI\FilteredMetadata\BibliographicFilteredRecord' )
61
			->disableOriginalConstructor()
62
			->getMock();
63
64
		$record->expects( $this->at( 0 ) )
65
			->method( 'get' )
66
			->with( $this->stringContains( 'ncbi-dbtype' ) )
67
			->will( $this->returnValue( $type ) );
68
69
		$ncbiPubMedFilteredHttpResponseParser = $this->getMockBuilder( '\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser' )
70
			->disableOriginalConstructor()
71
			->getMock();
72
73
		$ncbiPubMedFilteredHttpResponseParser->expects( $this->any() )
74
			->method( 'getFilteredRecord' )
75
			->will( $this->returnValue( $record ) );
76
77
		$ncbiPubMedFilteredHttpResponseParser->expects( $expects )
78
			->method( 'doFilterResponseFor' );
79
80
		$instance = new NcbiPubMedResponseParser( $ncbiPubMedFilteredHttpResponseParser );
81
		$instance->doFilterResponseFor( $id );
82
	}
83
84
	public function idProvider() {
85
86
		$provider[] = [
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...
87
			'abc',
88
			'pmc',
89
			 $this->never()
90
		];
91
92
		$provider[] = [
93
			'abc',
94
			'pubmed',
95
			 $this->never()
96
		];
97
98
		$provider[] = [
99
			'PMID54846467',
100
			'pmc',
101
			 $this->never()
102
		];
103
104
		$provider[] = [
105
			'PMC54846467',
106
			'pmc',
107
			 $this->once()
108
		];
109
110
		$provider[] = [
111
			'PMID54846467',
112
			'pmid',
113
			 $this->once()
114
		];
115
116
		$provider[] = [
117
			'PMID54846467',
118
			'pubmed',
119
			 $this->once()
120
		];
121
122
		return $provider;
123
	}
124
125
}
126