Code Duplication    Length = 29-30 lines in 3 locations

tests/php/controller/proxycontrollerTest.php 3 locations

@@ 95-123 (lines=29) @@
92
		$this->assertEquals('text/calendar', $actual->getHeaders()['Content-Type']);
93
	}
94
95
	public function testProxyClientException() {
96
		$testUrl = 'http://abc.def/foobar?123';
97
98
		$this->client->expects($this->once())
99
			->method('newClient')
100
			->will($this->returnValue($this->newClient));
101
		$this->newClient->expects($this->once())
102
			->method('get')
103
			->with($testUrl, [
104
				'stream' => true,
105
			])
106
			->will($this->throwException(new ClientException('Exception Message foo bar 42',
107
				$this->exceptionRequest, $this->exceptionResponse)));
108
		$this->exceptionResponse->expects($this->once())
109
			->method('getStatusCode')
110
			->will($this->returnValue(403));
111
		$this->logger->expects($this->once())
112
			->method('debug')
113
			->with($this->equalTo('Exception Message foo bar 42'));
114
115
		$actual = $this->controller->proxy($testUrl);
116
117
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
118
		$this->assertEquals('422', $actual->getStatus());
119
		$this->assertEquals([
120
			'message' => 'Exception Message foo bar 42',
121
			'proxy_code' => 403
122
		], $actual->getData());
123
	}
124
125
	public function testProxyConnectException() {
126
		$testUrl = 'http://abc.def/foobar?123';
@@ 125-154 (lines=30) @@
122
		], $actual->getData());
123
	}
124
125
	public function testProxyConnectException() {
126
		$testUrl = 'http://abc.def/foobar?123';
127
128
		$this->client->expects($this->once())
129
			->method('newClient')
130
			->will($this->returnValue($this->newClient));
131
		$this->newClient->expects($this->once())
132
			->method('get')
133
			->with($testUrl, [
134
				'stream' => true,
135
			])
136
			->will($this->throwException(new ConnectException('Exception Message foo bar 42',
137
				$this->exceptionRequest, $this->exceptionResponse)));
138
		$this->l10n->expects($this->once())
139
			->method('t')
140
			->with($this->equalTo('Error connecting to remote server'))
141
			->will($this->returnValue('translated string 1337'));
142
		$this->logger->expects($this->once())
143
			->method('debug')
144
			->with($this->equalTo('Exception Message foo bar 42'));
145
146
		$actual = $this->controller->proxy($testUrl);
147
148
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
149
		$this->assertEquals('422', $actual->getStatus());
150
		$this->assertEquals([
151
			'message' => 'translated string 1337',
152
			'proxy_code' => -1
153
		], $actual->getData());
154
	}
155
156
	public function testProxyRequestException() {
157
		$testUrl = 'http://abc.def/foobar?123';
@@ 156-185 (lines=30) @@
153
		], $actual->getData());
154
	}
155
156
	public function testProxyRequestException() {
157
		$testUrl = 'http://abc.def/foobar?123';
158
159
		$this->client->expects($this->once())
160
			->method('newClient')
161
			->will($this->returnValue($this->newClient));
162
		$this->newClient->expects($this->once())
163
			->method('get')
164
			->with($testUrl, [
165
				'stream' => true,
166
			])
167
			->will($this->throwException(new RequestException('Exception Message foo bar 42',
168
				$this->exceptionRequest, $this->exceptionResponse)));
169
		$this->l10n->expects($this->once())
170
			->method('t')
171
			->with($this->equalTo('Error requesting resource on remote server'))
172
			->will($this->returnValue('translated string 1337'));
173
		$this->logger->expects($this->once())
174
			->method('debug')
175
			->with($this->equalTo('Exception Message foo bar 42'));
176
177
		$actual = $this->controller->proxy($testUrl);
178
179
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
180
		$this->assertEquals('422', $actual->getStatus());
181
		$this->assertEquals([
182
			'message' => 'translated string 1337',
183
			'proxy_code' => -2
184
		], $actual->getData());
185
	}
186
}
187