2016-10-12 22:12:25 -04:00
|
|
|
<?php declare(strict_types=1);
|
2012-03-19 13:24:36 -04:00
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
2016-10-12 22:12:25 -04:00
|
|
|
* SQL Query Builder / Database Abstraction Layer
|
2012-03-19 13:24:36 -04:00
|
|
|
*
|
2018-01-19 16:50:34 -05:00
|
|
|
* PHP version 7.1
|
2016-10-12 22:12:25 -04:00
|
|
|
*
|
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-19 16:50:34 -05:00
|
|
|
* @copyright 2012 - 2018 Timothy J. Warren
|
2016-10-12 22:12:25 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @link https://git.timshomepage.net/aviat4ion/Query
|
2012-03-19 13:24:36 -04:00
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
namespace Query\Tests;
|
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
use BadMethodCallException;
|
2018-01-19 16:48:52 -05:00
|
|
|
use PDO;
|
2018-01-26 15:45:46 -05:00
|
|
|
use Query\Exception\BadDBDriverException;
|
2019-12-10 12:17:40 -05:00
|
|
|
use Query\QueryBuilderInterface;
|
2018-01-19 16:48:52 -05:00
|
|
|
|
2012-03-19 13:38:49 -04:00
|
|
|
/**
|
|
|
|
* Query builder parent test class
|
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
abstract class BaseQueryBuilderTest extends TestCase {
|
2012-03-19 13:24:36 -04:00
|
|
|
|
2018-01-22 16:04:29 -05:00
|
|
|
/**
|
2019-12-10 12:17:40 -05:00
|
|
|
* @var QueryBuilderInterface|null
|
2018-01-22 16:04:29 -05:00
|
|
|
*/
|
2015-07-30 16:40:30 -04:00
|
|
|
protected static $db;
|
|
|
|
|
2013-02-28 12:22:55 -05:00
|
|
|
public function __destruct()
|
|
|
|
{
|
2013-12-06 23:00:32 -05:00
|
|
|
if (isset($_GET['show_queries']))
|
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
echo '<pre>' . print_r(self::$db->queries, TRUE) . '</pre>';
|
2013-12-06 23:00:32 -05:00
|
|
|
}
|
2013-02-28 12:22:55 -05:00
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public static function tearDownAfterClass(): void
|
2015-07-30 16:40:30 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg')
|
|
|
|
{
|
|
|
|
echo '<pre>' . print_r(self::$db->queries, TRUE) . '</pre>';
|
|
|
|
}
|
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
self::$db = NULL;
|
|
|
|
}
|
2016-10-13 21:55:23 -04:00
|
|
|
|
2014-04-08 17:13:41 -04:00
|
|
|
// ! Driver-specific results
|
2019-12-10 12:17:40 -05:00
|
|
|
abstract public function testQueryExplain(): void;
|
2016-10-13 21:55:23 -04:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
// ! Get tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testInvalidConnectionName(): void
|
2014-02-11 14:29:41 -05:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->expectException('InvalidArgumentException');
|
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
Query('foo');
|
2014-02-11 14:29:41 -05:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testFunctionGet(): void
|
2013-04-25 08:15:56 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, COUNT(id) as count')
|
2013-04-25 08:15:56 -04:00
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupBy('id')
|
2013-04-25 08:15:56 -04:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGet(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->get('test');
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
2018-01-22 15:43:56 -05:00
|
|
|
$lastQuery = self::$db->getLastQuery();
|
|
|
|
$this->assertTrue(\is_string($lastQuery));
|
2012-03-19 13:24:36 -04:00
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testPrefixGet(): void
|
2012-11-07 08:42:34 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')->get();
|
2012-11-07 08:42:34 -05:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-11-08 14:28:49 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetWNumRows(): void
|
2012-09-27 13:41:29 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->get('test');
|
2012-09-27 13:41:29 -04:00
|
|
|
$numrows = count($query->fetchAll(PDO::FETCH_NUM));
|
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->assertEqual(self::$db->numRows(), $numrows);
|
2012-09-27 13:41:29 -04:00
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetLimit(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->get('test', 2);
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetLimitSkip(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->get('test', 2, 1);
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetWhere(): void
|
2012-04-17 08:29:28 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$query = self::$db->getWhere('test', ['id !=' => 1], 2, 1);
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-17 08:29:28 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testHaving(): void
|
2012-04-17 14:22:51 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupBy('id')
|
2018-01-26 08:39:30 -05:00
|
|
|
->having(['id >' => 1])
|
2012-04-17 14:22:51 -04:00
|
|
|
->having('id !=', 3)
|
|
|
|
->get();
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-17 14:22:51 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrHaving(): void
|
2012-04-17 14:22:51 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupBy('id')
|
2018-01-26 08:39:30 -05:00
|
|
|
->having(['id >' => 1])
|
2016-10-13 21:55:23 -04:00
|
|
|
->orHaving('id !=', 3)
|
2012-04-17 14:22:51 -04:00
|
|
|
->get();
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-17 14:22:51 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-14 22:08:19 -05:00
|
|
|
// ! Select tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectWhereGet(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2012-03-19 13:24:36 -04:00
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
2014-02-18 19:29:58 -05:00
|
|
|
->get('test', 2, 1);
|
2012-03-19 13:24:36 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectWhereGetNoAs(): void
|
|
|
|
{
|
|
|
|
$query = self::$db->select('id, key, val')
|
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
|
|
|
->get('test', 2, 1);
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSelectAvg(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->selectAvg('id', 'di')
|
2014-11-07 12:14:46 -05:00
|
|
|
->get('test');
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectSum(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->selectSum('id', 'di')
|
2014-11-07 12:14:46 -05:00
|
|
|
->get('test');
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectDistinct(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->selectSum('id', 'di')
|
2014-11-07 12:14:46 -05:00
|
|
|
->distinct()
|
|
|
|
->get('test');
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectGet(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-11-07 12:14:46 -05:00
|
|
|
->get('test', 2, 1);
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectFromGet(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-11-07 12:14:46 -05:00
|
|
|
->from('test ct')
|
|
|
|
->where('id >', 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectFromLimitGet(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-11-07 12:14:46 -05:00
|
|
|
->from('test ct')
|
|
|
|
->where('id >', 1)
|
|
|
|
->limit(3)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectWhereGet2(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2012-03-19 13:24:36 -04:00
|
|
|
->where('id !=', 1)
|
2014-02-18 19:29:58 -05:00
|
|
|
->get('test', 2, 1);
|
2012-03-19 13:24:36 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectMax(): void
|
2012-04-13 12:49:13 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->selectMax('id', 'di')
|
2012-11-07 08:42:34 -05:00
|
|
|
->get('test');
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-13 12:49:13 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSelectMin(): void
|
2012-04-13 12:49:13 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->selectMin('id', 'di')
|
2014-02-18 19:29:58 -05:00
|
|
|
->get('test');
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-13 12:49:13 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testMultiOrderBy(): void
|
2012-08-22 21:17:27 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->orderBy('id, key')
|
2012-08-22 21:17:27 -04:00
|
|
|
->get();
|
2012-08-24 12:17:08 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-14 22:08:19 -05:00
|
|
|
// ! Grouping tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGroup(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupStart()
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
2013-12-06 23:00:32 -05:00
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrGroup(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupStart()
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
|
|
|
->orGroupStart()
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('id =', 0)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
2013-12-06 23:00:32 -05:00
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrNotGroup(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupStart()
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
|
|
|
->orNotGroupStart()
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('id =', 0)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
2013-12-06 23:00:32 -05:00
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-24 12:17:08 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testAndNotGroupStart(): void
|
2016-10-12 20:32:23 -04:00
|
|
|
{
|
|
|
|
$query = self::$db->select('id, key as k, val')
|
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupStart()
|
2016-10-12 20:32:23 -04:00
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
|
|
|
->notGroupStart()
|
2016-10-12 20:32:23 -04:00
|
|
|
->where('id =', 0)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
2016-10-12 20:32:23 -04:00
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testNotGroupStart(): void
|
2016-10-12 20:32:23 -04:00
|
|
|
{
|
|
|
|
$query = self::$db->select('id, key as k, val')
|
|
|
|
->from('test')
|
2016-10-13 21:55:23 -04:00
|
|
|
->notGroupStart()
|
2016-10-12 20:32:23 -04:00
|
|
|
->where('id =', 0)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupEnd()
|
2016-10-12 20:32:23 -04:00
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGroupCamelCase(): void
|
2014-04-24 14:50:53 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-04-24 14:50:53 -04:00
|
|
|
->from('test')
|
|
|
|
->groupStart()
|
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
|
|
|
->groupEnd()
|
|
|
|
->orNotGroupStart()
|
|
|
|
->where('id =', 0)
|
|
|
|
->groupEnd()
|
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-14 22:08:19 -05:00
|
|
|
// ! Where In tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testWhereIn(): void
|
2012-08-24 12:17:08 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2018-01-26 08:39:30 -05:00
|
|
|
->whereIn('id', [0, 6, 56, 563, 341])
|
2012-08-24 12:17:08 -04:00
|
|
|
->get();
|
2012-08-22 21:17:27 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrWhereIn(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('key', 'false')
|
2018-01-26 08:39:30 -05:00
|
|
|
->orWhereIn('id', [0, 6, 56, 563, 341])
|
2013-12-06 23:00:32 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testWhereNotIn(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('key', 'false')
|
2018-01-26 08:39:30 -05:00
|
|
|
->whereNotIn('id', [0, 6, 56, 563, 341])
|
2013-12-06 23:00:32 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrWhereNotIn(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->where('key', 'false')
|
2018-01-26 08:39:30 -05:00
|
|
|
->orWhereNotIn('id', [0, 6, 56, 563, 341])
|
2013-12-06 23:00:32 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-04-17 08:29:28 -04:00
|
|
|
// ! Query modifier tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrderBy(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2012-03-19 13:24:36 -04:00
|
|
|
->where('id >', 0)
|
|
|
|
->where('id <', 9000)
|
2016-10-13 21:55:23 -04:00
|
|
|
->orderBy('id', 'DESC')
|
|
|
|
->orderBy('k', 'ASC')
|
2012-03-19 13:24:36 -04:00
|
|
|
->limit(5,2)
|
|
|
|
->get();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrderByRandom(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2012-03-19 13:24:36 -04:00
|
|
|
->where('id >', 0)
|
|
|
|
->where('id <', 9000)
|
2016-10-13 21:55:23 -04:00
|
|
|
->orderBy('id', 'rand')
|
2012-03-19 13:24:36 -04:00
|
|
|
->limit(5,2)
|
|
|
|
->get();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGroupBy(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2012-03-19 13:24:36 -04:00
|
|
|
->where('id >', 0)
|
|
|
|
->where('id <', 9000)
|
2016-10-13 21:55:23 -04:00
|
|
|
->groupBy('k')
|
2018-01-26 08:39:30 -05:00
|
|
|
->groupBy(['id','val'])
|
2016-10-13 21:55:23 -04:00
|
|
|
->orderBy('id', 'DESC')
|
|
|
|
->orderBy('k', 'ASC')
|
2012-03-19 13:24:36 -04:00
|
|
|
->limit(5,2)
|
|
|
|
->get();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
//public function testOr
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrWhere(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-02-18 19:29:58 -05:00
|
|
|
->from('test')
|
2012-03-19 13:24:36 -04:00
|
|
|
->where(' id ', 1)
|
2016-10-13 21:55:23 -04:00
|
|
|
->orWhere('key >', 0)
|
2012-03-19 13:24:36 -04:00
|
|
|
->limit(2, 1)
|
|
|
|
->get();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testLike(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2012-03-19 13:24:36 -04:00
|
|
|
->like('key', 'og')
|
|
|
|
->get();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrLike(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->like('key', 'og')
|
2016-10-13 21:55:23 -04:00
|
|
|
->orLike('key', 'val')
|
2013-12-06 23:00:32 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testOrNotLike(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->like('key', 'og', 'before')
|
2016-10-13 21:55:23 -04:00
|
|
|
->orNotLike('key', 'val')
|
2013-12-06 23:00:32 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testNotLike(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->like('key', 'og', 'before')
|
2016-10-13 21:55:23 -04:00
|
|
|
->notLike('key', 'val')
|
2013-12-06 23:00:32 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testLikeBefore(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->like('key', 'og', 'before')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testLikeAfter(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test')
|
2013-12-06 23:00:32 -05:00
|
|
|
->like('key', 'og', 'after')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testJoin(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test ct')
|
2012-11-07 08:42:34 -05:00
|
|
|
->join('join cj', 'cj.id = ct.id')
|
2012-03-19 13:24:36 -04:00
|
|
|
->get();
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testLeftJoin(): void
|
2013-05-01 15:59:23 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test ct')
|
2013-05-01 15:59:23 -04:00
|
|
|
->join('join cj', 'cj.id = ct.id', 'left')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testInnerJoin(): void
|
2013-05-01 15:59:23 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test ct')
|
2013-05-01 15:59:23 -04:00
|
|
|
->join('join cj', 'cj.id = ct.id', 'inner')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testJoinWithMultipleWhereValues(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->from('test ct')
|
2014-11-07 12:14:46 -05:00
|
|
|
->join('join cj', 'cj.id=ct.id', 'inner')
|
2018-01-26 08:39:30 -05:00
|
|
|
->where([
|
2014-11-07 12:14:46 -05:00
|
|
|
'ct.id < ' => 3,
|
|
|
|
'ct.key' => 'foo'
|
2018-01-26 08:39:30 -05:00
|
|
|
])
|
2014-11-07 12:14:46 -05:00
|
|
|
->get();
|
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2018-01-19 16:48:52 -05:00
|
|
|
|
2012-04-17 08:29:28 -04:00
|
|
|
// ! DB update tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testInsert(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->set('id', 98)
|
2014-02-18 19:29:58 -05:00
|
|
|
->set('key', 84)
|
|
|
|
->set('val', 120)
|
2012-11-07 08:42:34 -05:00
|
|
|
->insert('test');
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
2018-01-22 15:43:56 -05:00
|
|
|
$this->assertTrue(self::$db->affectedRows() > 0);
|
2012-03-19 13:24:36 -04:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testInsertArray(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$query = self::$db->insert('test', [
|
2018-01-19 16:48:52 -05:00
|
|
|
'id' => 587,
|
|
|
|
'key' => 1,
|
|
|
|
'val' => 2,
|
2018-01-26 08:39:30 -05:00
|
|
|
]);
|
2013-12-06 23:00:32 -05:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testInsertBatch(): void
|
2013-05-03 13:07:34 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$data = [
|
|
|
|
[
|
2013-05-03 13:07:34 -04:00
|
|
|
'id' => 544,
|
|
|
|
'key' => 3,
|
|
|
|
'val' => 7,
|
2018-01-26 08:39:30 -05:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 890,
|
2013-05-03 13:07:34 -04:00
|
|
|
'key' => 34,
|
2014-04-03 13:28:30 -04:00
|
|
|
'val' => "10 o'clock",
|
2018-01-26 08:39:30 -05:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 480,
|
2013-05-03 13:07:34 -04:00
|
|
|
'key' => 403,
|
|
|
|
'val' => 97,
|
2018-01-26 08:39:30 -05:00
|
|
|
],
|
|
|
|
];
|
2013-05-03 13:07:34 -04:00
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->insertBatch('test', $data);
|
2013-05-03 13:07:34 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testUpdate(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->where('id', 7)
|
2018-01-26 08:39:30 -05:00
|
|
|
->update('test', [
|
2014-02-18 14:50:20 -05:00
|
|
|
'id' => 7,
|
2013-12-06 23:00:32 -05:00
|
|
|
'key' => 'gogle',
|
|
|
|
'val' => 'non-word'
|
2018-01-26 08:39:30 -05:00
|
|
|
]);
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2018-01-22 15:43:56 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testUpdateBatchNull(): void
|
2018-01-22 15:43:56 -05:00
|
|
|
{
|
|
|
|
$query = self::$db->updateBatch('test', [], '');
|
|
|
|
$this->assertNull($query);
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testDriverUpdateBatch(): void
|
2018-01-26 08:39:30 -05:00
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
[
|
|
|
|
'id' => 480,
|
|
|
|
'key' => 49,
|
|
|
|
'val' => '7x7'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 890,
|
|
|
|
'key' => 100,
|
|
|
|
'val' => '10x10'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$affectedRows = self::$db->updateBatch('test', $data, 'id');
|
|
|
|
$this->assertEquals(2, $affectedRows);
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testSetArrayUpdate(): void
|
2012-10-24 20:19:39 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$array = [
|
2014-02-18 14:50:20 -05:00
|
|
|
'id' => 22,
|
2012-10-24 20:19:39 -04:00
|
|
|
'key' => 'gogle',
|
|
|
|
'val' => 'non-word'
|
2018-01-26 08:39:30 -05:00
|
|
|
];
|
2012-10-24 20:19:39 -04:00
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->set($array)
|
2014-02-18 14:50:20 -05:00
|
|
|
->where('id', 22)
|
2014-02-18 19:29:58 -05:00
|
|
|
->update('test');
|
2012-10-24 20:19:39 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testWhereSetUpdate(): void
|
2012-10-24 20:19:39 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->where('id', 36)
|
2014-02-18 14:50:20 -05:00
|
|
|
->set('id', 36)
|
2012-10-24 20:19:39 -04:00
|
|
|
->set('key', 'gogle')
|
|
|
|
->set('val', 'non-word')
|
2014-02-17 20:10:47 -05:00
|
|
|
->update('test');
|
2012-10-24 20:19:39 -04:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testDelete(): void
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$query = self::$db->delete('test', ['id' => 5]);
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-19 13:24:36 -04:00
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testDeleteWithMultipleWhereValues(): void
|
2014-11-07 12:14:46 -05:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$query = self::$db->delete('test', [
|
2014-11-07 12:14:46 -05:00
|
|
|
'id' => 5,
|
|
|
|
'key' => 'gogle'
|
2018-01-26 08:39:30 -05:00
|
|
|
]);
|
2014-11-07 12:14:46 -05:00
|
|
|
|
|
|
|
$this->assertIsA($query, 'PDOStatement');
|
|
|
|
}
|
2016-10-13 21:55:23 -04:00
|
|
|
|
2012-04-17 08:29:28 -04:00
|
|
|
// ! Non-data read queries
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testCountAll(): void
|
2012-04-10 14:06:34 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->countAll('test');
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-17 08:29:28 -04:00
|
|
|
$this->assertTrue(is_numeric($query));
|
2012-04-10 14:06:34 -04:00
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testCountAllResults(): void
|
2012-04-17 11:37:39 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$query = self::$db->countAllResults('test');
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-17 11:37:39 -04:00
|
|
|
$this->assertTrue(is_numeric($query));
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testCountAllResults2(): void
|
2012-04-17 11:37:39 -04:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2012-11-07 08:42:34 -05:00
|
|
|
->from('test')
|
2012-04-17 11:37:39 -04:00
|
|
|
->where(' id ', 1)
|
2016-10-13 21:55:23 -04:00
|
|
|
->orWhere('key >', 0)
|
2012-04-17 11:37:39 -04:00
|
|
|
->limit(2, 1)
|
2016-10-13 21:55:23 -04:00
|
|
|
->countAllResults();
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2012-04-17 11:37:39 -04:00
|
|
|
$this->assertTrue(is_numeric($query));
|
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testNumRows(): void
|
2012-04-20 16:33:40 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
self::$db->get('test');
|
|
|
|
$this->assertTrue(is_numeric(self::$db->numRows()));
|
2012-04-20 16:33:40 -04:00
|
|
|
}
|
2016-10-13 21:55:23 -04:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
// ! Compiled Query tests
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetCompiledSelect(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$sql = self::$db->getCompiledSelect('test');
|
|
|
|
$qbRes = self::$db->get('test');
|
|
|
|
$sqlRes = self::$db->query($sql);
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
$this->assertIsA($qbRes,'PDOStatement', 'Query Builder Result is a PDO Statement');
|
|
|
|
$this->assertIsA($sqlRes, 'PDOStatement', 'SQL Result is a PDO Statement');
|
2016-10-13 21:55:23 -04:00
|
|
|
//$this->assertEquals($qbRes, $sqlRes);
|
2013-12-06 23:00:32 -05:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetCompiledUpdate(): void
|
2013-12-09 19:46:34 -05:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$sql = self::$db->set([
|
2013-12-09 19:46:34 -05:00
|
|
|
'id' => 4,
|
|
|
|
'key' => 'foo',
|
|
|
|
'val' => 'baz'
|
2018-01-26 08:39:30 -05:00
|
|
|
])->getCompiledUpdate('test');
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->assertTrue(\is_string($sql));
|
2013-12-09 19:46:34 -05:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetCompiledInsert(): void
|
2013-12-09 19:46:34 -05:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$sql = self::$db->set([
|
2013-12-09 19:46:34 -05:00
|
|
|
'id' => 4,
|
|
|
|
'key' => 'foo',
|
|
|
|
'val' => 'baz'
|
2018-01-26 08:39:30 -05:00
|
|
|
])->getCompiledInsert('test');
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->assertTrue(\is_string($sql));
|
2013-12-09 19:46:34 -05:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testGetCompiledDelete(): void
|
2013-12-09 19:46:34 -05:00
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$sql = self::$db->where('id', 4)
|
2016-10-13 21:55:23 -04:00
|
|
|
->getCompiledDelete('test');
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->assertTrue(\is_string($sql));
|
2013-12-09 19:46:34 -05:00
|
|
|
}
|
2014-02-14 22:08:19 -05:00
|
|
|
// ! Error tests
|
2012-07-26 13:21:24 -04:00
|
|
|
/**
|
|
|
|
* Handles invalid drivers
|
|
|
|
*/
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testBadDriver(): void
|
2012-07-26 13:21:24 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$params = [
|
2012-07-26 13:21:24 -04:00
|
|
|
'host' => '127.0.0.1',
|
|
|
|
'port' => '3306',
|
|
|
|
'database' => 'test',
|
|
|
|
'user' => 'root',
|
|
|
|
'pass' => NULL,
|
|
|
|
'type' => 'QGYFHGEG'
|
2018-01-26 08:39:30 -05:00
|
|
|
];
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$this->expectException(BadDBDriverException::class);
|
2016-10-13 21:55:23 -04:00
|
|
|
|
|
|
|
self::$db = Query($params);
|
2012-07-26 13:21:24 -04:00
|
|
|
}
|
2012-08-22 21:17:27 -04:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testBadMethod(): void
|
2013-12-06 23:00:32 -05:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
$this->expectException(BadMethodCallException::class);
|
2016-10-13 21:55:23 -04:00
|
|
|
|
|
|
|
self::$db->foo();
|
2013-12-06 23:00:32 -05:00
|
|
|
}
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2019-12-10 12:17:40 -05:00
|
|
|
public function testBadNumRows(): void
|
2013-12-09 19:46:34 -05:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
self::$db->set([
|
2013-12-09 19:46:34 -05:00
|
|
|
'id' => 999,
|
|
|
|
'key' => 'ring',
|
|
|
|
'val' => 'sale'
|
2018-01-26 08:39:30 -05:00
|
|
|
])->insert('test');
|
2014-02-25 13:47:35 -05:00
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$res = self::$db->numRows();
|
2013-12-09 19:46:34 -05:00
|
|
|
$this->assertEqual(NULL, $res);
|
|
|
|
}
|
2016-10-13 21:55:23 -04:00
|
|
|
}
|