<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lucasdotvin / laravel-database-queries-counter example snippets
namespace Tests\Feature;
use App\Models\Post;
use App\Models\User;
use LucasDotVin\DBQueriesCounter\Traits\CountsQueries;
use Tests\TestCase;
class PostTest extends TestCase
{
use CountsQueries;
public function testIndexPageDoesNotPerfomNPlusOneQueries()
{
Post::factory()->times(10)->create();
$user = User::factory()->create();
$this->actingAs($user);
$this->startCountingQueries();
$response = $this->get(route('posts.index'));
$this->stopCountingQueries();
$response->assertSuccessful();
$this->assertDatabaseQueriesCount(1);
}
}
public function testIndexPageDoesNotPerfomNPlusOneQueries()
{
Post::factory()->times(10)->create();
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->whileCountingQueries(fn () => $this->get(route('posts.index')));
$response->assertSuccessful();
$this->assertDatabaseQueriesCount(1);
}