1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
<?php
namespace Illuminate\Tests\Integration\Database\SchemaTest;
use Doctrine\DBAL\Types\Type;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\SQLiteGrammar;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
use Illuminate\Tests\Integration\Database\Fixtures\TinyInteger;
/**
* @group integration
*/
class SchemaBuilderTest extends DatabaseTestCase
{
public function testDropAllTables()
{
Schema::create('table', function (Blueprint $table) {
$table->increments('id');
});
Schema::dropAllTables();
Schema::create('table', function (Blueprint $table) {
$table->increments('id');
});
$this->assertTrue(true);
}
public function testDropAllViews()
{
DB::statement('create view "view"("id") as select 1');
Schema::dropAllViews();
DB::statement('create view "view"("id") as select 1');
$this->assertTrue(true);
}
public function testRegisterCustomDoctrineType()
{
Schema::registerCustomDoctrineType(TinyInteger::class, TinyInteger::NAME, 'TINYINT');
Schema::create('test', function (Blueprint $table) {
$table->string('test_column');
});
$blueprint = new Blueprint('test', function (Blueprint $table) {
$table->tinyInteger('test_column')->change();
});
$expected = [
'CREATE TEMPORARY TABLE __temp__test AS SELECT test_column FROM test',
'DROP TABLE test',
'CREATE TABLE test (test_column TINYINT NOT NULL)',
'INSERT INTO test (test_column) SELECT test_column FROM __temp__test',
'DROP TABLE __temp__test',
];
$statements = $blueprint->toSql($this->getConnection(), new SQLiteGrammar());
$blueprint->build($this->getConnection(), new SQLiteGrammar());
$this->assertArrayHasKey(TinyInteger::NAME, Type::getTypesMap());
$this->assertSame('tinyinteger', Schema::getColumnType('test', 'test_column'));
$this->assertEquals($expected, $statements);
}
}
|