napp/codeception-sqlquery

SQL query assertions for Codeception

1.0 2018-04-24 21:24 UTC

This package is auto-updated.

Last update: 2024-04-05 19:11:40 UTC


README

Find N+1 or similar design bugs in your Laravel application.

Install with Composer

    {
        "require-dev": {
            "napp/codeception-sqlquery": "1.*"
        }
    }

Example suite configuration

    modules:
        enabled:
            - Laravel5
            - Db:
                dsn: "mysql:host=localhost;dbname=testdb"
            - Database:
                depends: [Db, Laravel5]
                connection: my_database

Usage

public function _before()
{
    // start by enabling the listener
    $this->tester->enableSqlQueryListener();
}

public function test_my_api_endpoint()
{
    $this->tester->sendGET('api/my_endpoint');
    $this->tester->seeResponseCodeIs(200);
    $this->tester->seeResponseIsJson();

    // then test sql query count
    $this->tester->assertSqlQueriesLessThanOrEqual(2);
    $this->tester->assertSqlExecutionTimeLessThan(4);
    
    // dump the sql queries for debugging
    //$this->tester->debugSqlQueries();
}