This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace FwlibTest\Bridge; |
||
3 | |||
4 | use Fwlib\Bridge\Adodb; |
||
5 | use Fwlib\Config\GlobalConfig; |
||
6 | use Fwlib\Db\SqlGenerator; |
||
7 | use Fwlib\Test\AbstractDbRelateTest; |
||
8 | use Fwlib\Util\UtilContainerAwareTrait; |
||
9 | |||
10 | /** |
||
11 | * @copyright Copyright 2013-2015, 2017 Fwolf |
||
12 | * @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
||
13 | */ |
||
14 | class AdodbMysqlTest extends AbstractDbRelateTest |
||
15 | { |
||
16 | use UtilContainerAwareTrait; |
||
17 | |||
18 | |||
19 | protected static $dbUsing = 'mysql'; |
||
20 | |||
21 | |||
22 | public function generateUuid() |
||
23 | { |
||
24 | return $this->getUtilContainer()->getUuidBase16()->generate(); |
||
25 | } |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Notice: Parameter type in adodb::SetFetchMode() is wrong, version 5.07 |
||
30 | * - 5.19 |
||
31 | */ |
||
32 | public function testCall() |
||
33 | { |
||
34 | /** @var \ADOConnection $dbMysql */ |
||
35 | $dbMysql = self::$dbMysql; |
||
36 | |||
37 | $fetchMode = $dbMysql->fetchMode; |
||
38 | $dbMysql->setFetchMode(3); // Both |
||
39 | |||
40 | $ar = $dbMysql->GetAll('SELECT 1 AS a'); |
||
41 | $y = [['1', 'a' => '1']]; |
||
42 | $this->assertEqualArray($y, $ar); |
||
43 | |||
44 | $ar = $dbMysql->CacheGetAll(1, 'SELECT 1 AS a'); |
||
45 | $y = [['1', 'a' => '1']]; |
||
46 | $this->assertEqualArray($y, $ar); |
||
47 | |||
48 | $dbMysql->setFetchMode($fetchMode); |
||
49 | } |
||
50 | |||
51 | |||
52 | public function testConstruct() |
||
53 | { |
||
54 | $profile = GlobalConfig::getInstance()->get('dbserver.mysql'); |
||
55 | $db = new Adodb($profile); |
||
56 | |||
57 | $this->assertEqualArray($profile, $db->getProfile()); |
||
58 | |||
59 | // SqlGenerator is not instanced now, see testGenerateSql() |
||
60 | $this->assertNull($this->reflectionGet($db, 'sqlGenerator')); |
||
61 | } |
||
62 | |||
63 | |||
64 | public function testConnect() |
||
65 | { |
||
66 | // Clone doesn't affect property object conn |
||
67 | //$conn = clone self::$dbMysql; |
||
68 | |||
69 | // Check connection is reused |
||
70 | $y = self::$dbMysql->_connectionID->thread_id; |
||
0 ignored issues
–
show
|
|||
71 | self::$dbMysql->connect(false); |
||
72 | $x = self::$dbMysql->_connectionID->thread_id; |
||
0 ignored issues
–
show
The property
_connectionID does not exist on object<Fwlib\Bridge\Adodb> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
73 | $this->assertEquals($y, $x); |
||
74 | |||
75 | // Force re-connect |
||
76 | self::$dbMysql->connect(true); |
||
77 | $x = self::$dbMysql->_connectionID->thread_id; |
||
0 ignored issues
–
show
The property
_connectionID does not exist on object<Fwlib\Bridge\Adodb> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
78 | $this->assertNotEquals($y, $x); |
||
79 | } |
||
80 | |||
81 | |||
82 | View Code Duplication | public function testConvertEncodingResult() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
83 | { |
||
84 | // Backup original charset |
||
85 | $originalCharsetPhp = self::$dbMysql->charsetPhp; |
||
86 | $originalCharsetDb = self::$dbMysql->profile['lang']; |
||
87 | |||
88 | self::$dbMysql->setCharsetPhp('UTF-8'); |
||
89 | self::$dbMysql->profile['lang'] = 'GB2312'; |
||
90 | |||
91 | $x = [null, 'ä½ å¥½']; |
||
92 | $y = [null, mb_convert_encoding('ä½ å¥½', 'UTF-8', 'GB2312')]; |
||
93 | $this->assertEquals( |
||
94 | $y, |
||
95 | self::$dbMysql->convertEncodingResult($x) |
||
96 | ); |
||
97 | |||
98 | |||
99 | // Recover original charset |
||
100 | self::$dbMysql->setCharsetPhp($originalCharsetPhp); |
||
101 | self::$dbMysql->profile['lang'] = $originalCharsetDb; |
||
102 | } |
||
103 | |||
104 | |||
105 | View Code Duplication | public function testConvertEncodingSql() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
106 | { |
||
107 | // Backup original charset |
||
108 | $originalCharsetPhp = self::$dbMysql->charsetPhp; |
||
109 | $originalCharsetDb = self::$dbMysql->profile['lang']; |
||
110 | |||
111 | self::$dbMysql->setCharsetPhp('UTF-8'); |
||
112 | self::$dbMysql->profile['lang'] = 'GB2312'; |
||
113 | |||
114 | $x = [null, 'ä½ å¥½']; |
||
115 | $y = [null, mb_convert_encoding('ä½ å¥½', 'GB2312', 'UTF-8')]; |
||
116 | $this->assertEquals( |
||
117 | $y, |
||
118 | self::$dbMysql->convertEncodingSql($x) |
||
119 | ); |
||
120 | |||
121 | |||
122 | // Recover original charset |
||
123 | self::$dbMysql->setCharsetPhp($originalCharsetPhp); |
||
124 | self::$dbMysql->profile['lang'] = $originalCharsetDb; |
||
125 | } |
||
126 | |||
127 | |||
128 | /** |
||
129 | * @expectedException \PHPUnit_Framework_Error |
||
130 | */ |
||
131 | public function testDeleteRow() |
||
132 | { |
||
133 | $i = self::$dbMysql->deleteRow(self::$tableUser, ''); |
||
134 | $this->assertEquals(-1, $i); |
||
135 | |||
136 | $i = self::$dbMysql->deleteRow( |
||
137 | self::$tableUser, |
||
138 | 'WHERE FALSE' |
||
139 | ); |
||
140 | $this->assertEquals(0, $i); |
||
141 | |||
142 | // When use executePrepare(), error was detected and rollback, so |
||
143 | // return 0 instead of -1, throw exception. |
||
144 | self::$dbMysql->deleteRow( |
||
145 | self::$tableUser, |
||
146 | 'WHERE ERROR_CLAUSE' |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | |||
151 | public function testError() |
||
152 | { |
||
153 | self::$dbMysql->execute('SELECT 1'); |
||
154 | $this->assertEquals('', self::$dbMysql->getErrorMessage()); |
||
155 | $this->assertEquals('', self::$dbMysql->errorMsg()); |
||
156 | $this->assertEquals(0, self::$dbMysql->getErrorCode()); |
||
157 | $this->assertEquals(0, self::$dbMysql->errorNo()); |
||
158 | } |
||
159 | |||
160 | |||
161 | public function testExecute() |
||
162 | { |
||
163 | self::$dbMysql->execute( |
||
164 | [ |
||
165 | 'SELECT' => 'uuid', |
||
166 | 'FROM' => self::$tableUser, |
||
167 | 'LIMIT' => 1 |
||
168 | ] |
||
169 | ); |
||
170 | $this->assertEquals(0, self::$dbMysql->getErrorCode()); |
||
171 | } |
||
172 | |||
173 | |||
174 | /** |
||
175 | * @expectedException \PHPUnit_Framework_Error |
||
176 | */ |
||
177 | public function testExecutePrepare() |
||
178 | { |
||
179 | self::$dbMysql->executePrepare( |
||
180 | [ |
||
0 ignored issues
–
show
array('SELECT' => 'uuid'...ableUser, 'LIMIT' => 1) is of type array<string,string|inte...ng","LIMIT":"integer"}> , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
181 | 'SELECT' => 'uuid', |
||
182 | 'FROM' => self::$tableUser, |
||
183 | 'LIMIT' => 1 |
||
184 | ] |
||
185 | ); |
||
186 | $this->assertEquals(0, self::$dbMysql->getErrorCode()); |
||
187 | |||
188 | self::$dbMysql->executePrepare( |
||
189 | [ |
||
0 ignored issues
–
show
array('SELECT' => 'uuid'...ERE' => 'Error Clause') is of type array<string,string,{"SE...ing","WHERE":"string"}> , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
190 | 'SELECT' => 'uuid', |
||
191 | 'FROM' => self::$tableUser, |
||
192 | 'WHERE' => 'Error Clause', |
||
193 | ] |
||
194 | ); |
||
195 | } |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Test for Mysql db only |
||
200 | */ |
||
201 | public function testForMysqlOnly() |
||
202 | { |
||
203 | if (!self::$dbMysql->isDbMysql()) { |
||
204 | $this->markTestSkipped('Skip mysql only test.'); |
||
205 | } |
||
206 | |||
207 | $this->assertEquals( |
||
208 | ";\n", |
||
209 | self::$dbMysql->getSqlDelimiter() |
||
210 | ); |
||
211 | |||
212 | $this->assertEquals( |
||
213 | false, |
||
214 | self::$dbMysql->isTimestampUnique() |
||
215 | ); |
||
216 | } |
||
217 | |||
218 | |||
219 | public function testGenerateSql() |
||
220 | { |
||
221 | $userTable = self::$tableUser; |
||
222 | |||
223 | $x = self::$dbMysql->generateSql(''); |
||
0 ignored issues
–
show
'' is of type string , but the function expects a array .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
224 | $this->assertEquals('', $x); |
||
225 | |||
226 | |||
227 | // SqlGenerator is instanced now |
||
228 | $this->assertInstanceOf( |
||
229 | SqlGenerator::class, |
||
230 | $this->reflectionGet(self::$dbMysql, 'sqlGenerator') |
||
231 | ); |
||
232 | |||
233 | |||
234 | $ar = [ |
||
235 | 'SELECT' => 'title', |
||
236 | 'FROM' => $userTable, |
||
237 | ]; |
||
238 | $x = self::$dbMysql->generateSql($ar); |
||
239 | $y = "SELECT title FROM $userTable"; |
||
240 | $this->assertEquals($y, $x); |
||
241 | } |
||
242 | |||
243 | |||
244 | public function testGenerateSqlPrepared() |
||
245 | { |
||
246 | $userTable = self::$tableUser; |
||
247 | |||
248 | $x = self::$dbMysql->generateSqlPrepared(''); |
||
0 ignored issues
–
show
'' is of type string , but the function expects a array .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
249 | $this->assertEquals('', $x); |
||
250 | |||
251 | $ar = [ |
||
252 | 'INSERT' => self::$tableUser, |
||
253 | 'VALUES' => [ |
||
254 | 'uuid' => self::$dbMysql->param('uuid'), |
||
255 | 'title' => self::$dbMysql->param('title'), |
||
256 | 'age' => self::$dbMysql->param('age'), |
||
257 | ], |
||
258 | ]; |
||
259 | $x = self::$dbMysql->generateSqlPrepared($ar); |
||
260 | $y = "INSERT INTO $userTable(uuid, title, age) VALUES (?, ?, ?)"; |
||
261 | $this->assertEquals($y, $x); |
||
262 | } |
||
263 | |||
264 | |||
265 | /** |
||
266 | * @expectedException \PHPUnit_Framework_Error_Warning |
||
267 | */ |
||
268 | public function testGetByKey() |
||
269 | { |
||
270 | // Normal getByKey() tested with write() |
||
271 | |||
272 | // Prepare data |
||
273 | $uuid = $this->generateUuid(); |
||
274 | $ar = [ |
||
275 | 'uuid' => $uuid, |
||
276 | 'title' => 'Title', |
||
277 | 'age' => 42, |
||
278 | ]; |
||
279 | self::$dbMysql->write(self::$tableUser, $ar); |
||
280 | |||
281 | |||
282 | // Different way to read one column |
||
283 | $this->assertEquals( |
||
284 | 'Title', |
||
285 | self::$dbMysql->getByKey(self::$tableUser, $uuid, 'title') |
||
286 | ); |
||
287 | $this->assertEquals( |
||
288 | 'Title', |
||
289 | self::$dbMysql->getByKey(self::$tableUser, $uuid, 'title', 'uuid') |
||
290 | ); |
||
291 | $this->assertEquals( |
||
292 | 'Title', |
||
293 | self::$dbMysql->getByKey( |
||
294 | self::$tableUser, |
||
295 | [$uuid], |
||
0 ignored issues
–
show
array($uuid) is of type array<integer,string,{"0":"string"}> , but the function expects a integer|string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
296 | 'title', |
||
297 | ['uuid'] |
||
298 | ) |
||
299 | ); |
||
300 | |||
301 | // Read more than one column |
||
302 | $this->assertEqualArray( |
||
303 | ['title' => 'Title', 'age' => '42'], |
||
304 | self::$dbMysql->getByKey(self::$tableUser, $uuid, 'title, age') |
||
305 | ); |
||
306 | |||
307 | // * col |
||
308 | $data = self::$dbMysql->getByKey(self::$tableUser, $uuid); |
||
309 | $this->assertEquals('Title', $data['title']); |
||
310 | $this->assertEquals(42, $data['age']); |
||
311 | |||
312 | // Not exists data |
||
313 | $data = self::$dbMysql->getByKey(self::$tableUser, $uuid . 'foo'); |
||
314 | $this->assertEquals(null, $data); |
||
315 | |||
316 | // More PK value than column, throw exception |
||
317 | $this->assertEquals( |
||
318 | null, |
||
319 | self::$dbMysql->getByKey(self::$tableUser, [1, 2], 'title') |
||
0 ignored issues
–
show
array(1, 2) is of type array<integer,integer,{"...nteger","1":"integer"}> , but the function expects a integer|string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
320 | ); |
||
321 | } |
||
322 | |||
323 | |||
324 | public function testGetMetaPrimaryKey() |
||
325 | { |
||
326 | // Normal test completed by other method |
||
327 | |||
328 | $this->assertEquals( |
||
329 | null, |
||
330 | self::$dbMysql->getMetaPrimaryKey(self::$tableUser . '_not_exists') |
||
331 | ); |
||
332 | } |
||
333 | |||
334 | |||
335 | public function testGetMetaTimestamp() |
||
336 | { |
||
337 | $this->assertEquals( |
||
338 | '', |
||
339 | self::$dbMysql->getMetaTimeStamp(self::$tableUser . '_not_exists') |
||
340 | ); |
||
341 | |||
342 | $this->assertEquals( |
||
343 | '', |
||
344 | self::$dbMysql->getMetaTimeStamp(self::$tableGroup) |
||
345 | ); |
||
346 | } |
||
347 | |||
348 | |||
349 | public function testGetProfileString() |
||
350 | { |
||
351 | $profileString = self::$dbMysql->getProfileString('-'); |
||
352 | $this->assertEquals(2, substr_count($profileString, '-')); |
||
353 | } |
||
354 | |||
355 | |||
356 | public function testGetQueryCount() |
||
357 | { |
||
358 | /** @var \ADOConnection|\Fwlib\Bridge\Adodb $db */ |
||
359 | $db = self::$dbMysql; |
||
360 | $i = $db->getQueryCount(); |
||
361 | |||
362 | $db->GetAll('SELECT 1 AS a'); |
||
0 ignored issues
–
show
The method
GetAll does not exist on object<Fwlib\Bridge\Adodb> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
363 | $this->assertEquals($i + 1, $db->getQueryCount()); |
||
364 | |||
365 | $db->CacheGetAll(0, 'SELECT 1 AS a'); |
||
0 ignored issues
–
show
The method
CacheGetAll does not exist on object<Fwlib\Bridge\Adodb> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
366 | $this->assertEquals($i + 1, $db->getQueryCount()); |
||
367 | |||
368 | $db->GetAll('SELECT 1 AS a'); |
||
0 ignored issues
–
show
The method
GetAll does not exist on object<Fwlib\Bridge\Adodb> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
369 | $this->assertEquals($i + 2, $db->getQueryCount()); |
||
370 | } |
||
371 | |||
372 | |||
373 | public function testGetSet() |
||
374 | { |
||
375 | self::$dbMysql->debug = false; |
||
0 ignored issues
–
show
The property
debug does not exist on object<Fwlib\Bridge\Adodb> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
376 | $this->assertFalse(self::$dbMysql->debug); |
||
0 ignored issues
–
show
The property
debug does not exist on object<Fwlib\Bridge\Adodb> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
377 | } |
||
378 | |||
379 | |||
380 | public function testGetSqlTrans() |
||
381 | { |
||
382 | $this->assertEquals( |
||
383 | 'TRANSACTION', |
||
384 | substr(self::$dbMysql->getSqlTransBegin(), 6, 11) |
||
385 | ); |
||
386 | $this->assertStringStartsWith( |
||
387 | 'COMMIT', |
||
388 | self::$dbMysql->getSqlTransCommit() |
||
389 | ); |
||
390 | $this->assertStringStartsWith( |
||
391 | 'ROLLBACK', |
||
392 | self::$dbMysql->getSqlTransRollback() |
||
393 | ); |
||
394 | } |
||
395 | |||
396 | |||
397 | public function testIsTblExist() |
||
398 | { |
||
399 | $this->assertTrue(self::$dbMysql->isTableExist(self::$tableUser)); |
||
400 | $this->assertFalse( |
||
401 | self::$dbMysql->isTableExist(self::$tableUser . '_not_exists') |
||
402 | ); |
||
403 | } |
||
404 | |||
405 | |||
406 | /** |
||
407 | * @expectedException \PHPUnit_Framework_Error_Warning |
||
408 | */ |
||
409 | public function testQuoteValue() |
||
410 | { |
||
411 | // Normal test completed by other method |
||
412 | |||
413 | // Quote un-exists column |
||
414 | // Compare will not execute because exception will be caught by PHPUnit |
||
415 | $col = 'not_exists'; |
||
416 | $this->assertEquals( |
||
417 | '\'' . $col . '\'', |
||
418 | self::$dbMysql->quoteValue(self::$tableUser, $col, $col) |
||
419 | ); |
||
420 | } |
||
421 | |||
422 | |||
423 | /** |
||
424 | * @expectedException \PHPUnit_Framework_Error_Warning |
||
425 | */ |
||
426 | public function testWrite() |
||
427 | { |
||
428 | $uuid = $this->generateUuid(); |
||
429 | |||
430 | // Auto INSERT |
||
431 | $ar = [ |
||
432 | 'uuid' => $uuid, |
||
433 | 'title' => 'Title', |
||
434 | 'age' => 42, |
||
435 | ]; |
||
436 | self::$dbMysql->write(self::$tableUser, $ar); |
||
437 | $this->assertEquals( |
||
438 | 'Title', |
||
439 | self::$dbMysql->getByKey(self::$tableUser, $uuid, 'title') |
||
440 | ); |
||
441 | |||
442 | // Auto UPDATE |
||
443 | $ar['age'] = 24; |
||
444 | self::$dbMysql->write(self::$tableUser, $ar); |
||
445 | $this->assertEquals( |
||
446 | 24, |
||
447 | self::$dbMysql->getByKey(self::$tableUser, $uuid, 'age') |
||
448 | ); |
||
449 | |||
450 | // Write without PK, will fail |
||
451 | unset($ar['uuid']); |
||
452 | $this->assertEquals( |
||
453 | -1, |
||
454 | self::$dbMysql->write(self::$tableUser, $ar) |
||
455 | ); |
||
456 | |||
457 | // For INSERT, will fail and throw exception |
||
458 | $ar['uuid'] = $uuid; |
||
459 | $this->assertEquals( |
||
460 | -1, |
||
461 | self::$dbMysql->write(self::$tableUser, $ar, 'I') |
||
462 | ); |
||
463 | } |
||
464 | } |
||
465 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.