123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace Medoo\Tests;
- /**
- * @coversDefaultClass \Medoo\Medoo
- */
- class CreateTest extends MedooTestCase
- {
- /**
- * @covers ::create()
- * @dataProvider typesProvider
- */
- public function testCreate($type)
- {
- $this->setType($type);
- $this->database->create("account", [
- "id" => [
- "INT",
- "NOT NULL",
- "AUTO_INCREMENT"
- ],
- "email" => [
- "VARCHAR(70)",
- "NOT NULL",
- "UNIQUE"
- ],
- "PRIMARY KEY (<id>)"
- ], [
- "AUTO_INCREMENT" => 200
- ]);
- $this->assertQuery(
- [
- 'default' => <<<EOD
- CREATE TABLE IF NOT EXISTS "account"
- ("id" INT NOT NULL AUTO_INCREMENT,
- "email" VARCHAR(70) NOT NULL UNIQUE,
- PRIMARY KEY ("id"))
- AUTO_INCREMENT = 200
- EOD,
- 'mssql' => <<<EOD
- CREATE TABLE [account]
- ([id] INT NOT NULL AUTO_INCREMENT,
- [email] VARCHAR(70) NOT NULL UNIQUE,
- PRIMARY KEY ([id]))
- AUTO_INCREMENT = 200
- EOD,
- 'oracle' => <<<EOD
- CREATE TABLE "account"
- ("id" INT NOT NULL AUTO_INCREMENT,
- "email" VARCHAR(70) NOT NULL UNIQUE,
- PRIMARY KEY ("id"))
- AUTO_INCREMENT = 200
- EOD
- ],
- $this->database->queryString
- );
- }
- /**
- * @covers ::create()
- * @dataProvider typesProvider
- */
- public function testCreateWithStringDefinition($type)
- {
- $this->setType($type);
- $this->database->create("account", [
- "id" => "INT NOT NULL AUTO_INCREMENT",
- "email" => "VARCHAR(70) NOT NULL UNIQUE"
- ]);
- $this->assertQuery(
- [
- 'default' => <<<EOD
- CREATE TABLE IF NOT EXISTS "account"
- ("id" INT NOT NULL AUTO_INCREMENT,
- "email" VARCHAR(70) NOT NULL UNIQUE)
- EOD,
- 'mssql' => <<<EOD
- CREATE TABLE [account]
- ([id] INT NOT NULL AUTO_INCREMENT,
- [email] VARCHAR(70) NOT NULL UNIQUE)
- EOD,
- 'oracle' => <<<EOD
- CREATE TABLE "account"
- ("id" INT NOT NULL AUTO_INCREMENT,
- "email" VARCHAR(70) NOT NULL UNIQUE)
- EOD
- ],
- $this->database->queryString
- );
- }
- /**
- * @covers ::create()
- * @dataProvider typesProvider
- */
- public function testCreateWithSingleOption($type)
- {
- $this->setType($type);
- $this->database->create("account", [
- "id" => [
- "INT",
- "NOT NULL",
- "AUTO_INCREMENT"
- ],
- "email" => [
- "VARCHAR(70)",
- "NOT NULL",
- "UNIQUE"
- ]
- ], "TABLESPACE tablespace_name");
- $this->assertQuery(
- [
- 'default' => <<<EOD
- CREATE TABLE IF NOT EXISTS "account"
- ("id" INT NOT NULL AUTO_INCREMENT,
- "email" VARCHAR(70) NOT NULL UNIQUE)
- TABLESPACE tablespace_name
- EOD,
- 'mssql' => <<<EOD
- CREATE TABLE [account]
- ([id] INT NOT NULL AUTO_INCREMENT,
- [email] VARCHAR(70) NOT NULL UNIQUE)
- TABLESPACE tablespace_name
- EOD,
- 'oracle' => <<<EOD
- CREATE TABLE "account"
- ("id" INT NOT NULL AUTO_INCREMENT,
- "email" VARCHAR(70) NOT NULL UNIQUE)
- TABLESPACE tablespace_name
- EOD
- ],
- $this->database->queryString
- );
- }
- }
|