Fix querybuilder and functionbuilder tests

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-07-24 12:01:35 +02:00
parent bb58667511
commit 293dea0625
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
2 changed files with 33 additions and 25 deletions

View File

@ -44,6 +44,8 @@ class FunctionBuilderTest extends TestCase {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->select($query->func()->concat($query->createNamedParameter('foo'), new Literal("'bar'"))); $query->select($query->func()->concat($query->createNamedParameter('foo'), new Literal("'bar'")));
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('foobar', $query->execute()->fetchColumn()); $this->assertEquals('foobar', $query->execute()->fetchColumn());
} }
@ -52,6 +54,8 @@ class FunctionBuilderTest extends TestCase {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->select($query->func()->md5($query->createNamedParameter('foobar'))); $query->select($query->func()->md5($query->createNamedParameter('foobar')));
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals(md5('foobar'), $query->execute()->fetchColumn()); $this->assertEquals(md5('foobar'), $query->execute()->fetchColumn());
} }
@ -60,6 +64,8 @@ class FunctionBuilderTest extends TestCase {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->select($query->func()->substring($query->createNamedParameter('foobar'), new Literal(2), $query->createNamedParameter(2))); $query->select($query->func()->substring($query->createNamedParameter('foobar'), new Literal(2), $query->createNamedParameter(2)));
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('oo', $query->execute()->fetchColumn()); $this->assertEquals('oo', $query->execute()->fetchColumn());
} }
@ -68,6 +74,8 @@ class FunctionBuilderTest extends TestCase {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->select($query->func()->substring($query->createNamedParameter('foobar'), new Literal(2))); $query->select($query->func()->substring($query->createNamedParameter('foobar'), new Literal(2)));
$query->from('appconfig')
->setMaxResults(1);
$this->assertEquals('oobar', $query->execute()->fetchColumn()); $this->assertEquals('oobar', $query->execute()->fetchColumn());
} }

View File

@ -472,15 +472,15 @@ class QueryBuilderTest extends \Test\TestCase {
public function dataFrom() { public function dataFrom() {
return [ return [
['data', null, null, null, [['table' => '`*PREFIX*data`', 'alias' => null]], '`*PREFIX*data`'], ['data', null, null, null, [['table' => '`*PREFIX*data`', 'alias' => null]], '`*PREFIX*data`'],
['data', 't', null, null, [['table' => '`*PREFIX*data`', 'alias' => 't']], '`*PREFIX*data` t'], ['data', 't', null, null, [['table' => '`*PREFIX*data`', 'alias' => '`t`']], '`*PREFIX*data` `t`'],
['data1', null, 'data2', null, [ ['data1', null, 'data2', null, [
['table' => '`*PREFIX*data1`', 'alias' => null], ['table' => '`*PREFIX*data1`', 'alias' => null],
['table' => '`*PREFIX*data2`', 'alias' => null] ['table' => '`*PREFIX*data2`', 'alias' => null]
], '`*PREFIX*data1`, `*PREFIX*data2`'], ], '`*PREFIX*data1`, `*PREFIX*data2`'],
['data', 't1', 'data', 't2', [ ['data', 't1', 'data', 't2', [
['table' => '`*PREFIX*data`', 'alias' => 't1'], ['table' => '`*PREFIX*data`', 'alias' => '`t1`'],
['table' => '`*PREFIX*data`', 'alias' => 't2'] ['table' => '`*PREFIX*data`', 'alias' => '`t2`']
], '`*PREFIX*data` t1, `*PREFIX*data` t2'], ], '`*PREFIX*data` `t1`, `*PREFIX*data` `t2`'],
]; ];
} }
@ -515,18 +515,18 @@ class QueryBuilderTest extends \Test\TestCase {
return [ return [
[ [
'd1', 'data2', null, null, 'd1', 'data2', null, null,
['d1' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]], ['`d1`' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]],
'`*PREFIX*data1` d1 INNER JOIN `*PREFIX*data2` ON ' '`*PREFIX*data1` `d1` INNER JOIN `*PREFIX*data2` ON '
], ],
[ [
'd1', 'data2', 'd2', null, 'd1', 'data2', 'd2', null,
['d1' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]], ['`d1`' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '`d2`', 'joinCondition' => null]]],
'`*PREFIX*data1` d1 INNER JOIN `*PREFIX*data2` d2 ON ' '`*PREFIX*data1` `d1` INNER JOIN `*PREFIX*data2` `d2` ON '
], ],
[ [
'd1', 'data2', 'd2', 'd1.`field1` = d2.`field2`', 'd1', 'data2', 'd2', '`d1`.`field1` = `d2`.`field2`',
['d1' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]], ['`d1`' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '`d2`', 'joinCondition' => '`d1`.`field1` = `d2`.`field2`']]],
'`*PREFIX*data1` d1 INNER JOIN `*PREFIX*data2` d2 ON d1.`field1` = d2.`field2`' '`*PREFIX*data1` `d1` INNER JOIN `*PREFIX*data2` `d2` ON `d1`.`field1` = `d2`.`field2`'
], ],
]; ];
@ -596,18 +596,18 @@ class QueryBuilderTest extends \Test\TestCase {
return [ return [
[ [
'd1', 'data2', null, null, 'd1', 'data2', null, null,
['d1' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]], ['`d1`' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]],
'`*PREFIX*data1` d1 LEFT JOIN `*PREFIX*data2` ON ' '`*PREFIX*data1` `d1` LEFT JOIN `*PREFIX*data2` ON '
], ],
[ [
'd1', 'data2', 'd2', null, 'd1', 'data2', 'd2', null,
['d1' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]], ['`d1`' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '`d2`', 'joinCondition' => null]]],
'`*PREFIX*data1` d1 LEFT JOIN `*PREFIX*data2` d2 ON ' '`*PREFIX*data1` `d1` LEFT JOIN `*PREFIX*data2` `d2` ON '
], ],
[ [
'd1', 'data2', 'd2', 'd1.`field1` = d2.`field2`', 'd1', 'data2', 'd2', '`d1`.`field1` = `d2`.`field2`',
['d1' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]], ['`d1`' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '`d2`', 'joinCondition' => '`d1`.`field1` = `d2`.`field2`']]],
'`*PREFIX*data1` d1 LEFT JOIN `*PREFIX*data2` d2 ON d1.`field1` = d2.`field2`' '`*PREFIX*data1` `d1` LEFT JOIN `*PREFIX*data2` `d2` ON `d1`.`field1` = `d2`.`field2`'
], ],
]; ];
} }
@ -646,18 +646,18 @@ class QueryBuilderTest extends \Test\TestCase {
return [ return [
[ [
'd1', 'data2', null, null, 'd1', 'data2', null, null,
['d1' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]], ['`d1`' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]],
'`*PREFIX*data1` d1 RIGHT JOIN `*PREFIX*data2` ON ' '`*PREFIX*data1` `d1` RIGHT JOIN `*PREFIX*data2` ON '
], ],
[ [
'd1', 'data2', 'd2', null, 'd1', 'data2', 'd2', null,
['d1' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]], ['`d1`' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '`d2`', 'joinCondition' => null]]],
'`*PREFIX*data1` d1 RIGHT JOIN `*PREFIX*data2` d2 ON ' '`*PREFIX*data1` `d1` RIGHT JOIN `*PREFIX*data2` `d2` ON '
], ],
[ [
'd1', 'data2', 'd2', 'd1.`field1` = d2.`field2`', 'd1', 'data2', 'd2', '`d1`.`field1` = `d2`.`field2`',
['d1' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]], ['`d1`' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '`d2`', 'joinCondition' => '`d1`.`field1` = `d2`.`field2`']]],
'`*PREFIX*data1` d1 RIGHT JOIN `*PREFIX*data2` d2 ON d1.`field1` = d2.`field2`' '`*PREFIX*data1` `d1` RIGHT JOIN `*PREFIX*data2` `d2` ON `d1`.`field1` = `d2`.`field2`'
], ],
]; ];
} }