PHP code example of napp / codeception-sqlquery

1. Go to this page and download the library: Download napp/codeception-sqlquery library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

napp / codeception-sqlquery example snippets


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();
}