Task 6 - duplicate values

This commit is contained in:
PovilasKorop
2021-11-09 10:44:29 +02:00
parent 16a72f52c2
commit 888d5d87c2
4 changed files with 68 additions and 0 deletions
+14
View File
@@ -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']);
}
}