Skip to content

Commit

Permalink
Fix psalm issue, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Aug 13, 2024
1 parent 04d9207 commit a010e68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Schema/Column/ColumnSchemaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* table?: string|null,
* type?: string,
* unsigned?: bool|string,
* ...
* }
*/
interface ColumnSchemaInterface
Expand Down
14 changes: 14 additions & 0 deletions tests/AbstractColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Db\Tests;

use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
use Yiisoft\Db\Tests\Support\TestTrait;

abstract class AbstractColumnFactoryTest extends TestCase
Expand Down Expand Up @@ -56,4 +57,17 @@ public function testFromType(string $type, string $expectedType, string $expecte
$this->assertInstanceOf($expectedInstanceOf, $column);
$this->assertSame($expectedType, $column->getType());
}

public function testFromDefinitionWithExtra(): void
{
$db = $this->getConnection();
$factory = $db->getSchema()->getColumnFactory();

$column = $factory->fromDefinition('char(1) NOT NULL', ['extra' => 'UNIQUE']);

$this->assertInstanceOf(StringColumnSchema::class, $column);
$this->assertSame('char', $column->getType());
$this->assertSame(1, $column->getSize());
$this->assertSame('NOT NULL UNIQUE', $column->getExtra());
}
}
4 changes: 4 additions & 0 deletions tests/Provider/ColumnSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ public static function load(): array
['name', null, 'getName', null],
['precision', 10, 'getPrecision', 10],
['precision', null, 'getPrecision', null],
['primary_key', true, 'isPrimaryKey', true],
['primary_key', false, 'isPrimaryKey', false],
['primary_key', '1', 'isPrimaryKey', true],
['primary_key', '0', 'isPrimaryKey', false],
['scale', 2, 'getScale', 2],
['scale', null, 'getScale', null],
['size', 255, 'getSize', 255],
Expand Down

0 comments on commit a010e68

Please sign in to comment.