Skip to content

Commit e08d96e

Browse files
committed
Fixed TODO of __call method
1 parent 868d429 commit e08d96e

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

Model/Datasource/RedisSource.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ public function __destruct() {
9696
* @param string $name The name of the method being called
9797
* @param array $arguments An enumerated array containing the parameters passed to the method
9898
* @return mixed Method return value
99-
* @todo Throw exception(s)
99+
* @throws RedisSourceException
100100
*/
101101
public function __call($name, $arguments) {
102102
if (!method_exists($this->_connection, $name)) {
103-
return false;
103+
throw new RedisSourceException(__d('redis', 'Method (%s) does not exist.', $name));
104104
}
105105

106-
return call_user_func_array(array($this->_connection, $name), $arguments);
106+
try {
107+
return call_user_func_array(array($this->_connection, $name), $arguments);
108+
} catch (RedisException $e) {
109+
throw new RedisSourceException(__d('redis', 'Method (%s) failed: %s.', $name, $e->getMessage()));
110+
}
107111
}
108112

109113
/**
@@ -257,3 +261,10 @@ public function calculate(Model $Model, $func, $params = array()) {
257261
}
258262

259263
}
264+
265+
/**
266+
* Redis Source Exception class.
267+
*
268+
*/
269+
class RedisSourceException extends CakeException {
270+
}

Test/Case/Model/Datasource/RedisSourceTest.php

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,60 @@ public function testConnectTcpPersistent() {
253253
}
254254

255255
/**
256-
* testCall method
256+
* testCallExisting method
257+
*
258+
* Tests calling of an existing (Redis) method on a connected / configured instance.
257259
*
258260
* @return void
259261
*/
260-
public function testCall() {
262+
public function testCallExisting() {
261263
$Source = new TestRedisSource();
262264

263-
//
264-
// Existing method
265-
//
266-
267265
$result = $Source->ping();
268266
$expected = '+PONG';
269267

270268
$this->assertIdentical($result, $expected);
269+
}
271270

272-
//
273-
// Non-existing method
274-
//
271+
/**
272+
* testCallNonExisting method
273+
*
274+
* Tests calling of an non-existing (Redis) method on a connected / configured instance.
275+
*
276+
* @return void
277+
* @expectedException RedisSourceException
278+
*/
279+
public function testCallNonExisting() {
280+
$Source = new TestRedisSource();
275281

276-
$result = $Source->pang();
282+
$Source->pang();
283+
}
277284

278-
$this->assertFalse($result);
285+
/**
286+
* testCallExistingFailure method
287+
*
288+
* Tests calling of an existing (Redis) method on a disconnected / misconfigured instance.
289+
*
290+
* @return void
291+
* @expectedException RedisSourceException
292+
*/
293+
public function testCallExistingFailure() {
294+
$unixSocket = '';
295+
$persistent = false;
296+
$host = '127.0.0.1';
297+
$port = 63790;
298+
$timeout = 0;
299+
300+
$config = array(
301+
'unix_socket' => $unixSocket,
302+
'persistent' => $persistent,
303+
'host' => $host,
304+
'port' => $port,
305+
'timeout' => $timeout,
306+
);
307+
308+
$Source = new TestRedisSource($config);
309+
$Source->ping();
279310
}
280311

281312
/**

0 commit comments

Comments
 (0)