diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index edcf3759..c444c550 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -12,12 +12,12 @@ on: jobs: linux: name: Linux (PHP ${{ matrix.php-versions }} CI) - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 strategy: fail-fast: false matrix: - operating-system: [ubuntu-latest] - php-versions: ['7.4', '8.0'] + operating-system: [ubuntu-18.04] + php-versions: ['7.4', '8.0', '8.1'] steps: - name: Checkout diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 155c46bf..6073157c 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -34,9 +34,10 @@ jobs: brew install mysql@5.7 - name: Brew Start MySQL run: | - brew services start mysql@5.7 brew link mysql@5.7 --force - mysqld --initialize-insecure + sudo rm -rf /usr/local/var/mysql + sudo rm /usr/local/etc/my.cnf + mysqld --initialize-insecure --explicit_defaults_for_timestamp mysql.server start - name: Setup MySQL Database run: | diff --git a/README.md b/README.md index d8c8aaf1..8afcb5ec 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ $db = Database::initialize('****', [$dsn_path_user, $password, $database, $other use ezsql\Config; use ezsql\Database\ez_****; -$setting = new Config('****', [$dsn_path_user, $password, $database, $other_settings]); +$settings = new Config('****', [$dsn_path_user, $password, $database, $other_settings]); $db = new ez_****($settings); ``` diff --git a/composer.json b/composer.json index d28eda0a..49262b9c 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "issues": "https://github.com/ezSQL/ezSQL/issues" }, "require": { - "php": "^7.1 || ^8", + "php": ">7.1", "psr/container": "^1.0" }, "provide": { @@ -55,7 +55,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^6 || ^7 || ^8" + "phpunit/phpunit": "^6 | ^7 | ^8" }, "autoload-dev": { "psr-4": { diff --git a/lib/Constants.php b/lib/Constants.php index 789a63e7..c24c1f3c 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -5,7 +5,7 @@ /** * ezsqlModel Constants */ - \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.1.1'); + \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.1.2'); \defined('OBJECT') or \define('OBJECT', 'OBJECT'); \defined('ARRAY_A') or \define('ARRAY_A', 'ARRAY_A'); \defined('ARRAY_N') or \define('ARRAY_N', 'ARRAY_N'); @@ -39,8 +39,8 @@ \define('_BETWEEN', 'BETWEEN'); \define('_notBETWEEN', 'NOT BETWEEN'); - \define('_isNULL', 'IS NULL'); - \define('_notNULL', 'IS NOT NULL'); + \define('_isNULL', 'IS'); + \define('_notNULL', 'IS NOT'); \define('_BOOLEAN_OPERATORS', [ '<', '>', '=', '!=', '>=', '<=', '<>', 'IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS', 'IS NOT' diff --git a/lib/Database.php b/lib/Database.php index 0b028739..4baf5e72 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -4,8 +4,8 @@ namespace ezsql; +use ezsql\Db; use ezsql\DInjector; -use function ezsql\functions\setInstance; class Database { @@ -15,9 +15,13 @@ class Database * @var float */ private static $_ts = null; - private static $factory = null; + + /** + * @var ezQueryInterface[] + */ private static $instances = []; + // @codeCoverageIgnoreStart private function __construct() { } @@ -27,6 +31,7 @@ private function __clone() public function __wakeup() { } + // @codeCoverageIgnoreEnd /** * Initialize and connect a vendor database. @@ -65,10 +70,10 @@ public function __wakeup() * @param string $tag Store the instance for later use * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli */ - public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null) + public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null): ezQueryInterface { if (isset(self::$instances[$vendor]) && empty($setting) && empty($tag)) - return setInstance(self::$instances[$vendor]) ? self::$instances[$vendor] : false; + return self::$instances[$vendor]; if (empty($vendor) || empty($setting)) { throw new \Exception(\MISSING_CONFIGURATION); @@ -77,7 +82,7 @@ public static function initialize(?string $vendor = null, ?array $setting = null $key = $vendor; $value = \VENDOR[$key]; - if (empty($GLOBALS['ez' . $key]) || !empty($tag)) { + if (!Db::has('ez' . $key) || !empty($tag)) { $di = new DInjector(); $di->set($key, $value); $di->set('ezsql\ConfigInterface', 'ezsql\Config'); @@ -88,8 +93,9 @@ public static function initialize(?string $vendor = null, ?array $setting = null } } - setInstance($GLOBALS['ez' . $key]); - return $GLOBALS['ez' . $key]; + $db = Db::get('ez' . $key); + Db::set('global', $db); + return $db; } } diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 7de25a4f..0d338359 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_mysqli extends ezsqlModel implements DatabaseInterface { @@ -44,9 +44,9 @@ public function __construct(ConfigInterface $settings = null) parent::__construct(); $this->database = $settings; - if (empty($GLOBALS['ez' . \MYSQLI])) - $GLOBALS['ez' . \MYSQLI] = $this; - setInstance($this); + if (!Db::has('ez' . \MYSQLI)) + Db::set('ez' . \MYSQLI, $this); + Db::set('global', $this); } // __construct public function settings() @@ -291,7 +291,7 @@ public function query_prepared(string $query, array $param = null) $params = []; $types = \array_reduce( $param, - function ($string, &$arg) use (&$params) { + function ($string, $arg) use (&$params) { $params[] = &$arg; if (\is_float($arg)) $string .= 'd'; diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index eec3acd1..644afbed 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_pdo extends ezsqlModel implements DatabaseInterface { @@ -47,9 +47,9 @@ public function __construct(ConfigInterface $settings = null) // Turn on track errors ini_set('track_errors', '1'); - if (empty($GLOBALS['ez' . \Pdo])) - $GLOBALS['ez' . \Pdo] = $this; - setInstance($this); + if (!Db::has('ez' . \Pdo)) + Db::set('ez' . \Pdo, $this); + Db::set('global', $this); } // __construct public function settings() diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 71f5aeb7..8ace292a 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_pgsql extends ezsqlModel implements DatabaseInterface { @@ -44,9 +44,9 @@ public function __construct(ConfigInterface $settings = null) parent::__construct(); $this->database = $settings; - if (empty($GLOBALS['ez' . \PGSQL])) - $GLOBALS['ez' . \PGSQL] = $this; - setInstance($this); + if (!Db::has('ez' . \PGSQL)) + Db::set('ez' . \PGSQL, $this); + Db::set('global', $this); } // __construct public function settings() diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index f36ac7f6..1cf729f7 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_sqlite3 extends ezsqlModel implements DatabaseInterface { @@ -51,9 +51,9 @@ public function __construct(ConfigInterface $settings = null) // Turn on track errors ini_set('track_errors', '1'); - if (!isset($GLOBALS['ez' . \SQLITE3])) - $GLOBALS['ez' . \SQLITE3] = $this; - setInstance($this); + if (!Db::has('ez' . \SQLITE3)) + Db::set('ez' . \SQLITE3, $this); + Db::set('global', $this); } public function settings() diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index aca7a533..fb0f34e0 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_sqlsrv extends ezsqlModel implements DatabaseInterface { @@ -53,9 +53,9 @@ public function __construct(ConfigInterface $settings = null) parent::__construct(); $this->database = $settings; - if (empty($GLOBALS['ez' . \SQLSRV])) - $GLOBALS['ez' . \SQLSRV] = $this; - setInstance($this); + if (!Db::has('ez' . \SQLSRV)) + Db::set('ez' . \SQLSRV, $this); + Db::set('global', $this); } public function settings() diff --git a/lib/Db.php b/lib/Db.php new file mode 100644 index 00000000..2da863e3 --- /dev/null +++ b/lib/Db.php @@ -0,0 +1,66 @@ +]*?>.*?@si', // Strip out javascript @@ -587,7 +563,7 @@ function clean_string(string $string) * @param string $filename will be preprocess with `sanitize_path()` * @return boolean */ - function is_traversal(string $basePath, string $filename) + function is_traversal(string $basePath, string $filename): bool { if (\strpos(\urldecode($filename), '..') !== false) return true; @@ -607,17 +583,17 @@ function is_traversal(string $basePath, string $filename) * * Example: * - * `sanitize_path("../../../../config.php");` - * - * Returns `config.php` without the path traversal - * @param string $path + * `sanitize_path("../../../../config.php-");` + * - Returns `config.php` without the path traversal + * @param string $path original file/path to be sanitized. * @return string */ - function sanitize_path(string $path) + function sanitize_path(string $path): string { $file = \preg_replace("/\.[\.]+/", "", $path); $file = \preg_replace("/^[\/]+/", "", $file); $file = \preg_replace("/^[A-Za-z][:\|][\/]?/", "", $file); + $file = \trim($file, '.-_'); return ($file); } @@ -965,14 +941,32 @@ function set_prefix(string $append = '') /** * Does an `select into` statement by calling `select` method - * @param $newTable, - new database table to be created - * @param $fromColumns - the columns from old database table - * @param $oldTable - old database table - * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra) ` - * - * @return mixed|object bool/result - false for error + * @param string $newTable, - new database table to be created + * @param mixed $fromColumns - the columns from old database table + * @param string $oldTable - old database table + * @param mixed $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/result - false for error + * @codeCoverageIgnore */ - function select_into($newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions) + function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) @@ -1096,15 +1090,15 @@ function grouping(...$conditions) * having( between( 'columns', values1, values2 ) ), * orderBy( 'columns', 'desc' ); * - * @param mixed $groupBy The grouping expression. + * @param string|array $column The grouping expression. * * @return string - GROUP BY SQL statement, or false on error */ - function groupBy($groupBy) + function groupBy($column) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->groupBy($groupBy) + ? $ezQuery->groupBy($column) : false; } @@ -1364,16 +1358,16 @@ function unionAll($table = '', $columnFields = '*', ...$conditions) /** * Specifies an ordering for the query results. - * @param string $orderBy - The column. - * @param string $order - The ordering direction. + * @param string|array $column - Which columns to use for ordering. + * @param string $order - The ordering direction, either `ASC`|`DESC`. * * @return string - ORDER BY SQL statement, or false on error */ - function orderBy($orderBy, $order) + function orderBy($column, $order) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->orderBy($orderBy, $order) + ? $ezQuery->orderBy($column, $order) : false; } @@ -1394,6 +1388,9 @@ function limit($numberOf, $offset = null) : false; } + /** + * @codeCoverageIgnore + */ function ezFunctions() { return true; diff --git a/lib/ezQuery.php b/lib/ezQuery.php index cbc413cf..4d0ff831 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -111,13 +111,13 @@ public static function to_string($arrays, $separation = ',') return $columns; } - public function groupBy($groupBy) + public function groupBy($column) { - if (empty($groupBy)) { + if (empty($column)) { return false; } - $columns = $this->to_string($groupBy); + $columns = $this->to_string($column); return 'GROUP BY ' . $columns; } @@ -262,15 +262,15 @@ private function joining( return ' ' . $type . ' JOIN ' . $rightTable . ' AS ' . $tableAs . ' ' . $onCondition; } - public function orderBy($orderBy, $order) + public function orderBy($column, $order) { - if (empty($orderBy)) { + if (empty($column)) { return false; } - $columns = $this->to_string($orderBy); - - $order = (\in_array(\strtoupper($order), array('ASC', 'DESC'))) ? \strtoupper($order) : 'ASC'; + $columns = $this->to_string($column); + $by = \strtoupper($order); + $order = (\in_array($by, array('ASC', 'DESC'))) ? $by : 'ASC'; return 'ORDER BY ' . $columns . ' ' . $order; } @@ -593,7 +593,10 @@ public function create_select(string $newTable, $fromColumns = '*', $oldTable = return $this->clearPrepare(); } - public function select_into(string $newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions) + /** + * @codeCoverageIgnore + */ + public function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions) { $this->isInto = true; if (isset($oldTable)) @@ -602,7 +605,7 @@ public function select_into(string $newTable, $fromColumns = '*', $oldTable = nu return $this->clearPrepare(); $newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$fromWhereConditions); - if (is_string($newTableFromTable)) + if (\is_string($newTableFromTable)) return (($this->isPrepareOn()) && !empty($this->prepareValues())) ? $this->query($newTableFromTable, true) : $this->query($newTableFromTable); @@ -619,7 +622,7 @@ public function update(string $table = null, $keyValue, ...$whereConditions) $sql = "UPDATE $table SET "; foreach ($keyValue as $key => $val) { - if (\strtolower($val) == 'null') { + if (is_null($val) || \strtolower($val) == 'null') { $sql .= "$key = NULL, "; } elseif (\in_array(\strtolower($val), array('current_timestamp()', 'date()', 'now()'))) { $sql .= "$key = CURRENT_TIMESTAMP(), "; diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 2fc422ac..14c3f1f7 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -50,11 +50,11 @@ public function prepareOff(); * having( between( 'columns', values1, values2 ) ), * orderBy( 'columns', 'desc' ); * - * @param mixed $groupBy The grouping expression. + * @param string|array $column The grouping expression. * * @return string - GROUP BY SQL statement, or false on error */ - public function groupBy($groupBy); + public function groupBy($column); /** * Specifies a `restriction` over the groups of the query. @@ -275,12 +275,12 @@ public function unionAll(string $table = null, $columnFields = '*', ...$conditio /** * Specifies an ordering for the query results. - * @param string $orderBy - The column. - * @param string $order - The ordering direction. + * @param string|array $column - Which columns to use for ordering. + * @param string $order - The ordering direction, either `ASC`|`DESC`. * * @return string - ORDER BY SQL statement, or false on error */ - public function orderBy($orderBy, $order); + public function orderBy($column, $order); /** * Specifies records from one or more tables in a database and @@ -452,10 +452,10 @@ function inserting(array $keyValue); /** * Does an `create select` statement by calling `select` method * - * @param $newTable, - new database table to be created - * @param $fromColumns - the columns from old database table - * @param $oldTable - old database table - * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * @param string $newTable, - new database table to be created + * @param string|array $fromColumns - the columns from old database table + * @param string $oldTable - old database table + * @param array $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` * - In the following format: *```js * eq('key/Field/Column', $value, _AND), // combine next expression @@ -480,10 +480,10 @@ public function create_select(string $newTable, $fromColumns = '*', $oldTable = /** * Does an `select into` statement by calling `select` method - * @param $newTable, - new database table to be created - * @param $fromColumns - the columns from old database table - * @param $oldTable - old database table - * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * @param string $newTable, - new database table to be created + * @param mixed $fromColumns - the columns from old database table + * @param string $oldTable - old database table + * @param mixed $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` * - In the following format: *```js * eq('key/Field/Column', $value, _AND), // combine next expression @@ -504,7 +504,7 @@ public function create_select(string $newTable, $fromColumns = '*', $oldTable = *``` * @return mixed bool/result - false for error */ - public function select_into(string $newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions); + public function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions); /** * Does an `update` query with an array, by conditional operator array diff --git a/lib/ezResultset.php b/lib/ezResultset.php index 5a9cc1ac..1eb31a2e 100644 --- a/lib/ezResultset.php +++ b/lib/ezResultset.php @@ -64,7 +64,7 @@ public function __construct($query_result) /** * Sets the position to zero */ - public function rewind() + public function rewind(): void { $this->_position = 0; } // rewind @@ -111,7 +111,7 @@ public function current($mode = self::RESULT_AS_OBJECT) * Returns the current position in the resultset * @return int */ - public function key() + public function key(): int { return $this->_position; } // key @@ -119,7 +119,7 @@ public function key() /** * Sets the position of the resultset up by one */ - public function next() + public function next(): void { ++$this->_position; } // next @@ -128,7 +128,7 @@ public function next() * Sets position of the resultset down by one, if the position is below the * start, the position is set to the start position */ - public function previous() + public function previous(): void { --$this->_position; @@ -141,7 +141,7 @@ public function previous() * Whether the current position contains a row, or not * @return boolean */ - public function valid() + public function valid(): bool { return isset($this->_resultset[$this->_position]); } // valid @@ -159,6 +159,7 @@ public function fetch_assoc() } else { $return_val = false; } + return $return_val; } // fetch_assoc @@ -175,6 +176,7 @@ public function fetch_row() } else { $return_val = false; } + return $return_val; } // fetch_row @@ -191,6 +193,7 @@ public function fetch_object() } else { $return_val = false; } + return $return_val; } // fetch_object @@ -206,6 +209,7 @@ public function fetch_json() } else { $return_val = false; } + return $return_val; } // fetch_assoc //public function diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index a8c374a2..6cd3eb7a 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -5,7 +5,6 @@ use ezsql\Tests\EZTestCase; use function ezsql\functions\{ - setInstance, getInstance, clearInstance, get_vendor, @@ -65,12 +64,15 @@ protected function setUp(): void public function testClean_string() { - $this->assertEquals("' help", clean_string("' help")); + if ((float) \phpversion() >= 8.1) + $this->assertEquals("' help", clean_string("' help")); + else + $this->assertEquals("' help", clean_string("' help")); } public function testSanitize_path() { - $this->assertEquals("config.php", sanitize_path("../../../../config.php")); + $this->assertEquals("config.php", sanitize_path("../../../../config.php-")); } public function testis_traversal() @@ -174,13 +176,13 @@ public function testGte() public function testIsNull() { $this->assertIsArray(isNull('field')); - $this->assertArraySubset([2 => 'null'], isNull('field')); + $this->assertArraySubset([2 => 'NULL'], isNull('field')); } public function testIsNotNull() { $this->assertIsArray(isNotNull('field')); - $this->assertArraySubset([2 => 'null'], isNotNull('field')); + $this->assertArraySubset([2 => 'NULL'], isNotNull('field')); } public function testLike() @@ -219,11 +221,6 @@ public function testNotBetween() $this->assertArraySubset([3 => 'data2'], notBetween('field', 'data', 'data2')); } - public function testSetInstance() - { - $this->assertFalse(setInstance()); - } - public function testSelect_into() { $this->assertFalse(select_into('field', 'data', 'data2')); diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 534f7ef4..85e7e9ff 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -25,6 +25,9 @@ dropping, altering, get_results, + groupBy, + limit, + orderBy, replacing, table_setup, where @@ -96,7 +99,12 @@ public function testConnect() $this->errors = array(); set_error_handler(array($this, 'errorHandler')); - $this->assertFalse($this->object->connect('no', '')); + if ((float) \phpversion() >= 8.1) { + $this->expectException(\mysqli_sql_exception::class); + $this->assertFalse($this->object->connect('no', '')); + } else + $this->assertFalse($this->object->connect('no', '')); + $this->assertFalse($this->object->connect('self::TEST_DB_USER', 'self::TEST_DB_PASSWORD', ' self::TEST_DB_HOST', 'self::TEST_DB_PORT')); $result = $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); @@ -281,8 +289,17 @@ public function testCreatingReplacing() { $this->object->quick_connect(); $this->object->prepareOff(); - $this->assertFalse($this->object->replacing([])); - $this->assertFalse($this->object->creating([])); + if ((float) \phpversion() >= 8.1) { + $this->expectException(\mysqli_sql_exception::class); + $this->assertFalse($this->object->replacing([])); + } else + $this->assertFalse($this->object->replacing([])); + + if ((float) \phpversion() >= 8.1) { + $this->expectException(\mysqli_sql_exception::class); + $this->assertFalse($this->object->creating([])); + } else + $this->assertFalse($this->object->creating([])); set_table('unit_test'); $this->assertEquals( @@ -603,7 +620,14 @@ public function testSelectAndCreateTable() ]) ); - $result = $this->object->select('users', 'id, tel_num, email', eq('user_name ', 'walker')); + $result = $this->object->select( + 'users', + 'id, tel_num, email', + where(eq('user_name ', 'walker')), + groupBy('id'), + orderBy('id', 'ASC'), + limit(1) + ); $this->object->debugOn(); $this->expectOutputRegex('/[123456]/');