CreateTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace Medoo\Tests;
  3. /**
  4. * @coversDefaultClass \Medoo\Medoo
  5. */
  6. class CreateTest extends MedooTestCase
  7. {
  8. /**
  9. * @covers ::create()
  10. * @dataProvider typesProvider
  11. */
  12. public function testCreate($type)
  13. {
  14. $this->setType($type);
  15. $this->database->create("account", [
  16. "id" => [
  17. "INT",
  18. "NOT NULL",
  19. "AUTO_INCREMENT"
  20. ],
  21. "email" => [
  22. "VARCHAR(70)",
  23. "NOT NULL",
  24. "UNIQUE"
  25. ],
  26. "PRIMARY KEY (<id>)"
  27. ], [
  28. "AUTO_INCREMENT" => 200
  29. ]);
  30. $this->assertQuery(
  31. [
  32. 'default' => <<<EOD
  33. CREATE TABLE IF NOT EXISTS "account"
  34. ("id" INT NOT NULL AUTO_INCREMENT,
  35. "email" VARCHAR(70) NOT NULL UNIQUE,
  36. PRIMARY KEY ("id"))
  37. AUTO_INCREMENT = 200
  38. EOD,
  39. 'mssql' => <<<EOD
  40. CREATE TABLE [account]
  41. ([id] INT NOT NULL AUTO_INCREMENT,
  42. [email] VARCHAR(70) NOT NULL UNIQUE,
  43. PRIMARY KEY ([id]))
  44. AUTO_INCREMENT = 200
  45. EOD,
  46. 'oracle' => <<<EOD
  47. CREATE TABLE "account"
  48. ("id" INT NOT NULL AUTO_INCREMENT,
  49. "email" VARCHAR(70) NOT NULL UNIQUE,
  50. PRIMARY KEY ("id"))
  51. AUTO_INCREMENT = 200
  52. EOD
  53. ],
  54. $this->database->queryString
  55. );
  56. }
  57. /**
  58. * @covers ::create()
  59. * @dataProvider typesProvider
  60. */
  61. public function testCreateWithStringDefinition($type)
  62. {
  63. $this->setType($type);
  64. $this->database->create("account", [
  65. "id" => "INT NOT NULL AUTO_INCREMENT",
  66. "email" => "VARCHAR(70) NOT NULL UNIQUE"
  67. ]);
  68. $this->assertQuery(
  69. [
  70. 'default' => <<<EOD
  71. CREATE TABLE IF NOT EXISTS "account"
  72. ("id" INT NOT NULL AUTO_INCREMENT,
  73. "email" VARCHAR(70) NOT NULL UNIQUE)
  74. EOD,
  75. 'mssql' => <<<EOD
  76. CREATE TABLE [account]
  77. ([id] INT NOT NULL AUTO_INCREMENT,
  78. [email] VARCHAR(70) NOT NULL UNIQUE)
  79. EOD,
  80. 'oracle' => <<<EOD
  81. CREATE TABLE "account"
  82. ("id" INT NOT NULL AUTO_INCREMENT,
  83. "email" VARCHAR(70) NOT NULL UNIQUE)
  84. EOD
  85. ],
  86. $this->database->queryString
  87. );
  88. }
  89. /**
  90. * @covers ::create()
  91. * @dataProvider typesProvider
  92. */
  93. public function testCreateWithSingleOption($type)
  94. {
  95. $this->setType($type);
  96. $this->database->create("account", [
  97. "id" => [
  98. "INT",
  99. "NOT NULL",
  100. "AUTO_INCREMENT"
  101. ],
  102. "email" => [
  103. "VARCHAR(70)",
  104. "NOT NULL",
  105. "UNIQUE"
  106. ]
  107. ], "TABLESPACE tablespace_name");
  108. $this->assertQuery(
  109. [
  110. 'default' => <<<EOD
  111. CREATE TABLE IF NOT EXISTS "account"
  112. ("id" INT NOT NULL AUTO_INCREMENT,
  113. "email" VARCHAR(70) NOT NULL UNIQUE)
  114. TABLESPACE tablespace_name
  115. EOD,
  116. 'mssql' => <<<EOD
  117. CREATE TABLE [account]
  118. ([id] INT NOT NULL AUTO_INCREMENT,
  119. [email] VARCHAR(70) NOT NULL UNIQUE)
  120. TABLESPACE tablespace_name
  121. EOD,
  122. 'oracle' => <<<EOD
  123. CREATE TABLE "account"
  124. ("id" INT NOT NULL AUTO_INCREMENT,
  125. "email" VARCHAR(70) NOT NULL UNIQUE)
  126. TABLESPACE tablespace_name
  127. EOD
  128. ],
  129. $this->database->queryString
  130. );
  131. }
  132. }