24/04
2018
SQL query assertions for Codeception
Find N+1 or similar design bugs in your Laravel application., (*1)
{ "require-dev": { "napp/codeception-sqlquery": "1.*" } }
modules: enabled: - Laravel5 - Db: dsn: "mysql:host=localhost;dbname=testdb" - Database: depends: [Db, Laravel5] connection: my_database
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(); }