mirror of
https://github.com/10h30/Test-Laravel-Eloquent-Basics.git
synced 2026-06-05 15:07:45 +09:00
Improved first test
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user