From 50924b83e5649899eab681d3c707b6527f629ce3 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Fri, 1 Sep 2023 00:21:40 +0200 Subject: [PATCH] Add SingleStore tests --- tests/QueryTest.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 39d7af6..1bc340f 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -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 @@ -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'])) { @@ -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), }; }