2016-10-12 22:12:25 -04:00
|
|
|
<?php declare(strict_types=1);
|
2014-06-09 17:02:14 -04:00
|
|
|
/**
|
2016-10-12 22:12:25 -04:00
|
|
|
* Query
|
2014-06-09 17:02:14 -04:00
|
|
|
*
|
2016-10-12 22:12:25 -04:00
|
|
|
* SQL Query Builder / Database Abstraction Layer
|
2014-06-09 17:02:14 -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
|
2014-06-09 17:02:14 -04:00
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
namespace Query\Tests\Drivers\SQLite;
|
|
|
|
|
|
|
|
use PDO;
|
|
|
|
use Query\Tests\BaseQueryBuilderTest;
|
2016-10-12 22:12:25 -04:00
|
|
|
|
2014-06-09 17:02:14 -04:00
|
|
|
/**
|
|
|
|
* Class for testing Query Builder with SQLite
|
|
|
|
*
|
|
|
|
* @requires extension pdo_sqlite
|
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
class SQLiteQueryBuilderTest extends BaseQueryBuilderTest {
|
2014-06-09 17:02:14 -04:00
|
|
|
|
2015-07-30 16:40:30 -04:00
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
// Defined in the SQLiteTest.php file
|
|
|
|
self::$db = Query('test_sqlite');
|
|
|
|
}
|
2014-06-09 17:02:14 -04:00
|
|
|
|
|
|
|
public function testQueryFunctionAlias()
|
|
|
|
{
|
|
|
|
$db = Query('test_sqlite');
|
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$this->assertTrue(self::$db === $db, 'Alias passed into query function gives the original object back');
|
2014-06-09 17:02:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testQueryExplain()
|
|
|
|
{
|
2015-07-30 16:40:30 -04:00
|
|
|
$query = self::$db->select('id, key as k, val')
|
2014-06-09 17:02:14 -04:00
|
|
|
->explain()
|
|
|
|
->where('id >', 1)
|
|
|
|
->where('id <', 900)
|
|
|
|
->get('create_test', 2, 1);
|
|
|
|
|
|
|
|
$res = $query->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$expectedPossibilities = [];
|
2014-06-09 17:02:14 -04:00
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$expectedPossibilities[] = [
|
|
|
|
[
|
2014-06-09 17:02:14 -04:00
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'TABLE create_test USING PRIMARY KEY',
|
2018-01-26 08:39:30 -05:00
|
|
|
]
|
|
|
|
];
|
2014-06-09 17:02:14 -04:00
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$expectedPossibilities[] = [
|
|
|
|
[
|
2014-06-09 17:02:14 -04:00
|
|
|
'selectid' => '0',
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?) (~60000 rows)',
|
2018-01-26 08:39:30 -05:00
|
|
|
],
|
|
|
|
];
|
2014-06-09 17:02:14 -04:00
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$expectedPossibilities[] = [
|
|
|
|
[
|
2014-06-09 17:02:14 -04:00
|
|
|
'selectid' => '0',
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?)',
|
2018-01-26 08:39:30 -05:00
|
|
|
],
|
|
|
|
];
|
2014-06-09 17:02:14 -04:00
|
|
|
|
2018-01-26 08:39:30 -05:00
|
|
|
$expectedPossibilities[] = [
|
|
|
|
[
|
2014-06-09 17:02:14 -04:00
|
|
|
'selectid' => '0',
|
|
|
|
'order' => '0',
|
|
|
|
'from' => '0',
|
|
|
|
'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid<?) (~62500 rows)',
|
2018-01-26 08:39:30 -05:00
|
|
|
],
|
|
|
|
];
|
2014-06-09 17:02:14 -04:00
|
|
|
|
|
|
|
$passed = FALSE;
|
|
|
|
|
|
|
|
// Check for a matching possibility
|
2016-10-13 21:55:23 -04:00
|
|
|
foreach($expectedPossibilities as $ep)
|
2014-06-09 17:02:14 -04:00
|
|
|
{
|
2018-01-26 08:39:30 -05:00
|
|
|
if ($res === $ep)
|
2014-06-09 17:02:14 -04:00
|
|
|
{
|
|
|
|
$this->assertTrue(TRUE);
|
|
|
|
$passed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Well, apparently not an expected possibility
|
|
|
|
if ( ! $passed)
|
|
|
|
{
|
|
|
|
var_export($res);
|
|
|
|
$this->assertTrue(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|