NcbiPubMedFilteredHttpResponseParserTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 80
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 15 1
B testFailedResponse() 0 30 1
B testNullResponse() 0 29 1
1
<?php
2
3
namespace Onoi\Remi\Tests\Ncbi;
4
5
use Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser;
6
7
/**
8
 * @covers \Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser
9
 * @group onoi-remi
10
 *
11
 * @license GNU GPL v2+
12
 * @since   0.1
13
 *
14
 * @author mwjames
15
 */
16
class NcbiPubMedFilteredHttpResponseParserTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$filteredRecord = $this->getMockBuilder( '\Onoi\Remi\FilteredRecord' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$this->assertInstanceOf(
29
			'\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser',
30
			new NcbiPubMedFilteredHttpResponseParser( $httpRequest, $filteredRecord )
31
		);
32
	}
33
34
	public function testFailedResponse() {
35
36
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$httpRequest->expects( $this->atLeastOnce() )
41
			->method( 'getLastError' )
42
			->will( $this->returnValue( 'error' ) );
43
44
		$filteredRecord = $this->getMockBuilder( '\Onoi\Remi\FilteredRecord' )
45
			->disableOriginalConstructor()
46
			->getMock();
47
48
		$instance = new NcbiPubMedFilteredHttpResponseParser(
49
			$httpRequest,
50
			$filteredRecord
51
		);
52
53
		$instance->doFilterResponseById( 'foo' );
54
55
		$this->assertEquals(
56
			array( array(
57
				'onoi-remi-request-error',
58
				'error',
59
				'foo'
60
			) ),
61
			$instance->getMessages()
62
		);
63
	}
64
65
	public function testNullResponse() {
66
67
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
68
			->disableOriginalConstructor()
69
			->getMock();
70
71
		$httpRequest->expects( $this->atLeastOnce() )
72
			->method( 'getLastError' )
73
			->will( $this->returnValue( '' ) );
74
75
		$filteredRecord = $this->getMockBuilder( '\Onoi\Remi\FilteredRecord' )
76
			->disableOriginalConstructor()
77
			->getMock();
78
79
		$instance = new NcbiPubMedFilteredHttpResponseParser(
80
			$httpRequest,
81
			$filteredRecord
82
		);
83
84
		$instance->doFilterResponseById( 'foo' );
85
86
		$this->assertEquals(
87
			array( array(
88
				'onoi-remi-response-empty',
89
				'foo'
90
			) ),
91
			$instance->getMessages()
92
		);
93
	}
94
95
}
96