Skip to content

Commit cccbe8a

Browse files
committed
update some tests for PHP 8.1 behavior changes
- update functions return type - PHP 8.1 compatible, whoever where this library return false for some access issues, 8.1 will throw errors/exceptions instead
1 parent 5eb0468 commit cccbe8a

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

lib/ezFunctions.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace ezsql\functions;
66

7+
use ezsql\Db;
78
use ezsql\ezQuery;
89
use ezsql\ezSchema;
910
use ezsql\Database;
1011
use ezsql\ezQueryInterface;
1112
use ezsql\DatabaseInterface;
12-
use ezsql\Db;
1313
use ezsql\ezsqlModelInterface;
1414

1515
if (!\function_exists('ezFunctions')) {
@@ -244,7 +244,7 @@ function changingColumn(string $columnName, ...$datatype)
244244
*
245245
* @return array
246246
*/
247-
function eq($x, $y, $and = null, ...$args)
247+
function eq($x, $y, $and = null, ...$args): array
248248
{
249249
$expression = array();
250250
\array_push($expression, $x, \EQ, $y, $and, ...$args);
@@ -270,7 +270,7 @@ function eq($x, $y, $and = null, ...$args)
270270
*
271271
* @return array
272272
*/
273-
function neq($x, $y, $and = null, ...$args)
273+
function neq($x, $y, $and = null, ...$args): array
274274
{
275275
$expression = array();
276276
\array_push($expression, $x, \NEQ, $y, $and, ...$args);
@@ -287,7 +287,7 @@ function neq($x, $y, $and = null, ...$args)
287287
*
288288
* @return array
289289
*/
290-
function ne($x, $y, $and = null, ...$args)
290+
function ne($x, $y, $and = null, ...$args): array
291291
{
292292
$expression = array();
293293
\array_push($expression, $x, \NE, $y, $and, ...$args);
@@ -304,7 +304,7 @@ function ne($x, $y, $and = null, ...$args)
304304
*
305305
* @return array
306306
*/
307-
function lt($x, $y, $and = null, ...$args)
307+
function lt($x, $y, $and = null, ...$args): array
308308
{
309309
$expression = array();
310310
\array_push($expression, $x, \LT, $y, $and, ...$args);
@@ -321,7 +321,7 @@ function lt($x, $y, $and = null, ...$args)
321321
*
322322
* @return array
323323
*/
324-
function lte($x, $y, $and = null, ...$args)
324+
function lte($x, $y, $and = null, ...$args): array
325325
{
326326
$expression = array();
327327
\array_push($expression, $x, \LTE, $y, $and, ...$args);
@@ -338,7 +338,7 @@ function lte($x, $y, $and = null, ...$args)
338338
*
339339
* @return array
340340
*/
341-
function gt($x, $y, $and = null, ...$args)
341+
function gt($x, $y, $and = null, ...$args): array
342342
{
343343
$expression = array();
344344
\array_push($expression, $x, \GT, $y, $and, ...$args);
@@ -355,7 +355,7 @@ function gt($x, $y, $and = null, ...$args)
355355
*
356356
* @return array
357357
*/
358-
function gte($x, $y, $and = null, ...$args)
358+
function gte($x, $y, $and = null, ...$args): array
359359
{
360360
$expression = array();
361361
\array_push($expression, $x, \GTE, $y, $and, ...$args);
@@ -372,7 +372,7 @@ function gte($x, $y, $and = null, ...$args)
372372
*
373373
* @return array
374374
*/
375-
function isNull($x, $y = 'null', $and = null, ...$args)
375+
function isNull($x, $y = 'null', $and = null, ...$args): array
376376
{
377377
$expression = array();
378378
\array_push($expression, $x, \_isNULL, $y, $and, ...$args);
@@ -389,7 +389,7 @@ function isNull($x, $y = 'null', $and = null, ...$args)
389389
*
390390
* @return array
391391
*/
392-
function isNotNull($x, $y = 'null', $and = null, ...$args)
392+
function isNotNull($x, $y = 'null', $and = null, ...$args): array
393393
{
394394
$expression = array();
395395
\array_push($expression, $x, \_notNULL, $y, $and, ...$args);
@@ -406,7 +406,7 @@ function isNotNull($x, $y = 'null', $and = null, ...$args)
406406
*
407407
* @return array
408408
*/
409-
function like($x, $y, $and = null, ...$args)
409+
function like($x, $y, $and = null, ...$args): array
410410
{
411411
$expression = array();
412412
\array_push($expression, $x, \_LIKE, $y, $and, ...$args);
@@ -423,7 +423,7 @@ function like($x, $y, $and = null, ...$args)
423423
*
424424
* @return array
425425
*/
426-
function notLike($x, $y, $and = null, ...$args)
426+
function notLike($x, $y, $and = null, ...$args): array
427427
{
428428
$expression = array();
429429
\array_push($expression, $x, \_notLIKE, $y, $and, ...$args);
@@ -440,7 +440,7 @@ function notLike($x, $y, $and = null, ...$args)
440440
*
441441
* @return array
442442
*/
443-
function in($x, $y, ...$args)
443+
function in($x, $y, ...$args): array
444444
{
445445
$expression = array();
446446
\array_push($expression, $x, \_IN, $y, ...$args);
@@ -457,7 +457,7 @@ function in($x, $y, ...$args)
457457
*
458458
* @return array
459459
*/
460-
function notIn($x, $y, ...$args)
460+
function notIn($x, $y, ...$args): array
461461
{
462462
$expression = array();
463463
\array_push($expression, $x, \_notIN, $y, ...$args);
@@ -474,7 +474,7 @@ function notIn($x, $y, ...$args)
474474
*
475475
* @return array
476476
*/
477-
function between($x, $y, $y2, ...$args)
477+
function between($x, $y, $y2, ...$args): array
478478
{
479479
$expression = array();
480480
\array_push($expression, $x, \_BETWEEN, $y, $y2, \_AND, ...$args);
@@ -491,7 +491,7 @@ function between($x, $y, $y2, ...$args)
491491
*
492492
* @return array
493493
*/
494-
function notBetween($x, $y, $y2, ...$args)
494+
function notBetween($x, $y, $y2, ...$args): array
495495
{
496496
$expression = array();
497497
\array_push($expression, $x, \_notBETWEEN, $y, $y2, \_AND, ...$args);
@@ -540,7 +540,7 @@ function get_results($output = \OBJECT, $instance = null)
540540
*
541541
* @return string cleaned string
542542
*/
543-
function clean_string(string $string)
543+
function clean_string(string $string): string
544544
{
545545
$patterns = array( // strip out:
546546
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
@@ -563,7 +563,7 @@ function clean_string(string $string)
563563
* @param string $filename will be preprocess with `sanitize_path()`
564564
* @return boolean
565565
*/
566-
function is_traversal(string $basePath, string $filename)
566+
function is_traversal(string $basePath, string $filename): bool
567567
{
568568
if (\strpos(\urldecode($filename), '..') !== false)
569569
return true;
@@ -588,7 +588,7 @@ function is_traversal(string $basePath, string $filename)
588588
* @param string $path original file/path to be sanitized.
589589
* @return string
590590
*/
591-
function sanitize_path(string $path)
591+
function sanitize_path(string $path): string
592592
{
593593
$file = \preg_replace("/\.[\.]+/", "", $path);
594594
$file = \preg_replace("/^[\/]+/", "", $file);

tests/ezFunctionsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ protected function setUp(): void
6464

6565
public function testClean_string()
6666
{
67-
$this->assertEquals("' help", clean_string("<?php echo 'foo' >' help</php?>"));
67+
if ((float) \phpversion() >= 8.1)
68+
$this->assertEquals("&#039; help", clean_string("<?php echo 'foo' >' help</php?>"));
69+
else
70+
$this->assertEquals("' help", clean_string("<?php echo 'foo' >' help</php?>"));
6871
}
6972

7073
public function testSanitize_path()

tests/mysqli/mysqliTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ public function testConnect()
9999
$this->errors = array();
100100
set_error_handler(array($this, 'errorHandler'));
101101

102-
$this->assertFalse($this->object->connect('no', ''));
102+
if ((float) \phpversion() >= 8.1) {
103+
$this->expectException(\mysqli_sql_exception::class);
104+
$this->assertFalse($this->object->connect('no', ''));
105+
} else
106+
$this->assertFalse($this->object->connect('no', ''));
107+
103108
$this->assertFalse($this->object->connect('self::TEST_DB_USER', 'self::TEST_DB_PASSWORD', ' self::TEST_DB_HOST', 'self::TEST_DB_PORT'));
104109
$result = $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD);
105110

@@ -284,8 +289,17 @@ public function testCreatingReplacing()
284289
{
285290
$this->object->quick_connect();
286291
$this->object->prepareOff();
287-
$this->assertFalse($this->object->replacing([]));
288-
$this->assertFalse($this->object->creating([]));
292+
if ((float) \phpversion() >= 8.1) {
293+
$this->expectException(\mysqli_sql_exception::class);
294+
$this->assertFalse($this->object->replacing([]));
295+
} else
296+
$this->assertFalse($this->object->replacing([]));
297+
298+
if ((float) \phpversion() >= 8.1) {
299+
$this->expectException(\mysqli_sql_exception::class);
300+
$this->assertFalse($this->object->creating([]));
301+
} else
302+
$this->assertFalse($this->object->creating([]));
289303

290304
set_table('unit_test');
291305
$this->assertEquals(

0 commit comments

Comments
 (0)