Skip to content

Commit

Permalink
Add SingleStore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Aug 31, 2023
1 parent adaa10e commit 50924b8
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ public function testWithExpressionSqlServer()
$this->assertEquals($expected, $builder->toSql());
}

public function testWithExpressionSingleStore()
{
$builder = $this->getBuilder('SingleStore');
$builder->select('u.id')
->from('u')
->withExpression('u', $this->getBuilder('SingleStore')->from('users'))
->withExpression('p', $this->getBuilder('SingleStore')->from('posts'))
->join('p', 'p.user_id', '=', 'u.id');

$expected = 'with `u` as (select * from `users`), `p` as (select * from `posts`) select `u`.`id` from `u` inner join `p` on `p`.`user_id` = `u`.`id`';
$this->assertEquals($expected, $builder->toSql());
}

public function testWithRecursiveExpression()
{
// SingleStore doesn't support previous variant of the RCTE
Expand Down Expand Up @@ -189,6 +202,25 @@ public function testWithRecursiveExpressionSqlServer()
$this->assertEquals([3], $builder->getRawBindings()['expressions']);
}

public function testWithRecursiveExpressionSingleStore()
{
$query = $this->getBuilder('SingleStore')
->selectRaw('1')
->unionAll(
$this->getBuilder('SingleStore')
->selectRaw('number + 1')
->from('numbers')
->where('number', '<', 3)
);
$builder = $this->getBuilder('SingleStore');
$builder->from('numbers')
->withRecursiveExpression('numbers', $query, ['number']);

$expected = 'with recursive `numbers` (`number`) as ('.$query->toSql().') select * from `numbers`';
$this->assertEquals($expected, $builder->toSql());
$this->assertEquals([3], $builder->getRawBindings()['expressions']);
}

public function testWithRecursiveExpressionAndCycleDetection()
{
if (!in_array($this->database, ['mariadb', 'pgsql'])) {
Expand Down Expand Up @@ -488,7 +520,7 @@ protected function getBuilder($database)
$processor = $this->createMock(Processor::class);

return match ($database) {
'singlestore' => new SingleStoreBuilder($connection, new $grammar(), $processor),
'SingleStore' => new SingleStoreBuilder($connection, new $grammar(), $processor),
default => new Builder($connection, new $grammar(), $processor),
};
}
Expand Down

0 comments on commit 50924b8

Please sign in to comment.