Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
- Enh #1065: Allow to use table name as a column prefix in update queries (@Tigrov)
- Enh #1068: Quote string values as column names when join condition is an associative array (@Tigrov)
- Chg #1070: Change "IndexBy" closure signature to `Closure(array|object):int|string` (@vjik)
- Enh #1072, #1077, #1078, #1079, #1080, #1085, #1087: Improve psalm types (@vjik)
- Enh #1072, #1077, #1078, #1079, #1080, #1085, #1087, #1096: Improve psalm types (@vjik)
- New #1074: Add `ConnectionProvider` class (@Tigrov)
- Chg #1075: Rename `Query::$join` property to `$joins` (@vjik)
- New #1076: Allow to use expressions as table name or condition in "join" query methods (@vjik)
Expand Down
5 changes: 0 additions & 5 deletions src/Schema/Column/AbstractColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ protected function columnDefinitionParser(): ColumnDefinitionParser
}

/**
* @psalm-param ColumnType::* $type
* @psalm-param ColumnInfo $info
* @psalm-return class-string<ColumnInterface>
*/
Expand Down Expand Up @@ -291,8 +290,6 @@ protected function isDbType(string $dbType): bool

/**
* Checks if the column type is a pseudo-type.
*
* @psalm-assert-if-true PseudoType::* $pseudoType
Comment thread
Tigrov marked this conversation as resolved.
*/
protected function isPseudoType(string $pseudoType): bool
{
Expand All @@ -309,8 +306,6 @@ protected function isPseudoType(string $pseudoType): bool

/**
* Checks if the column type is an abstract type.
*
* @psalm-assert-if-true ColumnType::* $type
*/
protected function isType(string $type): bool
{
Expand Down
2 changes: 0 additions & 2 deletions src/Schema/Column/ColumnFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function fromDefinition(string $definition, array $info = []): ColumnInte
* @param string $pseudoType The pseudo-type.
* @param array $info The column information. The set of parameters may be different for a specific DBMS.
*
* @psalm-param PseudoType::* $pseudoType
Comment thread
Tigrov marked this conversation as resolved.
* @psalm-param ColumnInfo $info
*/
public function fromPseudoType(string $pseudoType, array $info = []): ColumnInterface;
Expand All @@ -84,7 +83,6 @@ public function fromPseudoType(string $pseudoType, array $info = []): ColumnInte
* @param string $type The abstract database type.
* @param array $info The column information. The set of parameters may be different for a specific DBMS.
*
* @psalm-param ColumnType::* $type
* @psalm-param ColumnInfo $info
*/
public function fromType(string $type, array $info = []): ColumnInterface;
Expand Down
5 changes: 5 additions & 0 deletions src/Schema/Column/ColumnInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constraint\ForeignKey;
use Yiisoft\Db\Exception\NotSupportedException;

/**
* This interface defines a set of methods that must be implemented by a class that represents a database table column.
Expand Down Expand Up @@ -86,6 +87,8 @@ public function dbType(?string $dbType): static;
* directly in your code.
*
* If the value is `null` or an {@see Expression}, there will be no conversion.
*
* @throws NotSupportedException
*/
public function dbTypecast(mixed $value): mixed;

Expand Down Expand Up @@ -291,6 +294,8 @@ public function null(): static;

/**
* Converts the input value after retrieval from the database.
*
* @throws NotSupportedException
*/
public function phpTypecast(mixed $value): mixed;

Expand Down
73 changes: 17 additions & 56 deletions tests/AbstractCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,18 @@
namespace Yiisoft\Db\Tests;

use PHPUnit\Framework\TestCase;
use Throwable;
use Yiisoft\Db\Expression\Value\Param;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Profiler\Context\CommandContext;
use Yiisoft\Db\Profiler\ContextInterface;
use Yiisoft\Db\Profiler\ProfilerInterface;
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 @@ -47,10 +36,6 @@ public function testAutoQuoting(): void
);
}

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

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testGetParams(): void
{
$db = $this->getConnection();
Expand Down Expand Up @@ -103,19 +84,14 @@ public function testGetParams(): void
$this->assertContainsOnlyInstancesOf(Param::class, $bindedValues);
$this->assertCount(3, $bindedValues);
$this->assertEquals($param, $bindedValues['int']);

$db->close();
}

/**
* Test command getRawSql.
*
* @dataProvider \Yiisoft\Db\Tests\Provider\CommandProvider::rawSql
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws \Exception
*
* {@see https://github.com/yiisoft/yii2/issues/8592}
* @see https://github.com/yiisoft/yii2/issues/8592
*/
public function testGetRawSql(string $sql, array $params, string $expectedRawSql): void
{
Expand All @@ -124,12 +100,10 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql
$command = $db->createCommand($sql, $params);

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

$db->close();
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testGetSetSql(): void
{
$db = $this->getConnection();
Expand All @@ -145,12 +119,10 @@ public function testGetSetSql(): void
SQL;
$command->setSql($sql2);
$this->assertSame($sql2, $command->getSql());

$db->close();
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testPrepareCancel(): void
{
$db = $this->getConnection(true);
Expand All @@ -171,13 +143,10 @@ public function testPrepareCancel(): void
$command->cancel();

$this->assertNull($command->getPdoStatement());

$db->close();
}

/**
* @throws Exception
* @throws InvalidConfigException
* @throws \Exception
*/
public function testSetRawSql(): void
{
$db = $this->getConnection();
Expand All @@ -190,12 +159,10 @@ public function testSetRawSql(): void
);

$this->assertSame('SELECT 123', $command->getRawSql());

$db->close();
}

/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testSetSql(): void
{
$db = $this->getConnection();
Expand All @@ -208,14 +175,10 @@ public function testSetSql(): void
);

$this->assertSame('SELECT 123', $command->getSql());

$db->close();
}

/**
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
* @throws \PHPUnit\Framework\MockObject\Exception
*/
public function testProfiler(?string $sql = null): void
{
$sql ??= 'SELECT 123';
Expand All @@ -233,14 +196,10 @@ public function testProfiler(?string $sql = null): void
$db->setProfiler($profiler);

$db->createCommand($sql)->execute();

$db->close();
}

/**
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
* @throws \PHPUnit\Framework\MockObject\Exception
*/
public function testProfilerData(?string $sql = null): void
{
$sql ??= 'SELECT 123';
Expand Down Expand Up @@ -271,5 +230,7 @@ public function end(string $token, ContextInterface|array $context = []): void
$db->setProfiler($profiler);

$db->createCommand($sql)->execute();

$db->close();
}
}
6 changes: 0 additions & 6 deletions tests/AbstractQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
use function PHPUnit\Framework\assertEmpty;
use function PHPUnit\Framework\assertSame;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
abstract class AbstractQueryBuilderTest extends TestCase
{
use TestTrait;
Expand Down Expand Up @@ -142,9 +139,6 @@ public function testAddDefaultValue(): void

/**
* @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::addForeignKey
*
* @throws Exception
* @throws InvalidArgumentException
*/
public function testAddForeignKey(
string $name,
Expand Down
5 changes: 2 additions & 3 deletions tests/AbstractQueryGetTableAliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ abstract class AbstractQueryGetTableAliasTest extends TestCase
{
use TestTrait;

/**
* @throws InvalidArgumentException
*/
public function testAliasesFromString(): void
{
$db = $this->getConnection();
Expand All @@ -25,6 +22,8 @@ public function testAliasesFromString(): void
$query->from('profile AS \'prf\', user "usr", service srv, order, [a b] [c d], {{something}} AS myalias');
$tables = $query->getTablesUsedInFrom();

$db->close();

$this->assertSame(
[
'{{prf}}' => '{{profile}}',
Expand Down
4 changes: 4 additions & 0 deletions tests/AbstractQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ public function testColumnWithIndexBy(): void
->where(['id' => null]);

$this->assertSame([], $query->column());

$db->close();
}

/**
Expand Down Expand Up @@ -853,5 +855,7 @@ public function testResultCallback(): void
$query->resultCallback(null);

$this->assertNull($query->getResultCallback());

$db->close();
}
}
6 changes: 6 additions & 0 deletions tests/AbstractSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function testGetDefaultSchema(): void

$schema = $db->getSchema();

$db->close();

$this->assertSame('', $schema->getDefaultSchema());
}

Expand All @@ -44,6 +46,8 @@ public function testGetDataType(): void

$schema = $db->getSchema();

$db->close();

foreach ($values as $value) {
$this->assertSame(
$value[1],
Expand All @@ -62,6 +66,8 @@ public function testRefresh(): void
$schema = $db->getSchema();
$schema->refresh();

$db->close();

$this->assertSame([], Assert::getPropertyValue($schema, 'tableMetadata'));
$this->assertSame([], Assert::getPropertyValue($schema, 'tableNames'));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Common/CommonBatchQueryResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function testBatchWithoutDbParameter(): void
$query = $query->from('customer')->orderBy('id')->limit(3);
$customers = $this->getAllRowsFromBatch($query->batch(2));

$db->close();

$this->assertCount(3, $customers);
$this->assertEquals('user1', $customers[0]['name']);
$this->assertEquals('user2', $customers[1]['name']);
Expand Down Expand Up @@ -161,6 +163,8 @@ public function testBatchQueryResultWithoutPopulate(): void

$customers = $this->getAllRowsFromBatch($batchQueryResult);

$db->close();

$this->assertCount(3, $customers);
$this->assertEquals('user1', $customers[0]['name']);
$this->assertEquals('user2', $customers[1]['name']);
Expand Down
2 changes: 2 additions & 0 deletions tests/Common/CommonQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ public function testMultiOperandFunctionBuilder(
sort($result, SORT_NATURAL);
}

$db->close();

$this->assertEquals($expectedResult, $result);
}

Expand Down
Loading
Loading