Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 4be96cd

Browse files
committed
added tests for GuzzleHttpService
1 parent 166a359 commit 4be96cd

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"zendframework/zend-loader" : "2.*",
2222
"sensiolabs/security-checker": "1.3.*@dev",
2323
"symfony/yaml": "v2.3.11",
24-
"guzzle/http" : "3.*"
24+
"guzzle/http" : "3.*",
25+
"guzzle/plugin-mock" : "3.*"
2526
},
2627
"suggest" : {
2728
"ext-bcmath" : "Required by Check\\CpuPerformance",

src/ZendDiagnostics/Check/GuzzleHttpService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function check()
5252
return new Failure("Status code {$this->statusCode} does not match response from {$this->url}");
5353
}
5454

55-
if ($this->content && !strpos($response->getBody(true), $this->content)) {
55+
if ($this->content && (false === strpos($response->getBody(true), $this->content))) {
5656
return new Failure("Content {$this->content} not found in response from {$this->url}");
5757
}
5858

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace ZendDiagnosticsTest;
4+
5+
use Guzzle\Http\Client;
6+
use Guzzle\Http\Message\Response;
7+
use Guzzle\Plugin\Mock\MockPlugin;
8+
use ZendDiagnostics\Check\GuzzleHttpService;
9+
10+
class GuzzleHttpServiceTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @dataProvider checkProvider
14+
*/
15+
public function testCheck($content, $actualContent, $actualStatusCode, $resultClass)
16+
{
17+
$check = new GuzzleHttpService(
18+
'http://www.example.com/foobar',
19+
array(),
20+
array(),
21+
200,
22+
$content,
23+
$this->getMockClient($actualStatusCode, $actualContent)
24+
);
25+
$result = $check->check();
26+
27+
$this->assertInstanceOf($resultClass, $result);
28+
}
29+
30+
public function checkProvider()
31+
{
32+
return array(
33+
array(null, null, 200, 'ZendDiagnostics\Result\SuccessInterface'),
34+
array(null, null, 404, 'ZendDiagnostics\Result\FailureInterface'),
35+
array('foo', 'foobar', 200, 'ZendDiagnostics\Result\SuccessInterface'),
36+
array('baz', 'foobar', 200, 'ZendDiagnostics\Result\FailureInterface')
37+
);
38+
}
39+
40+
private function getMockClient($statusCode = 200, $content = null)
41+
{
42+
$plugin = new MockPlugin();
43+
$plugin->addResponse(new Response($statusCode, null, $content));
44+
45+
$client = new Client(null, array(
46+
'request.options' => array(
47+
'exceptions' => false
48+
)
49+
));
50+
$client->addSubscriber($plugin);
51+
52+
return $client;
53+
}
54+
}

0 commit comments

Comments
 (0)