Skip to content

Commit

Permalink
Change methods to static QueryBuilderProvider::class. (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 17, 2023
1 parent 747d398 commit 9140400
Show file tree
Hide file tree
Showing 7 changed files with 552 additions and 202 deletions.
45 changes: 42 additions & 3 deletions tests/AbstractCommandTest.php
Expand Up @@ -4,8 +4,8 @@

namespace Yiisoft\Db\Tests;

use Closure;
use PHPUnit\Framework\TestCase;
use Throwable;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Exception\Exception;
Expand All @@ -15,12 +15,19 @@
use Yiisoft\Db\Tests\Support\DbHelper;
use Yiisoft\Db\Tests\Support\TestTrait;

/**
* @psalm-suppress RedundantCondition
*/
abstract class AbstractCommandTest extends TestCase
{
use TestTrait;

protected string $upsertTestCharCast = '';

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testAutoQuoting(): void
{
$db = $this->getConnection();
Expand All @@ -41,6 +48,10 @@ public function testAutoQuoting(): void
);
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testConstruct(): void
{
$db = $this->getConnection();
Expand All @@ -58,6 +69,10 @@ public function testConstruct(): void
$this->assertSame([':name' => 'John'], $command->getParams());
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testGetParams(): void
{
$db = $this->getConnection();
Expand Down Expand Up @@ -99,18 +114,23 @@ public function testGetParams(): void
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws \Exception
*
* {@see https://github.com/yiisoft/yii2/issues/8592}
*/
public function testGetRawSql(string $sql, array $params, Closure $expectedRawSql): void
public function testGetRawSql(string $sql, array $params, string $expectedRawSql): void
{
$db = $this->getConnection();

$command = $db->createCommand($sql, $params);

$this->assertSame($expectedRawSql($db->getName()), $command->getRawSql());
$this->assertSame($expectedRawSql, $command->getRawSql());
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testGetSetSql(): void
{
$db = $this->getConnection();
Expand All @@ -128,6 +148,10 @@ public function testGetSetSql(): void
$this->assertSame($sql2, $command->getSql());
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testPrepareCancel(): void
{
$db = $this->getConnection(true);
Expand All @@ -150,6 +174,11 @@ public function testPrepareCancel(): void
$this->assertNull($command->getPdoStatement());
}

/**
* @throws Exception
* @throws InvalidConfigException
* @throws \Exception
*/
public function testSetRawSql(): void
{
$db = $this->getConnection();
Expand All @@ -164,6 +193,10 @@ public function testSetRawSql(): void
$this->assertSame('SELECT 123', $command->getRawSql());
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testSetSql(): void
{
$db = $this->getConnection();
Expand All @@ -178,6 +211,12 @@ public function testSetSql(): void
$this->assertSame('SELECT 123', $command->getSql());
}

/**
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
* @throws \PHPUnit\Framework\MockObject\Exception
*/
public function testProfiler(): void
{
$sql = 'SELECT 123';
Expand Down

0 comments on commit 9140400

Please sign in to comment.