SchemaBuilderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Illuminate\Tests\Integration\Database;
  3. use Doctrine\DBAL\Types\Type;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Database\Schema\Grammars\SQLiteGrammar;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Schema;
  8. use Illuminate\Tests\Integration\Database\Fixtures\TinyInteger;
  9. class SchemaBuilderTest extends DatabaseTestCase
  10. {
  11. protected function destroyDatabaseMigrations()
  12. {
  13. Schema::dropAllViews();
  14. }
  15. public function testDropAllTables()
  16. {
  17. $this->expectNotToPerformAssertions();
  18. Schema::create('table', function (Blueprint $table) {
  19. $table->increments('id');
  20. });
  21. Schema::dropAllTables();
  22. $this->artisan('migrate:install');
  23. Schema::create('table', function (Blueprint $table) {
  24. $table->increments('id');
  25. });
  26. }
  27. public function testDropAllViews()
  28. {
  29. $this->expectNotToPerformAssertions();
  30. DB::statement('create view foo (id) as select 1');
  31. Schema::dropAllViews();
  32. DB::statement('create view foo (id) as select 1');
  33. }
  34. public function testRegisterCustomDoctrineType()
  35. {
  36. if ($this->driver !== 'sqlite') {
  37. $this->markTestSkipped('Test requires a SQLite connection.');
  38. }
  39. Schema::registerCustomDoctrineType(TinyInteger::class, TinyInteger::NAME, 'TINYINT');
  40. Schema::create('test', function (Blueprint $table) {
  41. $table->string('test_column');
  42. });
  43. $blueprint = new Blueprint('test', function (Blueprint $table) {
  44. $table->tinyInteger('test_column')->change();
  45. });
  46. $blueprint->build($this->getConnection(), new SQLiteGrammar);
  47. $this->assertArrayHasKey(TinyInteger::NAME, Type::getTypesMap());
  48. $this->assertSame('tinyinteger', Schema::getColumnType('test', 'test_column'));
  49. }
  50. public function testRegisterCustomDoctrineTypeASecondTime()
  51. {
  52. if ($this->driver !== 'sqlite') {
  53. $this->markTestSkipped('Test requires a SQLite connection.');
  54. }
  55. Schema::registerCustomDoctrineType(TinyInteger::class, TinyInteger::NAME, 'TINYINT');
  56. Schema::create('test', function (Blueprint $table) {
  57. $table->string('test_column');
  58. });
  59. $blueprint = new Blueprint('test', function (Blueprint $table) {
  60. $table->tinyInteger('test_column')->change();
  61. });
  62. $blueprint->build($this->getConnection(), new SQLiteGrammar);
  63. $this->assertArrayHasKey(TinyInteger::NAME, Type::getTypesMap());
  64. $this->assertSame('tinyinteger', Schema::getColumnType('test', 'test_column'));
  65. }
  66. }