Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test cases typo fixed & missing PHPDocs added. #324

Closed
wants to merge 1 commit into from
Closed
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: 3 additions & 0 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ protected function buildCommentString(): string
return ' COMMENT ' . (string) (new Quoter('`', '`'))->quoteValue($this->getComment());
}

/**
* @return string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since it's obvious from return type and there's no custom description.

*/
public function asString(): string
{
$format = match ($this->getTypeCategory()) {
Expand Down
18 changes: 17 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
*/
final class Command extends AbstractPdoCommand
{
/**
* @param string $table
* @param array $columns
* @return bool|array

Check failure on line 18 in src/Command.php

View workflow job for this annotation

GitHub Actions / PHP 8.0

ImplementedReturnTypeMismatch

src/Command.php:18:16: ImplementedReturnTypeMismatch: The inherited return type 'array<array-key, mixed>|false' for Yiisoft\Db\Command\CommandInterface::insertWithReturningPks is different to the implemented return type for Yiisoft\Db\Mysql\Command::insertwithreturningpks 'array<array-key, mixed>|bool' (see https://psalm.dev/123)

Check failure on line 18 in src/Command.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

ImplementedReturnTypeMismatch

src/Command.php:18:16: ImplementedReturnTypeMismatch: The inherited return type 'array<array-key, mixed>|false' for Yiisoft\Db\Command\CommandInterface::insertWithReturningPks is different to the implemented return type for Yiisoft\Db\Mysql\Command::insertwithreturningpks 'array<array-key, mixed>|bool' (see https://psalm.dev/123)

Check failure on line 18 in src/Command.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

ImplementedReturnTypeMismatch

src/Command.php:18:16: ImplementedReturnTypeMismatch: The inherited return type 'array<array-key, mixed>|false' for Yiisoft\Db\Command\CommandInterface::insertWithReturningPks is different to the implemented return type for Yiisoft\Db\Mysql\Command::insertwithreturningpks 'array<array-key, mixed>|bool' (see https://psalm.dev/123)
* @throws \Throwable
* @throws \Yiisoft\Db\Exception\Exception
* @throws \Yiisoft\Db\Exception\InvalidArgumentException
* @throws \Yiisoft\Db\Exception\InvalidCallException
* @throws \Yiisoft\Db\Exception\InvalidConfigException
* @throws \Yiisoft\Db\Exception\NotSupportedException
*/
public function insertWithReturningPks(string $table, array $columns): bool|array
{
$params = [];
Expand All @@ -29,7 +40,7 @@

foreach ($tablePrimaryKeys as $name) {
if ($tableSchema?->getColumn($name)?->isAutoIncrement()) {
$result[$name] = $this->db->getLastInsertID((string) $tableSchema?->getSequenceName());
$result[$name] = $this->db->getLastInsertID((string)$tableSchema?->getSequenceName());
continue;
}

Expand All @@ -40,6 +51,11 @@
return $result;
}

/**
* @return array
* @throws \Throwable
* @throws \Yiisoft\Db\Exception\Exception
*/
public function showDatabases(): array
{
$sql = <<<SQL
Expand Down
17 changes: 17 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
final class Connection extends AbstractPdoConnection
{
/**
* @return void
*/
public function close(): void
{
if ($this->pdo !== null) {
Expand All @@ -39,6 +42,11 @@ public function close(): void
}
}

/**
* @param string|null $sql
* @param array $params
* @return PdoCommandInterface
*/
public function createCommand(string $sql = null, array $params = []): PdoCommandInterface
{
$command = new Command($this);
Expand All @@ -63,6 +71,9 @@ public function createTransaction(): TransactionInterface
return new Transaction($this);
}

/**
* @return QueryBuilderInterface
*/
public function getQueryBuilder(): QueryBuilderInterface
{
if ($this->queryBuilder === null) {
Expand All @@ -75,6 +86,9 @@ public function getQueryBuilder(): QueryBuilderInterface
return $this->queryBuilder;
}

/**
* @return QuoterInterface
*/
public function getQuoter(): QuoterInterface
{
if ($this->quoter === null) {
Expand All @@ -84,6 +98,9 @@ public function getQuoter(): QuoterInterface
return $this->quoter;
}

/**
* @return SchemaInterface
*/
public function getSchema(): SchemaInterface
{
if ($this->schema === null) {
Expand Down
6 changes: 6 additions & 0 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
final class Driver extends AbstractPdoDriver
{
/**
* @return PDO
*/
public function createConnection(): PDO
{
$this->attributes += [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
Expand All @@ -35,6 +38,9 @@ public function createConnection(): PDO
return $pdo;
}

/**
* @return string
*/
public function getDriverName(): string
{
return 'mysql';
Expand Down
4 changes: 4 additions & 0 deletions src/Quoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
final class Quoter extends BaseQuoter
{
/**
* @param mixed $value
* @return mixed
*/
public function quoteValue(mixed $value): mixed
{
if (!is_string($value)) {
Expand Down
8 changes: 8 additions & 0 deletions tests/ColumnSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public function testPhpTypeCastJson(): void
$this->assertSame(['a' => 1], $columnSchema->phpTypeCast('{"a":1}'));
}

/**
* @return void
* @throws Exception
* @throws Throwable
* @throws \Yiisoft\Db\Exception\InvalidArgumentException
* @throws \Yiisoft\Db\Exception\InvalidConfigException
* @throws \Yiisoft\Db\Exception\NotSupportedException
*/
public function testPhpTypeCast(): void
{
$db = $this->getConnection(true);
Expand Down
26 changes: 16 additions & 10 deletions tests/PdoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonPdoConnectionTest;

Expand Down Expand Up @@ -93,18 +94,23 @@ public function testGetLastInsertID(): void
$this->assertSame('0', $db->getLastInsertID());
}

public function testTransactionAutocommit()
/**
* @return void
* @throws Throwable
*/
public function testTransactionAutocommit(): void
{
$db = $this->getConnection(true);
$db->transaction(function (PdoConnectionInterface $db) {
$this->assertTrue($db->getTransaction()->isActive());

// create table will cause the transaction to be implicitly committed
// (see https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html)
$name = 'test_implicit_transaction_table';
$db->createCommand()->createTable($name, ['id' => 'pk'])->execute();
$db->createCommand()->dropTable($name)->execute();
});
$db->transaction(
function (PdoConnectionInterface $db) {
$this->assertTrue($db->getTransaction()->isActive());

// create table will cause the transaction to be implicitly committed
// (see https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html)
$name = 'test_implicit_transaction_table';
$db->createCommand()->createTable($name, ['id' => 'pk'])->execute();
$db->createCommand()->dropTable($name)->execute();
});
// If we made it this far without an error, then everything's working
}
}
6 changes: 6 additions & 0 deletions tests/Provider/ColumnSchemaBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ final class ColumnSchemaBuilderProvider extends \Yiisoft\Db\Tests\Provider\Colum
{
protected static string $driverName = 'mysql';

/**
* @return array
*/
public static function types(): array
{
$types = parent::types();
Expand Down Expand Up @@ -39,6 +42,9 @@ public static function types(): array
);
}

/**
* @return array
*/
public static function createColumnTypes(): array
{
$types = parent::createColumnTypes();
Expand Down
9 changes: 9 additions & 0 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ final class SchemaProvider extends \Yiisoft\Db\Tests\Provider\SchemaProvider
{
use TestTrait;

/**
* @return array
*/
public static function columns(): array
{
return [
Expand Down Expand Up @@ -375,6 +378,9 @@ public static function columnsTypeBit(): array
];
}

/**
* @return array
*/
public static function constraints(): array
{
$constraints = parent::constraints();
Expand All @@ -388,6 +394,9 @@ public static function constraints(): array
return $constraints;
}

/**
* @return array[]
*/
public static function tableSchemaWithDbSchemes(): array
{
return [
Expand Down
33 changes: 28 additions & 5 deletions tests/QueryBuilderJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ final class QueryBuilderJsonTest extends TestCase
{
use TestTrait;

public function testAlterColumn()
/**
* @return void
*/
public function testAlterColumn(): void
{
$qb = $this->getConnection()->getQueryBuilder();
$columnSchemaBuilder = new Column(SchemaInterface::TYPE_JSON);
Expand All @@ -33,7 +36,10 @@ public function testAlterColumn()
);
}

public function testAddColumn()
/**
* @return void
*/
public function testAddColumn(): void
{
$qb = $this->getConnection()->getQueryBuilder();
$columnSchemaBuilder = new Column(SchemaInterface::TYPE_JSON);
Expand All @@ -47,7 +53,10 @@ public function testAddColumn()
);
}

public function testCreateTable()
/**
* @return void
*/
public function testCreateTable(): void
{
$qb = $this->getConnection()->getQueryBuilder();
$columnSchemaBuilder = new Column(SchemaInterface::TYPE_JSON);
Expand All @@ -63,7 +72,14 @@ public function testCreateTable()
);
}

public function testInsertAndSelect()
/**
* @return void
* @throws \Yiisoft\Db\Exception\Exception
* @throws \Yiisoft\Db\Exception\InvalidArgumentException
* @throws \Yiisoft\Db\Exception\InvalidConfigException
* @throws \Yiisoft\Db\Exception\NotSupportedException
*/
public function testInsertAndSelect(): void
{
$db = $this->getConnection(true);

Expand All @@ -77,7 +93,14 @@ public function testInsertAndSelect()
);
}

public function testInsertJsonExpresionAndSelect()
/**
* @return void
* @throws \Yiisoft\Db\Exception\Exception
* @throws \Yiisoft\Db\Exception\InvalidArgumentException
* @throws \Yiisoft\Db\Exception\InvalidConfigException
* @throws \Yiisoft\Db\Exception\NotSupportedException
*/
public function testInsertJsonExpressionAndSelect(): void
{
$db = $this->getConnection(true);

Expand Down
10 changes: 9 additions & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ final class QueryBuilderTest extends CommonQueryBuilderTest
{
use TestTrait;

public function testAddcheck(): void
/**
* @return void
*/
public function testAddCheck(): void
{
$db = $this->getConnection();

Expand All @@ -40,7 +43,9 @@ public function testAddcheck(): void
}

/**
* @return void
* @throws Exception
* @throws InvalidConfigException
*/
public function testAddCommentOnColumn(): void
{
Expand All @@ -65,6 +70,7 @@ public function testAddCommentOnColumn(): void
}

/**
* @return void
* @throws Exception
*/
public function testAddCommentOnTable(): void
Expand All @@ -83,7 +89,9 @@ public function testAddCommentOnTable(): void
}

/**
* @return void
* @throws Exception
* @throws NotSupportedException
*/
public function testAddDefaultValue(): void
{
Expand Down
16 changes: 13 additions & 3 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testLimitOffsetWithExpression(): void

$query = (new Query($db))->from('customer')->select('id')->orderBy('id');

/* In MySQL limit and offset arguments must both be non negative integer constant */
/* In MySQL limit and offset arguments must both be non-negative integer constant */
$query->limit(new Expression('2'))->offset(new Expression('1'));

$result = $query->column();
Expand All @@ -82,7 +82,12 @@ public function testLimitOffsetWithExpression(): void
$this->assertNotContains('1', $result);
}

public function testWithQuery()
/**
* @return void
* @throws Exception
* @throws InvalidConfigException
*/
public function testWithQuery(): void
{
$db = $this->getConnection();

Expand All @@ -96,7 +101,12 @@ public function testWithQuery()
parent::testWithQuery();
}

public function testWithQueryRecursive()
/**
* @return void
* @throws Exception
* @throws InvalidConfigException
*/
public function testWithQueryRecursive(): void
{
$db = $this->getConnection();

Expand Down
3 changes: 3 additions & 0 deletions tests/QuoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function testQuoteTableName(string $tableName, string $expected): void
parent::testQuoteTableName($tableName, $expected);
}

/**
* @return void
*/
public function testQuoteValue(): void
{
$db = $this->getConnection();
Expand Down
Loading
Loading