mirror of
https://github.com/10h30/Test-Laravel-Migrations.git
synced 2026-07-11 19:05:54 +09:00
Task 6 - duplicate values
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -72,4 +74,16 @@ class MigrationsTest extends TestCase
|
||||
|
||||
Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task5']);
|
||||
}
|
||||
|
||||
public function test_duplicate_name()
|
||||
{
|
||||
// We expect that the second Company::create() would throw an exception like
|
||||
// "Integrity constraint violation: 1062 Duplicate entry 'Company One'"
|
||||
$this->expectException(QueryException::class);
|
||||
|
||||
Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task6']);
|
||||
|
||||
Company::create(['name' => 'Company One']);
|
||||
Company::create(['name' => 'Company One']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user