This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-13
lines changed
src/ZendDiagnostics/Check
tests/ZendDiagnosticsTest Expand file tree Collapse file tree 2 files changed +27
-13
lines changed Original file line number Diff line number Diff line change 55
66namespace ZendDiagnostics \Check ;
77
8- use Predis \Client ;
9- use ZendDiagnostics \ Result \ Failure ;
8+ use Predis \Client as PredisClient ;
9+ use Redis as RedisExtensionClient ;
1010use ZendDiagnostics \Result \Success ;
1111
1212/**
@@ -38,21 +38,35 @@ public function __construct($host = 'localhost', $port = 6379)
3838 * Perform the check
3939 *
4040 * @see \ZendDiagnostics\Check\CheckInterface::check()
41- * @return Failure|Success
4241 */
4342 public function check ()
4443 {
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 );
4859
49- $ client = new Client (array (
50- 'host ' => $ this ->host ,
51- 'port ' => $ this ->port ,
52- ));
60+ return $ client ;
61+ }
5362
54- $ client ->ping ();
63+ if (class_exists ('Predis\Client ' )) {
64+ return new PredisClient (array (
65+ 'host ' => $ this ->host ,
66+ 'port ' => $ this ->port ,
67+ ));
68+ }
5569
56- return new Success ( );
70+ throw new \ RuntimeException ( ' Neither the PHP Redis extension or Predis are installed ' );
5771 }
5872}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public function testRedis()
6363 $ this ->assertInstanceOf ('ZendDiagnostics\Result\Success ' , $ result );
6464
6565 $ check = new Redis ('127.0.0.250 ' , 9999 );
66- $ this ->setExpectedException ('Predis\Connection\ConnectionException ' );
66+ $ this ->setExpectedException ('\Exception ' );
6767 $ check ->check ();
6868 }
6969
You can’t perform that action at this time.
0 commit comments