Trait for Laravel testing to count/assert about database queries

Overview

counts_database_queries

Trait for Laravel testing to count/assert about database queries

Installing

composer require ohffs/counts-database-queries-trait

Usage

<?php

namespace Tests\Feature;

use Ohffs\CountsDatabaseQueries\CountsDatabaseQueries;

class MyAmazingTest extends TestCase
{
    use CountsDatabaseQueries;

    /** @test */
    public function we_can_see_the_webpage()
    {
        $user = User::factory()->create();
        $stuff = Stuff::factory()->count(3)->create();
 
        // you'd usually want to start counting only after all your setup calls
        $this->countDatabaseQueries();

        $response = $this->actingAs($user)->get('/stuff');

        $response->assertOk();
        $response->assertSee('Stuff');
        $this->assertQueryCountEquals(6);
        $this->assertQueryCountBetween(5, 7);
        $this->assertQueryCountGreaterThan(5);
        $this->assertQueryCountLessThan(7);
        dd($this->recordedDatabaseQueries);
    }
}
You might also like...
a Laravel package help you to execute more effective databases queries.
a Laravel package help you to execute more effective databases queries.

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimizing sql queries, this package will contain all advanced sq

Simple Laravel 5 package to dump all running queries on the page.
Simple Laravel 5 package to dump all running queries on the page.

Abandoned: Use this package instead Laravel QueryDumper Introduction Simple Laravel 5 package to dump all running queries on the page. If it's SELECT

Fullstack komponents to write Forms, Queries and Menus in Laravel

kompo.io • Documentation • Demos • Twitter kompo/kompo kompo/kompo is a library of Fullstack Komponents to help you write forms, queries and menus in

Log executed Laravel SQL queries and their line number and more

A lightweight laravel package for logging executed SQL queries, line number and more

Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily.
Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily.

DevMakerLab/Laravel-Filters Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily. Insta

Laravel Dusk provides simple end-to-end testing and browser automation.

Introduction Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK

Github repository dedicated for my YT tutorial which shows how to use testing in Laravel

Testing in Laravel The following documentation is based on my Laravel Testing for Beginners tutorial we’re going to cover the basics of unit tests, fe

Providing some testing functionality for Laravel
Providing some testing functionality for Laravel

Laravel TestBench Laravel TestBench was created by, and is maintained by Graham Campbell, and provides some testing functionality for Laravel. It util

Eloquent scope assertion for testing Laravel applications.

Eloquent Scope Assertion This package allows you to assert that the scope of a model is called in your tests. Installation You can install the package

Owner
null
Tag support for Laravel Eloquent models - Taggable Trait

Laravel Taggable Trait This package is not meant to handle javascript or html in any way. This package handles database storage and read/writes only.

Rob 859 Dec 11, 2022
A Single Table Inheritance Trait for Eloquent/Laravel

Single Table Inheritance Credit This code is a fork of Nanigans/single-table-inheritance. I've only updated it to work with Laravel 5 Single Table Inh

Peter Haza 15 Feb 17, 2022
A Single Table Inheritance Trait for Eloquent/Laravel

Single Table Inheritance Single Table Inheritance is a trait for Laravel 5.8+ Eloquent models that allows multiple models to be stored in the same dat

Jon Palmer 240 Oct 26, 2022
Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Limewell 30 Dec 24, 2022
This package provides a trait that will generate a unique uuid when saving any Eloquent model.

Generate slugs when saving Eloquent models This package provides a trait that will generate a unique uuid when saving any Eloquent model. $model = new

Abdul Kudus 2 Oct 14, 2021
Trait for multilingual resource file support

⚡ Usage This library supports MultilingualResourceTrait which can be used in PluginBase. Multilingual support of resource files is possible using this

PocketMine-MP projects of PresentKim 1 Jun 7, 2022
This package provides a trait to run your tests against a MinIO S3 server.

Laravel MinIO Testing Tools This package provides a trait to run your tests against a MinIO S3 server. ?? Blog post: https://protone.media/en/blog/how

Protone Media 7 Oct 12, 2022
Livewire trait (throttling). Limiting request processing speed

Livewire Throttling Installation You can install the package via composer: composer require f1uder/livewire-throttling Usage Livewire component <?php

Fluder 5 Dec 7, 2022
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Syrian Open Source 15 Nov 20, 2022
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Mouad ZIANI 59 Sep 25, 2022