Improved first test

This commit is contained in:
PovilasKorop
2021-11-16 07:25:20 +02:00
parent 8c860fbac5
commit 37db8803e2
3 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ Good luck!
## Task 1. Model with Different Table Name. ## Task 1. Model with Different Table Name.
In `app/Models/News.php` file, specify that the model would work with "morning_news" table, as it is created in the migrations. In `app/Models/Morningnews.php` file, change it so that the model would work with "morning_news" table, as it is created in the migrations.
Test method `test_create_model_different_table()`. Test method `test_create_model_incorrect_table()`.
@@ -5,8 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
// TASK: Define the model's related table as "morning_news" class Morningnews extends Model
class News extends Model
{ {
use HasFactory; use HasFactory;
+4 -3
View File
@@ -2,6 +2,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Morningnews;
use App\Models\News; use App\Models\News;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase; use Tests\TestCase;
@@ -10,13 +11,13 @@ class EloquentTest extends TestCase
{ {
use RefreshDatabase; use RefreshDatabase;
public function test_create_model_different_table() // TASK: Make the model Morningnews work with DB table "morning_news"
public function test_create_model_incorrect_table()
{ {
$article = ['title' => 'Something', 'news_text' => 'Something']; $article = ['title' => 'Something', 'news_text' => 'Something'];
News::create($article); Morningnews::create($article);
$this->assertDatabaseHas('morning_news', $article); $this->assertDatabaseHas('morning_news', $article);
} }
} }