Skip to content

Commit

Permalink
Add test for bit type (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Aug 9, 2023
1 parent b172ec9 commit b4435ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/ColumnSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testPhpTypeCast(): void
'blob_col' => "\x10\x11\x12",
'timestamp_col' => '2023-07-11 14:50:23',
'bool_col' => false,
'bit_col' => 0b0110_0110, // 102
]
);
$command->execute();
Expand All @@ -49,6 +50,7 @@ public function testPhpTypeCast(): void
$blobColPhpType = $tableSchema->getColumn('blob_col')?->phpTypecast($query['blob_col']);
$timestampColPhpType = $tableSchema->getColumn('timestamp_col')?->phpTypecast($query['timestamp_col']);
$boolColPhpType = $tableSchema->getColumn('bool_col')?->phpTypecast($query['bool_col']);
$bitColPhpType = $tableSchema->getColumn('bit_col')?->phpTypecast($query['bit_col']);

$this->assertSame(1, $intColPhpType);
$this->assertSame(str_repeat('x', 100), $charColPhpType);
Expand All @@ -57,6 +59,7 @@ public function testPhpTypeCast(): void
$this->assertSame("\x10\x11\x12", $blobColPhpType);
$this->assertSame('2023-07-11 14:50:23', $timestampColPhpType);
$this->assertFalse($boolColPhpType);
$this->assertSame(0b0110_0110, $bitColPhpType);

$db->close();
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ public static function columns(): array
'scale' => null,
'defaultValue' => new Expression('CURRENT_TIMESTAMP'),
],
'bit_col' => [
'type' => 'smallint',
'dbType' => 'bit(8)',
'phpType' => 'integer',
'primaryKey' => false,
'allowNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 8,
'precision' => 8,
'scale' => null,
'defaultValue' => 0b1000_0010, // 130
],
],
'tableName' => 'type',
],
Expand Down
3 changes: 2 additions & 1 deletion tests/Support/Fixture/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ CREATE TABLE "type" (
timestamp_col timestamp NOT NULL DEFAULT '2002-01-01 00:00:00',
bool_col tinyint(1) NOT NULL,
bool_col2 tinyint(1) DEFAULT '1',
ts_default TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
ts_default TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
bit_col BIT(8) NOT NULL DEFAULT 130 -- 0b1000_0010
);

CREATE TABLE "type_bit" (
Expand Down

0 comments on commit b4435ad

Please sign in to comment.