This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree 2 files changed +27
-13
lines changed
src/ZendDiagnostics/Check
tests/ZendDiagnosticsTest
2 files changed +27
-13
lines changed Original file line number Diff line number Diff line change 5
5
6
6
namespace ZendDiagnostics \Check ;
7
7
8
- use Predis \Client ;
9
- use ZendDiagnostics \ Result \ Failure ;
8
+ use Predis \Client as PredisClient ;
9
+ use Redis as RedisExtensionClient ;
10
10
use ZendDiagnostics \Result \Success ;
11
11
12
12
/**
@@ -38,21 +38,35 @@ public function __construct($host = 'localhost', $port = 6379)
38
38
* Perform the check
39
39
*
40
40
* @see \ZendDiagnostics\Check\CheckInterface::check()
41
- * @return Failure|Success
42
41
*/
43
42
public function check ()
44
43
{
45
- if (!class_exists ('Predis\Client ' )) {
46
- return new Failure ('Predis is not installed ' );
47
- }
44
+ $ this ->createClient ()->ping ();
45
+
46
+ return new Success ();
47
+ }
48
+
49
+ /**
50
+ * @return PredisClient|RedisExtensionClient
51
+ *
52
+ * @throws \RuntimeException
53
+ */
54
+ private function createClient ()
55
+ {
56
+ if (class_exists ('\Redis ' )) {
57
+ $ client = new RedisExtensionClient ();
58
+ $ client ->connect ($ this ->host );
48
59
49
- $ client = new Client (array (
50
- 'host ' => $ this ->host ,
51
- 'port ' => $ this ->port ,
52
- ));
60
+ return $ client ;
61
+ }
53
62
54
- $ client ->ping ();
63
+ if (class_exists ('Predis\Client ' )) {
64
+ return new PredisClient (array (
65
+ 'host ' => $ this ->host ,
66
+ 'port ' => $ this ->port ,
67
+ ));
68
+ }
55
69
56
- return new Success ( );
70
+ throw new \ RuntimeException ( ' Neither the PHP Redis extension or Predis are installed ' );
57
71
}
58
72
}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public function testRedis()
63
63
$ this ->assertInstanceOf ('ZendDiagnostics\Result\Success ' , $ result );
64
64
65
65
$ check = new Redis ('127.0.0.250 ' , 9999 );
66
- $ this ->setExpectedException ('Predis\Connection\ConnectionException ' );
66
+ $ this ->setExpectedException ('\Exception ' );
67
67
$ check ->check ();
68
68
}
69
69
You can’t perform that action at this time.
0 commit comments