2016-10-12 22:12:25 -04:00
|
|
|
<?php declare(strict_types=1);
|
2012-08-02 11:59:11 -04:00
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
2016-10-12 22:12:25 -04:00
|
|
|
* SQL Query Builder / Database Abstraction Layer
|
2012-08-02 11:59:11 -04:00
|
|
|
*
|
2018-01-19 16:48:52 -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:48:52 -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-08-02 11:59:11 -04:00
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
namespace Query\Tests;
|
2012-08-02 11:59:11 -04:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
use Query\QueryParser;
|
|
|
|
use Query\Drivers\Sqlite\Driver;
|
2012-08-02 11:59:11 -04:00
|
|
|
|
2012-08-09 12:15:36 -04:00
|
|
|
/**
|
|
|
|
* Tests for the Query Parser
|
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
class QueryParserTest extends TestCase {
|
2012-08-02 11:59:11 -04:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
public function setUp()
|
2012-08-02 11:59:11 -04:00
|
|
|
{
|
2018-01-19 16:48:52 -05:00
|
|
|
$db = new Driver('sqlite::memory:');
|
|
|
|
$this->parser = new QueryParser($db);
|
2012-08-02 11:59:11 -04:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
public function testGeneric()
|
2012-08-02 11:59:11 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$matches = $this->parser->parseJoin('table1.field1=table2.field2');
|
2015-07-31 10:24:34 -04:00
|
|
|
$this->assertEqual($matches['combined'], array(
|
2012-08-09 12:15:36 -04:00
|
|
|
'table1.field1', '=', 'table2.field2'
|
|
|
|
));
|
2012-08-02 11:59:11 -04:00
|
|
|
}
|
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
public function testGeneric2()
|
2012-08-02 11:59:11 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$matches = $this->parser->parseJoin('db1.table1.field1!=db2.table2.field2');
|
2015-07-31 10:24:34 -04:00
|
|
|
$this->assertEqual($matches['combined'], array(
|
2012-08-09 12:15:36 -04:00
|
|
|
'db1.table1.field1','!=','db2.table2.field2'
|
|
|
|
));
|
|
|
|
}
|
2012-08-02 11:59:11 -04:00
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
public function testWUnderscore()
|
2012-08-09 12:15:36 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$matches = $this->parser->parseJoin('table_1.field1 = tab_le2.field_2');
|
2015-07-31 10:24:34 -04:00
|
|
|
$this->assertEqual($matches['combined'], array(
|
2012-08-09 12:15:36 -04:00
|
|
|
'table_1.field1', '=', 'tab_le2.field_2'
|
|
|
|
));
|
2012-08-02 11:59:11 -04:00
|
|
|
}
|
|
|
|
|
2014-02-14 22:08:19 -05:00
|
|
|
public function testFunction()
|
2012-08-09 12:15:36 -04:00
|
|
|
{
|
2016-10-13 21:55:23 -04:00
|
|
|
$matches = $this->parser->parseJoin('table1.field1 > SUM(3+5)');
|
2015-07-31 10:24:34 -04:00
|
|
|
$this->assertEqual($matches['combined'], array(
|
2012-08-09 12:15:36 -04:00
|
|
|
'table1.field1', '>', 'SUM(3+5)'
|
|
|
|
));
|
|
|
|
}
|
2012-08-02 11:59:11 -04:00
|
|
|
}
|