Files
Test-Laravel-Migrations/tests/Feature/MigrationsTest.php
T

43 lines
1.2 KiB
PHP
Raw Normal View History

2021-11-08 11:50:12 +02:00
<?php
namespace Tests\Feature;
2021-11-09 10:08:56 +02:00
use App\Models\User;
2021-11-08 11:50:12 +02:00
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class MigrationsTest extends TestCase
{
// !!! IMPORTANT: TESTS ARE CONFIGURED TO RUN ON A LOCAL MYSQL DATABASE
// WHICH SHOULD BE CALLED "mysql_testing"
// !!! DON'T FORGET TO CREATE THAT DATABASE
// !!! NOTICE: THAT DB WILL BE WIPED A LOT WITHIN TESTS BY "migrate:fresh"
2021-11-08 11:53:49 +02:00
public function test_successful_foreign_key_tasks_comments()
2021-11-08 11:50:12 +02:00
{
// We just test if the migration succeeds or throws an exception
$this->expectNotToPerformAssertions();
Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task1']);
}
2021-11-09 10:08:56 +02:00
public function test_column_added_to_the_table()
{
Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task2']);
User::factory()->create(['surname' => 'Testing']);
$this->assertDatabaseHas(User::class, ['surname' => 'Testing']);
$user = User::first();
$fieldNumber = 0;
foreach ($user->getAttributes() as $key => $value) {
$fieldNumber++;
if ($key == "surname") break;
}
$this->assertEquals(3, $fieldNumber);
}
2021-11-08 11:50:12 +02:00
}