Skip to content

Commit 486dc6f

Browse files
committed
Added tests
And some TODOS
1 parent 89cc404 commit 486dc6f

File tree

3 files changed

+575
-14
lines changed

3 files changed

+575
-14
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ php:
44
- 5.3
55
- 5.4
66
- 5.5
7+
- 5.6
78

89
env:
910
global:
1011
- REPO_NAME=cakephp-redis
1112
- PLUGIN_NAME=Redis
1213
- REQUIRE=""
13-
- DB=mysql CAKE_VERSION=master
14+
- DB=redis CAKE_VERSION=master
1415

1516
matrix:
16-
- DB=mysql CAKE_VERSION=2.3
17-
- DB=mysql CAKE_VERSION=2.4
18-
- DB=mysql CAKE_VERSION=2.5
17+
- DB=redis CAKE_VERSION=2.3
18+
- DB=redis CAKE_VERSION=2.4
19+
- DB=redis CAKE_VERSION=2.5
1920

2021
matrix:
2122
include:

Model/Datasource/RedisSource.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class RedisSource extends DataSource {
5151
*/
5252
public $connected = false;
5353

54+
/**
55+
* Whether or not source data like available tables and schema descriptions should be cached.
56+
*
57+
* @var bool
58+
*/
59+
public $cacheSources = false;
60+
5461
/**
5562
* Constructor.
5663
*
@@ -64,6 +71,8 @@ public function __construct($config = array()) {
6471
return false;
6572
}
6673

74+
$this->_connection = new Redis();
75+
6776
return $this->connect();
6877
}
6978

@@ -73,6 +82,7 @@ public function __construct($config = array()) {
7382
* Closes the connection to the host (if needed).
7483
*
7584
* @return void
85+
* @todo Write test
7686
*/
7787
public function __destruct() {
7888
if (!$this->config['persistent']) {
@@ -86,8 +96,13 @@ public function __destruct() {
8696
* @param string $name The name of the method being called
8797
* @param array $arguments An enumerated array containing the parameters passed to the method
8898
* @return mixed Method return value
99+
* @todo Throw exception(s)
89100
*/
90101
public function __call($name, $arguments) {
102+
if (!method_exists($this->_connection, $name)) {
103+
return false;
104+
}
105+
91106
return call_user_func_array(array($this->_connection, $name), $arguments);
92107
}
93108

@@ -115,7 +130,7 @@ public function connect() {
115130
$this->connected = $this->_connect();
116131
$this->connected = $this->connected && $this->_authenticate();
117132
$this->connected = $this->connected && $this->_select();
118-
$this->connected = $this->connected && !$this->_setPrefix();
133+
$this->connected = $this->connected && $this->_setPrefix();
119134

120135
return $this->connected;
121136
}
@@ -126,9 +141,8 @@ public function connect() {
126141
* @return bool True if connecting to the DataSource succeeds, else false
127142
*/
128143
protected function _connect() {
144+
// TODO: Remove useless try / catch?
129145
try {
130-
$this->_connection = new Redis();
131-
132146
if ($this->config['unix_socket']) {
133147
return $this->_connection->connect($this->config['unix_socket']);
134148
} elseif (!$this->config['persistent']) {
@@ -192,6 +206,7 @@ protected function _setPrefix() {
192206
* @return bool Always true
193207
*/
194208
public function close() {
209+
// TODO: Remove useless condition
195210
if ($this->isConnected()) {
196211
$this->_connection->close();
197212
}
@@ -216,19 +231,21 @@ public function isConnected() {
216231
*
217232
* @param mixed $data List of tables
218233
* @return array Array of sources available in this datasource
234+
* @todo: Remove useless method?
219235
*/
220236
public function listSources($data = null) {
221-
return null;
237+
return parent::listSources($data);
222238
}
223239

224240
/**
225241
* Returns a Model description (metadata) or null if none found.
226242
*
227243
* @param Model|string $model Name of database table to inspect or model instance
228244
* @return array Array of Metadata for the $model
245+
* @todo: Remove useless method?
229246
*/
230247
public function describe($model) {
231-
return null;
248+
return parent::describe($model);
232249
}
233250

234251
/**
@@ -238,6 +255,7 @@ public function describe($model) {
238255
* @param string $func Lowercase name of SQL function, i.e. 'count' or 'max'
239256
* @param array $params Function parameters (any values must be quoted manually)
240257
* @return string An SQL calculation function
258+
* @todo Remove useless method?
241259
*/
242260
public function calculate(Model $Model, $func, $params = array()) {
243261
return array('count' => true);

0 commit comments

Comments
 (0)