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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"vimeo/psalm": "^5.26.1 || ^6.8.8",
"vlucas/phpdotenv": "^5.6.1",
"yiisoft/aliases": "^2.0",
"yiisoft/cache-file": "^3.2",
"yiisoft/psr-dummy-provider": "^1.0",
"yiisoft/test-support": "^3.0",
"yiisoft/var-dumper": "^1.7"
},
"provide": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

namespace Yiisoft\Db\Mssql\Tests\Builder;

use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Mssql\Builder\InBuilder;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\QueryBuilder\Condition\In;
use Yiisoft\Db\Tests\Support\IntegrationTestCase;

/**
* @group mssql
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class InconditionBuilderTest extends TestCase
final class InConditionBuilderTest extends IntegrationTestCase
{
use TestTrait;
use IntegrationTestTrait;

public function testBuildSubqueryInCondition(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();

$inCondition = new In(
['id'],
(new Query($db))->select('id')->from('users')->where(['active' => 1]),
Expand Down
7 changes: 2 additions & 5 deletions tests/ColumnBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Mssql\Tests\Provider\ColumnBuilderProvider;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\AbstractColumnBuilderTest;
use Yiisoft\Db\Tests\Common\CommonColumnBuilderTest;

/**
* @group mssql
*/
class ColumnBuilderTest extends AbstractColumnBuilderTest
class ColumnBuilderTest extends CommonColumnBuilderTest
{
use TestTrait;

#[DataProviderExternal(ColumnBuilderProvider::class, 'buildingMethods')]
public function testBuildingMethods(
string $buildingMethod,
Expand Down
7 changes: 2 additions & 5 deletions tests/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Mssql\Tests\Provider\ColumnFactoryProvider;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Tests\AbstractColumnFactoryTest;
use Yiisoft\Db\Tests\Common\CommonColumnFactoryTest;

/**
* @group mssql
*/
final class ColumnFactoryTest extends AbstractColumnFactoryTest
final class ColumnFactoryTest extends CommonColumnFactoryTest
{
use TestTrait;

#[DataProviderExternal(ColumnFactoryProvider::class, 'dbTypes')]
public function testFromDbType(string $dbType, string $expectedType, string $expectedInstanceOf): void
{
Expand Down
15 changes: 11 additions & 4 deletions tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Yiisoft\Db\Expression\Value\Param;
use Yiisoft\Db\Mssql\Column\BinaryColumn;
use Yiisoft\Db\Mssql\Tests\Provider\ColumnProvider;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Schema\Column\BooleanColumn;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\Column\DoubleColumn;
Expand All @@ -30,11 +30,11 @@
*/
final class ColumnTest extends CommonColumnTest
{
use TestTrait;
use IntegrationTestTrait;

public function testSelectWithPhpTypecasting(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();

$sql = "SELECT null AS [null], 1 AS [1], 2.5 AS [2.5], 'string' AS [string]";

Expand Down Expand Up @@ -80,7 +80,9 @@ public function testSelectWithPhpTypecasting(): void

public function testColumnInstance()
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$schema = $db->getSchema();
$tableSchema = $schema->getTableSchema('type');

Expand Down Expand Up @@ -163,4 +165,9 @@ protected function assertTypecastedValues(array $result, bool $allTypecasted = f
$this->assertSame('[{"a":1,"b":null,"c":[1,3,5]}]', $result['json_col']);
}
}

protected function createTimestampDefaultValue(): mixed
{
return new Expression('getdate()');
}
}
65 changes: 40 additions & 25 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Db\Mssql\Tests;

use Closure;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Constraint\Index;
use Yiisoft\Db\Exception\IntegrityException;
Expand All @@ -13,7 +14,8 @@
use Yiisoft\Db\Mssql\Column\ColumnBuilder;
use Yiisoft\Db\Mssql\IndexType;
use Yiisoft\Db\Mssql\Tests\Provider\CommandProvider;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Mssql\Tests\Support\TestConnection;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Tests\Common\CommonCommandTest;

Expand All @@ -25,13 +27,12 @@
*/
final class CommandTest extends CommonCommandTest
{
use TestTrait;

protected string $upsertTestCharCast = 'CAST([[address]] AS VARCHAR(255))';
use IntegrationTestTrait;

public function testAlterColumn(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();
$command->alterColumn('{{customer}}', 'email', 'ntext')->execute();
Expand All @@ -44,7 +45,7 @@ public function testAlterColumn(): void

public function testCheckIntegrity(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();

$command = $db->createCommand();
$command->checkIntegrity('{{dbo}}', '{{customer}}');
Expand All @@ -60,7 +61,8 @@ public function testCheckIntegrity(): void

public function testCheckIntegrityExecuteException(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();
$command->checkIntegrity('{{dbo}}', '{{T_constraints_3}}', false)->execute();
Expand All @@ -84,7 +86,8 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql
#[DataProviderExternal(CommandProvider::class, 'dataInsertVarbinary')]
public function testInsertVarbinary(mixed $expectedData, mixed $testData): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();

Expand All @@ -99,7 +102,8 @@ public function testInsertVarbinary(mixed $expectedData, mixed $testData): void

public function testInsertReturningPksWithComputedColumn(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();
$command->setSql(
Expand Down Expand Up @@ -132,7 +136,8 @@ public function testInsertReturningPksWithComputedColumn(): void

public function testInsertReturningPksWithRowVersionColumn(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();
$command->setSql(
Expand All @@ -148,7 +153,8 @@ public function testInsertReturningPksWithRowVersionColumn(): void

public function testInsertReturningPksWithRowVersionNullColumn(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();
$command->setSql(
Expand All @@ -167,7 +173,8 @@ public function testInsertReturningPksWithRowVersionNullColumn(): void

public function testResetSequence(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$command = $db->createCommand();
$oldRow = $command->insertReturningPks('{{item}}', ['name' => 'insert_value_for_sequence', 'category_id' => 1]);
Expand All @@ -183,7 +190,7 @@ public function testUpdate(
string $table,
array $columns,
array|ExpressionInterface|string $conditions,
array|ExpressionInterface|string|null $from,
Closure|array|ExpressionInterface|string|null $from,
array $params,
array $expectedValues,
int $expectedCount,
Expand All @@ -198,14 +205,15 @@ public function testUpdate(
}

#[DataProviderExternal(CommandProvider::class, 'upsert')]
public function testUpsert(array $firstData, array $secondData): void
public function testUpsert(Closure|array $firstData, Closure|array $secondData): void
{
parent::testUpsert($firstData, $secondData);
}

public function testQueryScalarWithBlob(): void
{
$db = $this->getConnection(true);
$db = $this->getSharedConnection();
$this->loadFixture();

$value = json_encode(['test'], JSON_THROW_ON_ERROR);
$db->createCommand()->insert('{{%T_upsert_varbinary}}', ['id' => 1, 'blob_col' => $value])->execute();
Expand All @@ -216,7 +224,7 @@ public function testQueryScalarWithBlob(): void

public function testAddDefaultValueSql(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();

$command = $db->createCommand();

Expand All @@ -230,7 +238,7 @@ public function testAddDefaultValueSql(): void

public function testDropDefaultValueSql(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();

$command = $db->createCommand();

Expand All @@ -244,7 +252,7 @@ public function testDropDefaultValueSql(): void

public function testDropTableCascade(): void
{
$command = $this->getConnection()->createCommand();
$command = $this->getSharedConnection()->createCommand();

$this->expectException(NotSupportedException::class);
$this->expectExceptionMessage('MSSQL doesn\'t support cascade drop table.');
Expand All @@ -254,19 +262,21 @@ public function testDropTableCascade(): void
public function testShowDatabases(): void
{
$expectedDatabases = [];
if (self::getDatabaseName() !== 'tempdb') {
$expectedDatabases[] = self::getDatabaseName();
if (TestConnection::databaseName() !== 'tempdb') {
$expectedDatabases[] = TestConnection::databaseName();
}

$actualDatabases = self::getDb()->createCommand()->showDatabases();
$actualDatabases = $this->getSharedConnection()->createCommand()->showDatabases();

$this->assertSame($expectedDatabases, $actualDatabases);
}

/** @link https://github.com/yiisoft/db-migration/issues/11 */
/**
* @link https://github.com/yiisoft/db-migration/issues/11
*/
public function testAlterColumnWithDefaultNull()
{
$db = $this->getConnection();
$db = $this->getSharedConnection();
$command = $db->createCommand();

if ($db->getTableSchema('column_with_constraint', true) !== null) {
Expand Down Expand Up @@ -295,7 +305,7 @@ public function testCreateIndex(array $columns, array $indexColumns, ?string $in

public function testCreateClusteredColumnstoreIndex(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();

$command = $db->createCommand();
$schema = $db->getSchema();
Expand All @@ -320,7 +330,7 @@ public function testCreateClusteredColumnstoreIndex(): void

public function testCreateXmlIndex(): void
{
$db = $this->getConnection();
$db = $this->getSharedConnection();
$command = $db->createCommand();
$schema = $db->getSchema();

Expand Down Expand Up @@ -357,4 +367,9 @@ public function testBatchInsert(
): void {
parent::testBatchInsert($table, $values, $columns, $expected, $expectedParams, $insertedRow);
}

protected function getUpsertTestCharCast(): string
{
return 'CAST([[address]] AS VARCHAR(255))';
}
}
Loading
Loading