mirror of
https://github.com/10h30/Test-Laravel-Eloquent-Basics.git
synced 2026-07-11 10:55:52 +09:00
Test 2 - get data
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Morningnews;
|
||||
use App\Models\News;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -20,4 +21,27 @@ class EloquentTest extends TestCase
|
||||
$this->assertDatabaseHas('morning_news', $article);
|
||||
}
|
||||
|
||||
// TASK: Write Eloquent query to return the newest 3 verified users
|
||||
public function test_users_get()
|
||||
{
|
||||
$user1 = User::factory()->create(['created_at' => now()->subMinutes(5)]);
|
||||
$user2 = User::factory()->create(['created_at' => now()->subMinutes(4)]);
|
||||
$user3 = User::factory()->create(['created_at' => now()->subMinutes(3), 'email_verified_at' => NULL]);
|
||||
$user4 = User::factory()->create(['created_at' => now()->subMinutes(2)]);
|
||||
$user5 = User::factory()->create(['created_at' => now()->subMinute()]);
|
||||
|
||||
$response = $this->get('users');
|
||||
|
||||
// This one should be filtered by "email_verified_at is not null"
|
||||
$response->assertDontSee($user3->name);
|
||||
|
||||
// This one should be filtered out by "limit 3"
|
||||
$response->assertDontSee($user1->name);
|
||||
|
||||
// Do we have the correct order?
|
||||
$response->assertSee('1. ' . $user5->name);
|
||||
$response->assertSee('2. ' . $user4->name);
|
||||
$response->assertSee('3. ' . $user2->name); // not $user3
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user