Skip to content

Commit 4b1f01f

Browse files
authored
[12.x] Test Improvements (#53524)
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
1 parent 935e5f7 commit 4b1f01f

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/Illuminate/Foundation/Testing/RefreshDatabase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ protected function usingInMemoryDatabases()
4848
*
4949
* @return bool
5050
*/
51-
protected function usingInMemoryDatabase(string $name)
51+
protected function usingInMemoryDatabase(?string $name)
5252
{
53+
if (is_null($name)) {
54+
$name = config('database.default');
55+
}
56+
5357
return config("database.connections.{$name}.database") === ':memory:';
5458
}
5559

tests/Database/DatabaseSchemaBlueprintTest.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -400,34 +400,30 @@ public function testGenerateRelationshipColumnWithUlidModel()
400400

401401
public function testGenerateRelationshipConstrainedColumn()
402402
{
403-
$base = new Blueprint('posts', function ($table) {
404-
$table->foreignIdFor('Illuminate\Foundation\Auth\User')->constrained();
405-
});
406-
407-
$connection = m::mock(Connection::class);
408-
409-
$blueprint = clone $base;
403+
$getSql = function ($grammar) {
404+
return $this->getBlueprint($grammar, 'posts', function ($table) {
405+
$table->foreignIdFor('Illuminate\Foundation\Auth\User')->constrained();
406+
})->toSql();
407+
};
410408

411409
$this->assertEquals([
412410
'alter table `posts` add `user_id` bigint unsigned not null',
413411
'alter table `posts` add constraint `posts_user_id_foreign` foreign key (`user_id`) references `users` (`id`)',
414-
], $blueprint->toSql($connection, new MySqlGrammar));
412+
], $getSql(new MySqlGrammar));
415413
}
416414

417415
public function testGenerateRelationshipForModelWithNonStandardPrimaryKeyName()
418416
{
419-
$base = new Blueprint('posts', function ($table) {
420-
$table->foreignIdFor(User::class)->constrained();
421-
});
422-
423-
$connection = m::mock(Connection::class);
424-
425-
$blueprint = clone $base;
417+
$getSql = function ($grammar) {
418+
return $this->getBlueprint($grammar, 'posts', function ($table) {
419+
$table->foreignIdFor(User::class)->constrained();
420+
})->toSql();
421+
};
426422

427423
$this->assertEquals([
428424
'alter table `posts` add `user_internal_id` bigint unsigned not null',
429425
'alter table `posts` add constraint `posts_user_internal_id_foreign` foreign key (`user_internal_id`) references `users` (`internal_id`)',
430-
], $blueprint->toSql($connection, new MySqlGrammar));
426+
], $getSql(new MySqlGrammar));
431427
}
432428

433429
public function testDropRelationshipColumnWithIncrementalModel()

0 commit comments

Comments
 (0)