diff --git a/.github/workflows/databases.yml b/.github/workflows/databases.yml new file mode 100644 index 000000000000..e74c19469d1f --- /dev/null +++ b/.github/workflows/databases.yml @@ -0,0 +1,90 @@ +name: databases + +on: [push, pull_request] + +jobs: + mysql_57: + runs-on: ubuntu-20.04 + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: forge + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + strategy: + fail-fast: true + + name: MySQL 5.7 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit tests/Integration/Database --verbose + env: + DB_CONNECTION: mysql + DB_USERNAME: root + + mysql_8: + runs-on: ubuntu-20.04 + + services: + mysql: + image: mysql:8 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: forge + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + strategy: + fail-fast: true + + name: MySQL 8.0 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit tests/Integration/Database --verbose + env: + DB_CONNECTION: mysql + DB_USERNAME: root diff --git a/tests/Integration/Database/DatabaseEmulatePreparesMySqlConnectionTest.php b/tests/Integration/Database/DatabaseEmulatePreparesMySqlConnectionTest.php index f61aa136d5b0..46a2b20f904f 100755 --- a/tests/Integration/Database/DatabaseEmulatePreparesMySqlConnectionTest.php +++ b/tests/Integration/Database/DatabaseEmulatePreparesMySqlConnectionTest.php @@ -12,8 +12,8 @@ class DatabaseEmulatePreparesMySqlConnectionTest extends DatabaseMySqlConnection { protected function getEnvironmentSetUp($app) { - $app['config']->set('app.debug', 'true'); - $app['config']->set('database.default', 'mysql'); + parent::getEnvironmentSetUp($app); + $app['config']->set('database.connections.mysql.options', [ PDO::ATTR_EMULATE_PREPARES => true, ]); diff --git a/tests/Integration/Database/DatabaseMySqlConnectionTest.php b/tests/Integration/Database/DatabaseMySqlConnectionTest.php index 8b91c04908e1..7d413fe15eb5 100644 --- a/tests/Integration/Database/DatabaseMySqlConnectionTest.php +++ b/tests/Integration/Database/DatabaseMySqlConnectionTest.php @@ -10,13 +10,20 @@ * @requires extension pdo_mysql * @requires OS Linux|Darwin */ -class DatabaseMySqlConnectionTest extends DatabaseMySqlTestCase +class DatabaseMySqlConnectionTest extends DatabaseTestCase { const TABLE = 'player'; const FLOAT_COL = 'float_col'; const JSON_COL = 'json_col'; const FLOAT_VAL = 0.2; + protected function getEnvironmentSetUp($app) + { + parent::getEnvironmentSetUp($app); + + $app['config']->set('database.default', 'mysql'); + } + protected function setUp(): void { parent::setUp(); diff --git a/tests/Integration/Database/DatabaseSchemaBuilderAlterTableWithEnumTest.php b/tests/Integration/Database/DatabaseMySqlSchemaBuilderAlterTableWithEnumTest.php similarity index 80% rename from tests/Integration/Database/DatabaseSchemaBuilderAlterTableWithEnumTest.php rename to tests/Integration/Database/DatabaseMySqlSchemaBuilderAlterTableWithEnumTest.php index fa88e84fc264..92b644f7857d 100644 --- a/tests/Integration/Database/DatabaseSchemaBuilderAlterTableWithEnumTest.php +++ b/tests/Integration/Database/DatabaseMySqlSchemaBuilderAlterTableWithEnumTest.php @@ -10,8 +10,15 @@ * @requires extension pdo_mysql * @requires OS Linux|Darwin */ -class DatabaseSchemaBuilderAlterTableWithEnumTest extends DatabaseMySqlTestCase +class DatabaseMySqlSchemaBuilderAlterTableWithEnumTest extends DatabaseTestCase { + protected function getEnvironmentSetUp($app) + { + parent::getEnvironmentSetUp($app); + + $app['config']->set('database.default', 'mysql'); + } + protected function setUp(): void { parent::setUp(); @@ -58,7 +65,12 @@ public function testGetAllTablesAndColumnListing() $tableProperties = array_values((array) $tables[0]); $this->assertEquals(['users', 'BASE TABLE'], $tableProperties); - $this->assertEquals(['id', 'name', 'age', 'color'], Schema::getColumnListing('users')); + + $columns = Schema::getColumnListing('users'); + + foreach (['id', 'name', 'age', 'color'] as $column) { + $this->assertContains($column, $columns); + } Schema::create('posts', function (Blueprint $table) { $table->integer('id'); diff --git a/tests/Integration/Database/DatabaseMySqlTestCase.php b/tests/Integration/Database/DatabaseMySqlTestCase.php deleted file mode 100644 index 6b4722ed98fb..000000000000 --- a/tests/Integration/Database/DatabaseMySqlTestCase.php +++ /dev/null @@ -1,23 +0,0 @@ -set('app.debug', 'true'); - $app['config']->set('database.default', 'mysql'); - } - - protected function setUp(): void - { - parent::setUp(); - - if (! isset($_SERVER['CI'])) { - $this->markTestSkipped('This test is only executed on CI.'); - } - } -} diff --git a/tests/Integration/Database/DatabaseTestCase.php b/tests/Integration/Database/DatabaseTestCase.php index af8c9ff1ea7e..d932db5c9563 100644 --- a/tests/Integration/Database/DatabaseTestCase.php +++ b/tests/Integration/Database/DatabaseTestCase.php @@ -4,18 +4,29 @@ use Orchestra\Testbench\TestCase; -class DatabaseTestCase extends TestCase +abstract class DatabaseTestCase extends TestCase { protected function getEnvironmentSetUp($app) { $app['config']->set('app.debug', 'true'); - $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ]); + + if (! env('DB_CONNECTION')) { + $app['config']->set('database.default', 'testbench'); + } + } + + protected function tearDown(): void + { + if ($this->app['config']->get('database.default') !== 'testbench') { + $this->artisan('db:wipe', ['--drop-views' => true]); + } + + parent::tearDown(); } } diff --git a/tests/Integration/Database/EloquentBelongsToManyTest.php b/tests/Integration/Database/EloquentBelongsToManyTest.php index 3f5b85f99ffb..708d1a4880dd 100644 --- a/tests/Integration/Database/EloquentBelongsToManyTest.php +++ b/tests/Integration/Database/EloquentBelongsToManyTest.php @@ -48,7 +48,7 @@ protected function setUp(): void Schema::create('posts_tags', function (Blueprint $table) { $table->integer('post_id'); - $table->integer('tag_id'); + $table->string('tag_id'); $table->string('flag')->default('')->nullable(); $table->timestamps(); }); @@ -132,7 +132,7 @@ public function testCustomPivotClass() $post->tagsWithCustomPivot()->attach($tag->id); $this->assertInstanceOf(PostTagPivot::class, $post->tagsWithCustomPivot[0]->pivot); - $this->assertEquals('1507630210', $post->tagsWithCustomPivot[0]->pivot->getAttributes()['created_at']); + $this->assertEquals('1507630210', $post->tagsWithCustomPivot[0]->pivot->created_at); $this->assertInstanceOf(PostTagPivot::class, $post->tagsWithCustomPivotClass[0]->pivot); $this->assertSame('posts_tags', $post->tagsWithCustomPivotClass()->getTable()); @@ -213,8 +213,8 @@ public function testCustomPivotClassUpdatesTimestamps() DB::table('posts_tags')->insert([ [ 'post_id' => $post->id, 'tag_id' => $tag->id, 'flag' => 'empty', - 'created_at' => '1507630210', - 'updated_at' => '1507630210', + 'created_at' => '2017-10-10 10:10:10', + 'updated_at' => '2017-10-10 10:10:10', ], ]); @@ -226,8 +226,8 @@ public function testCustomPivotClassUpdatesTimestamps() ); foreach ($post->tagsWithCustomExtraPivot as $tag) { $this->assertSame('exclude', $tag->pivot->flag); - $this->assertEquals('1507630210', $tag->pivot->getAttributes()['created_at']); - $this->assertEquals('1507630220', $tag->pivot->getAttributes()['updated_at']); // +10 seconds + $this->assertEquals('2017-10-10 10:10:10', $tag->pivot->getAttributes()['created_at']); + $this->assertEquals('2017-10-10 10:10:20', $tag->pivot->getAttributes()['updated_at']); // +10 seconds } } @@ -1068,7 +1068,11 @@ class UserPostPivot extends Pivot class PostTagPivot extends Pivot { protected $table = 'posts_tags'; - protected $dateFormat = 'U'; + + public function getCreatedAtAttribute($value) + { + return Carbon::parse($value)->format('U'); + } } class TagWithGlobalScope extends Model diff --git a/tests/Integration/Database/EloquentCursorPaginateTest.php b/tests/Integration/Database/EloquentCursorPaginateTest.php index 826f424f7f1b..c38e01376270 100644 --- a/tests/Integration/Database/EloquentCursorPaginateTest.php +++ b/tests/Integration/Database/EloquentCursorPaginateTest.php @@ -180,7 +180,7 @@ public function testPaginationWithDistinctColumnsAndSelect() TestPost::create(['title' => 'Goodbye world']); } - $query = TestPost::query()->distinct('title')->select('title'); + $query = TestPost::query()->orderBy('title')->distinct('title')->select('title'); $this->assertEquals(2, $query->get()->count()); $this->assertEquals(2, $query->count()); diff --git a/tests/Integration/Database/EloquentModelDateCastingTest.php b/tests/Integration/Database/EloquentModelDateCastingTest.php index 57790dab777c..1141f6fc8bbd 100644 --- a/tests/Integration/Database/EloquentModelDateCastingTest.php +++ b/tests/Integration/Database/EloquentModelDateCastingTest.php @@ -45,20 +45,20 @@ public function testDatesFormattedAttributeBindings() $bindings = $query->bindings; }); - $user = TestModel1::create([ - 'date_field' => '2019-10', + TestModel1::create([ + 'date_field' => '2019-10-01', 'datetime_field' => '2019-10-01 10:15:20', 'immutable_date_field' => '2019-10-01', 'immutable_datetime_field' => '2019-10-01 10:15', ]); - $this->assertSame(['2019-10', '2019-10-01 10:15:20', '2019-10-01', '2019-10-01 10:15'], $bindings); + $this->assertSame(['2019-10-01', '2019-10-01 10:15:20', '2019-10-01', '2019-10-01 10:15'], $bindings); } public function testDatesFormattedArrayAndJson() { $user = TestModel1::create([ - 'date_field' => '2019-10', + 'date_field' => '2019-10-01', 'datetime_field' => '2019-10-01 10:15:20', 'immutable_date_field' => '2019-10-01', 'immutable_datetime_field' => '2019-10-01 10:15', @@ -78,7 +78,6 @@ public function testDatesFormattedArrayAndJson() public function testCustomDateCastsAreComparedAsDatesForCarbonInstances() { - /** @var TestModel1 */ $user = TestModel1::create([ 'date_field' => '2019-10-01', 'datetime_field' => '2019-10-01 10:15:20', @@ -99,7 +98,6 @@ public function testCustomDateCastsAreComparedAsDatesForCarbonInstances() public function testCustomDateCastsAreComparedAsDatesForStringValues() { - /** @var TestModel1 */ $user = TestModel1::create([ 'date_field' => '2019-10-01', 'datetime_field' => '2019-10-01 10:15:20', diff --git a/tests/Integration/Database/EloquentPrunableTest.php b/tests/Integration/Database/EloquentPrunableTest.php index fb8d6c3ec41e..c9ef7f3d1578 100644 --- a/tests/Integration/Database/EloquentPrunableTest.php +++ b/tests/Integration/Database/EloquentPrunableTest.php @@ -111,15 +111,6 @@ public function testPruneWithCustomPruneMethod() $this->assertFalse((bool) PrunableWithCustomPruneMethodTestModel::orderBy('id', 'desc')->first()->pruned); $this->assertEquals(5000, PrunableWithCustomPruneMethodTestModel::count()); } - - public function tearDown(): void - { - parent::tearDown(); - - Container::setInstance(null); - - m::close(); - } } class PrunableTestModel extends Model diff --git a/tests/Integration/Database/EloquentWhereHasMorphTest.php b/tests/Integration/Database/EloquentWhereHasMorphTest.php index a39645fc8af4..f581dd921215 100644 --- a/tests/Integration/Database/EloquentWhereHasMorphTest.php +++ b/tests/Integration/Database/EloquentWhereHasMorphTest.php @@ -53,7 +53,7 @@ public function testWhereHasMorph() { $comments = Comment::whereHasMorph('commentable', [Post::class, Video::class], function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 4], $comments->pluck('id')->all()); } @@ -67,7 +67,7 @@ public function testWhereHasMorphWithMorphMap() try { $comments = Comment::whereHasMorph('commentable', [Post::class, Video::class], function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 4], $comments->pluck('id')->all()); } finally { @@ -83,7 +83,7 @@ public function testWhereHasMorphWithWildcard() $comments = Comment::withTrashed() ->whereHasMorph('commentable', '*', function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 4], $comments->pluck('id')->all()); } @@ -97,9 +97,9 @@ public function testWhereHasMorphWithWildcardAndMorphMap() try { $comments = Comment::whereHasMorph('commentable', '*', function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); - $this->assertEquals([4, 1], $comments->pluck('id')->all()); + $this->assertEquals([1, 4], $comments->pluck('id')->all()); } finally { Relation::morphMap([], false); } @@ -109,7 +109,7 @@ public function testWhereHasMorphWithRelationConstraint() { $comments = Comment::whereHasMorph('commentableWithConstraint', Video::class, function (Builder $query) { $query->where('title', 'like', 'ba%'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([5], $comments->pluck('id')->all()); } @@ -124,7 +124,7 @@ public function testWhereHasMorphWitDifferentConstraints() if ($type === Video::class) { $query->where('title', 'bar'); } - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 5], $comments->pluck('id')->all()); } @@ -145,35 +145,35 @@ public function testWhereHasMorphWithOwnerKey() $comments = Comment::whereHasMorph('commentableWithOwnerKey', Post::class, function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1], $comments->pluck('id')->all()); } public function testHasMorph() { - $comments = Comment::hasMorph('commentable', Post::class)->get(); + $comments = Comment::hasMorph('commentable', Post::class)->orderBy('id')->get(); $this->assertEquals([1, 2], $comments->pluck('id')->all()); } public function testOrHasMorph() { - $comments = Comment::where('id', 1)->orHasMorph('commentable', Video::class)->get(); + $comments = Comment::where('id', 1)->orHasMorph('commentable', Video::class)->orderBy('id')->get(); $this->assertEquals([1, 4, 5, 6], $comments->pluck('id')->all()); } public function testDoesntHaveMorph() { - $comments = Comment::doesntHaveMorph('commentable', Post::class)->get(); + $comments = Comment::doesntHaveMorph('commentable', Post::class)->orderBy('id')->get(); $this->assertEquals([3], $comments->pluck('id')->all()); } public function testOrDoesntHaveMorph() { - $comments = Comment::where('id', 1)->orDoesntHaveMorph('commentable', Post::class)->get(); + $comments = Comment::where('id', 1)->orDoesntHaveMorph('commentable', Post::class)->orderBy('id')->get(); $this->assertEquals([1, 3], $comments->pluck('id')->all()); } @@ -183,7 +183,7 @@ public function testOrWhereHasMorph() $comments = Comment::where('id', 1) ->orWhereHasMorph('commentable', Video::class, function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 4], $comments->pluck('id')->all()); } @@ -192,7 +192,7 @@ public function testWhereDoesntHaveMorph() { $comments = Comment::whereDoesntHaveMorph('commentable', Post::class, function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([2, 3], $comments->pluck('id')->all()); } @@ -202,7 +202,7 @@ public function testOrWhereDoesntHaveMorph() $comments = Comment::where('id', 1) ->orWhereDoesntHaveMorph('commentable', Post::class, function (Builder $query) { $query->where('title', 'foo'); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 2, 3], $comments->pluck('id')->all()); } @@ -211,7 +211,7 @@ public function testModelScopesAreAccessible() { $comments = Comment::whereHasMorph('commentable', [Post::class, Video::class], function (Builder $query) { $query->someSharedModelScope(); - })->get(); + })->orderBy('id')->get(); $this->assertEquals([1, 4], $comments->pluck('id')->all()); } diff --git a/tests/Integration/Database/EloquentWhereHasTest.php b/tests/Integration/Database/EloquentWhereHasTest.php index fa32016ed8f3..489a9a31476c 100644 --- a/tests/Integration/Database/EloquentWhereHasTest.php +++ b/tests/Integration/Database/EloquentWhereHasTest.php @@ -26,7 +26,7 @@ protected function setUp(): void Schema::create('texts', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('post_id'); - $table->boolean('content'); + $table->text('content'); }); Schema::create('comments', function (Blueprint $table) { diff --git a/tests/Integration/Database/EloquentWithCountTest.php b/tests/Integration/Database/EloquentWithCountTest.php index 6394ad14c7b3..6abc13f3339a 100644 --- a/tests/Integration/Database/EloquentWithCountTest.php +++ b/tests/Integration/Database/EloquentWithCountTest.php @@ -67,9 +67,10 @@ public function testSortingScopes() $one = Model1::create(); $one->twos()->create(); - $result = Model1::withCount('twos')->toSql(); + $query = Model1::withCount('twos')->getQuery(); - $this->assertSame('select "one".*, (select count(*) from "two" where "one"."id" = "two"."one_id") as "twos_count" from "one"', $result); + $this->assertNull($query->orders); + $this->assertSame([], $query->getRawBindings()['order']); } } diff --git a/tests/Integration/Database/MigrateWithRealpathTest.php b/tests/Integration/Database/MigrateWithRealpathTest.php index edc87f7fdec5..be75595fe4b2 100644 --- a/tests/Integration/Database/MigrateWithRealpathTest.php +++ b/tests/Integration/Database/MigrateWithRealpathTest.php @@ -3,13 +3,33 @@ namespace Illuminate\Tests\Integration\Database; use Illuminate\Support\Facades\Schema; +use Orchestra\Testbench\TestCase; -class MigrateWithRealpathTest extends DatabaseTestCase +class MigrateWithRealpathTest extends TestCase { + protected function getEnvironmentSetUp($app) + { + $app['config']->set('app.debug', 'true'); + + $app['config']->set('database.connections.testbench', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + + if (! env('DB_CONNECTION')) { + $app['config']->set('database.default', 'testbench'); + } + } + protected function setUp(): void { parent::setUp(); + if ($this->app['config']->get('database.default') !== 'testbench') { + $this->artisan('db:wipe', ['--drop-views' => true]); + } + $options = [ '--path' => realpath(__DIR__.'/stubs/'), '--realpath' => true, diff --git a/tests/Integration/Database/QueryBuilderTest.php b/tests/Integration/Database/QueryBuilderTest.php index ea3fd71b8edd..51aa8a7098de 100644 --- a/tests/Integration/Database/QueryBuilderTest.php +++ b/tests/Integration/Database/QueryBuilderTest.php @@ -73,9 +73,9 @@ public function testSelectReplacesExistingSelects() public function testSelectWithSubQuery() { $this->assertEquals( - ['id' => '1', 'title' => 'Foo Post', 'foo' => 'bar'], + ['id' => '1', 'title' => 'Foo Post', 'foo' => 'Lorem Ipsum.'], (array) DB::table('posts')->select(['id', 'title', 'foo' => function ($query) { - $query->select('bar'); + $query->select('content'); }])->first() ); } @@ -92,16 +92,16 @@ public function testAddSelect() public function testAddSelectWithSubQuery() { $this->assertEquals( - ['id' => '1', 'title' => 'Foo Post', 'foo' => 'bar'], + ['id' => '1', 'title' => 'Foo Post', 'foo' => 'Lorem Ipsum.'], (array) DB::table('posts')->addSelect(['id', 'title', 'foo' => function ($query) { - $query->select('bar'); + $query->select('content'); }])->first() ); } public function testFromWithAlias() { - $this->assertSame('select * from "posts" as "alias"', DB::table('posts', 'alias')->toSql()); + $this->assertCount(2, DB::table('posts', 'alias')->select('alias.*')->get()); } public function testFromWithSubQuery() @@ -127,7 +127,7 @@ public function testWhereValueSubQuery() public function testWhereValueSubQueryBuilder() { - $subQuery = DB::table('posts')->selectRaw("'Sub query value'"); + $subQuery = DB::table('posts')->selectRaw("'Sub query value'")->limit(1); $this->assertTrue(DB::table('posts')->where($subQuery, 'Sub query value')->exists()); $this->assertFalse(DB::table('posts')->where($subQuery, 'Does not match')->exists()); diff --git a/tests/Integration/Database/RefreshCommandTest.php b/tests/Integration/Database/RefreshCommandTest.php index a72b67fc1827..506341148f54 100644 --- a/tests/Integration/Database/RefreshCommandTest.php +++ b/tests/Integration/Database/RefreshCommandTest.php @@ -3,9 +3,25 @@ namespace Illuminate\Tests\Integration\Database; use Illuminate\Support\Facades\DB; +use Orchestra\Testbench\TestCase; -class RefreshCommandTest extends DatabaseTestCase +class RefreshCommandTest extends TestCase { + protected function getEnvironmentSetUp($app) + { + $app['config']->set('app.debug', 'true'); + + $app['config']->set('database.connections.testbench', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + + if (! env('DB_CONNECTION')) { + $app['config']->set('database.default', 'testbench'); + } + } + public function testRefreshWithoutRealpath() { $this->app->setBasePath(__DIR__); @@ -14,7 +30,7 @@ public function testRefreshWithoutRealpath() '--path' => 'stubs/', ]; - $this->migrate_refresh_with($options); + $this->migrateRefreshWith($options); } public function testRefreshWithRealpath() @@ -24,11 +40,15 @@ public function testRefreshWithRealpath() '--realpath' => true, ]; - $this->migrate_refresh_with($options); + $this->migrateRefreshWith($options); } - private function migrate_refresh_with(array $options) + private function migrateRefreshWith(array $options) { + if ($this->app['config']->get('database.default') !== 'testbench') { + $this->artisan('db:wipe', ['--drop-views' => true]); + } + $this->beforeApplicationDestroyed(function () use ($options) { $this->artisan('migrate:rollback', $options); }); diff --git a/tests/Integration/Database/SchemaBuilderTest.php b/tests/Integration/Database/SchemaBuilderTest.php index 34b93585b9f1..41f0a8a7f693 100644 --- a/tests/Integration/Database/SchemaBuilderTest.php +++ b/tests/Integration/Database/SchemaBuilderTest.php @@ -31,11 +31,11 @@ public function testDropAllViews() { $this->expectNotToPerformAssertions(); - DB::statement('create view "view"("id") as select 1'); + DB::statement('create view foo (id) as select 1'); Schema::dropAllViews(); - DB::statement('create view "view"("id") as select 1'); + DB::statement('create view foo (id) as select 1'); } public function testRegisterCustomDoctrineType() @@ -50,20 +50,9 @@ public function testRegisterCustomDoctrineType() $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); } }