DatabaseMySqlSchemaBuilderAlterTableWithEnumTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Illuminate\Tests\Integration\Database\MySql;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. use stdClass;
  6. /**
  7. * @requires extension pdo_mysql
  8. * @requires OS Linux|Darwin
  9. */
  10. class DatabaseMySqlSchemaBuilderAlterTableWithEnumTest extends MySqlTestCase
  11. {
  12. protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
  13. {
  14. Schema::create('users', function (Blueprint $table) {
  15. $table->integer('id');
  16. $table->string('name');
  17. $table->string('age');
  18. $table->enum('color', ['red', 'blue']);
  19. });
  20. }
  21. protected function destroyDatabaseMigrations()
  22. {
  23. Schema::drop('users');
  24. }
  25. public function testRenameColumnOnTableWithEnum()
  26. {
  27. Schema::table('users', function (Blueprint $table) {
  28. $table->renameColumn('name', 'username');
  29. });
  30. $this->assertTrue(Schema::hasColumn('users', 'username'));
  31. }
  32. public function testChangeColumnOnTableWithEnum()
  33. {
  34. Schema::table('users', function (Blueprint $table) {
  35. $table->unsignedInteger('age')->charset('')->change();
  36. });
  37. $this->assertSame('integer', Schema::getColumnType('users', 'age'));
  38. }
  39. public function testGetAllTablesAndColumnListing()
  40. {
  41. $tables = Schema::getAllTables();
  42. $this->assertCount(2, $tables);
  43. $tableProperties = array_values((array) $tables[0]);
  44. $this->assertEquals(['migrations', 'BASE TABLE'], $tableProperties);
  45. $this->assertInstanceOf(stdClass::class, $tables[1]);
  46. $tableProperties = array_values((array) $tables[1]);
  47. $this->assertEquals(['users', 'BASE TABLE'], $tableProperties);
  48. $columns = Schema::getColumnListing('users');
  49. foreach (['id', 'name', 'age', 'color'] as $column) {
  50. $this->assertContains($column, $columns);
  51. }
  52. Schema::create('posts', function (Blueprint $table) {
  53. $table->integer('id');
  54. $table->string('title');
  55. });
  56. $tables = Schema::getAllTables();
  57. $this->assertCount(3, $tables);
  58. Schema::drop('posts');
  59. }
  60. }