Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hind-sagar-biswas committed Nov 5, 2023
1 parent 76894f5 commit 6945e28
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Table/Traits/AutoIncrement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ trait AutoIncrement
public function ai(): self
{
$this->ai = true;
$this->nullable();
return $this;
}
}
4 changes: 2 additions & 2 deletions tests/Column/FullTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class FullTableTest extends TestCase
{
public function test_basic_users_table_build()
{
$expected = "CREATE TABLE IF NOT EXISTS users (`id` INT(11) UNSIGNED NULL AUTO_INCREMENT, `username` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `is_superadmin` INT(2) NOT NULL DEFAULT '0', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIME, `update_time` DATETIME on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIME, CONSTRAINT users_PK PRIMARY KEY (id), CONSTRAINT username_UC UNIQUE (`username`), CONSTRAINT email_UC UNIQUE (`email`)) ENGINE = InnoDB;";
$expected = "CREATE TABLE IF NOT EXISTS users (`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `is_superadmin` INT(2) NOT NULL DEFAULT '0', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIME, `update_time` DATETIME on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIME, CONSTRAINT users_PK PRIMARY KEY (id), CONSTRAINT username_UC UNIQUE (`username`), CONSTRAINT email_UC UNIQUE (`email`)) ENGINE = InnoDB;";

$query = Table::create('users')->columns([
'id' => Col::integer(11)->unsigned()->pk()->ai(),
Expand All @@ -29,7 +29,7 @@ public function test_basic_users_table_build()

public function test_table_with_foreign_keys_build()
{
$expected = "CREATE TABLE IF NOT EXISTS tokens (`id` INT UNSIGNED NULL AUTO_INCREMENT, `selector` VARCHAR(255) NOT NULL, `hashed_validator` VARCHAR(255) NOT NULL, `user_id` INT(11) UNSIGNED NOT NULL, `expiry` DATETIME NOT NULL, CONSTRAINT tokens_PK PRIMARY KEY (id), FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE) ENGINE = InnoDB;";
$expected = "CREATE TABLE IF NOT EXISTS tokens (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `selector` VARCHAR(255) NOT NULL, `hashed_validator` VARCHAR(255) NOT NULL, `user_id` INT(11) UNSIGNED NOT NULL, `expiry` DATETIME NOT NULL, CONSTRAINT tokens_PK PRIMARY KEY (id), FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE) ENGINE = InnoDB;";

$user = Table::create('users')->columns([
'id' => Col::integer(11)->unsigned()->pk()->ai(),
Expand Down
5 changes: 5 additions & 0 deletions tests/Column/IntegerColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function test_integer_column_build()
$query = Col::integer()->build('column');
$this->assertSame($expected, $query);

/// Basic INT column
$expected = "`column` INT NOT NULL AUTO_INCREMENT";
$query = Col::integer()->ai()->build('column');
$this->assertSame($expected, $query);

/// length specified zerofill INT column
$expected = "`column` INT(11) ZEROFILL NOT NULL";
$query = Col::integer(11)->zerofill()->build('column');
Expand Down

0 comments on commit 6945e28

Please sign in to comment.