From 58dca0ca5da183a948bdb41f24b14ee1bc444235 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 10 Apr 2020 17:13:06 +0200 Subject: [PATCH] Add tests. --- tests/Phinx/Db/Adapter/MysqlAdapterTest.php | 34 +++++++++++++++++++ .../Phinx/Db/Adapter/PostgresAdapterTest.php | 34 +++++++++++++++++++ tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 31 +++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php index fabc3be53..6ddd6341e 100644 --- a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php +++ b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php @@ -309,6 +309,40 @@ public function testCreateTableWithMultiplePrimaryKeys() $this->assertFalse($this->adapter->hasIndex('table1', ['tag_id', 'user_email'])); } + /** + * @return void + */ + public function testCreateTableWithPrimaryKeyAsUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'uuid')->save(); + $table->addColumn('user_id', 'integer')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + $this->assertTrue($this->adapter->hasColumn('ztable', 'user_id')); + } + + /** + * @return void + */ + public function testCreateTableWithPrimaryKeyAsBinaryUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'binaryuuid')->save(); + $table->addColumn('user_id', 'integer')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + $this->assertTrue($this->adapter->hasColumn('ztable', 'user_id')); + } + public function testCreateTableWithMultipleIndexes() { $table = new \Phinx\Db\Table('table1', [], $this->adapter); diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 54217c511..03a7a3e45 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -294,6 +294,40 @@ public function testCreateTableWithMultiplePrimaryKeysWithSchema() $this->adapter->dropSchema('schema1'); } + /** + * @return void + */ + public function testCreateTableWithPrimaryKeyAsUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'uuid')->save(); + $table->addColumn('user_id', 'integer')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + $this->assertTrue($this->adapter->hasColumn('ztable', 'user_id')); + } + + /** + * @return void + */ + public function testCreateTableWithPrimaryKeyAsBinaryUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'binaryuuid')->save(); + $table->addColumn('user_id', 'integer')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + $this->assertTrue($this->adapter->hasColumn('ztable', 'user_id')); + } + public function testCreateTableWithMultipleIndexes() { $table = new \Phinx\Db\Table('table1', [], $this->adapter); diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index dcdfa2c9a..20be247df 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -201,6 +201,36 @@ public function testCreateTableWithMultiplePrimaryKeys() $this->assertFalse($this->adapter->hasIndex('table1', ['tag_id', 'user_email'])); } + /** + * @return void + */ + public function testCreateTableWithPrimaryKeyAsUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'uuid')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + } + + /** + * @return void + */ + public function testCreateTableWithPrimaryKeyAsBinaryUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'binaryuuid')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + } + public function testCreateTableWithMultipleIndexes() { $table = new \Phinx\Db\Table('table1', [], $this->adapter); @@ -1649,6 +1679,7 @@ public function testGetColumnTypes() SQLiteAdapter::PHINX_TYPE_TEXT, SQLiteAdapter::PHINX_TYPE_TIME, SQLiteAdapter::PHINX_TYPE_UUID, + SQLiteAdapter::PHINX_TYPE_BINARYUUID, SQLiteAdapter::PHINX_TYPE_TIMESTAMP, SQLiteAdapter::PHINX_TYPE_VARBINARY, ];