mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Add a unit test to check for casting a IQueryFunction
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
5d7d70538b
commit
11d21e5f5c
1 changed files with 34 additions and 0 deletions
|
|
@ -22,6 +22,7 @@
|
|||
namespace Test\DB\QueryBuilder;
|
||||
|
||||
use OC\DB\QueryBuilder\Literal;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -109,4 +110,37 @@ class ExpressionBuilderDBTest extends TestCase {
|
|||
$result->closeCursor();
|
||||
$this->assertEquals($match, $column);
|
||||
}
|
||||
|
||||
public function testCastColumn(): void {
|
||||
$appId = $this->getUniqueID('testing');
|
||||
$this->createConfig($appId, '1', '4');
|
||||
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->update('appconfig')
|
||||
->set('configvalue',
|
||||
$query->expr()->castColumn(
|
||||
$query->createFunction(
|
||||
'(' . $query->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT)
|
||||
. ' + 1)'
|
||||
)
|
||||
, IQueryBuilder::PARAM_STR
|
||||
)
|
||||
)
|
||||
->where($query->expr()->eq('appid', $query->createNamedParameter($appId)))
|
||||
->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('1')));
|
||||
|
||||
$result = $query->executeStatement();
|
||||
$this->assertEquals(1, $result);
|
||||
}
|
||||
|
||||
protected function createConfig($appId, $key, $value) {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->insert('appconfig')
|
||||
->values([
|
||||
'appid' => $query->createNamedParameter($appId),
|
||||
'configkey' => $query->createNamedParameter((string) $key),
|
||||
'configvalue' => $query->createNamedParameter((string) $value),
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue