Functional Tests. The api error handler throw error

Hello everybody!

When i run api test with phpBrowser and controller has other errors (domain, error, throwable), i see this error in json response:

1) AuthCest: Try to test
 Test  tests/api/AuthCest.php:tryToTest
 Step  See response contains json {"data":[]}
 Fail  Response JSON does not contain the provided JSON

- Expected | + Actual
@@ @@
Array (
-    'data' => Array ()
+    'errors' => Array (...)
)

Scenario Steps:

 2. $I->seeResponseContainsJson({"data":[]}) at tests/api/AuthCest.php:23
 1. $I->sendPost("/brand/list") at tests/api/AuthCest.php:20

When i use functional tests, i have error in tests. I see this:

How can i change this behaviour and see like api tests?

I change some settings in error handler component silentExitOnException => true and YII_ENV_TEST => true , but nothing.

I got error because DomainExeception is not HttpException:

My config in api.suite.yml:

actor: ApiTester
modules:
    enabled:
        - Yii2
        - REST:
            depends: Yii2
            part: json
            shortDebugResponse: 600
        - Db
        - \Helper\Api

Code for test:

<?php

use Codeception\Util\Debug;
use cosmetic\entity\user\User;
use cosmetic\store\db\UsersStore;
use yii\helpers\VarDumper;

class AuthCest
{
    public function _before(ApiTester $I)
    {
    }

    // tests
    public function tryToTest(ApiTester $I)
    {
        $I->sendPost("/brand/list");
        $I->seeResponseContainsJson([
            'data' => []
        ]);
    }
}

Your test is generating an error, which by the API definition (using the default ActiveController) will return a list of errors, with the index error in the response.

Still you are NOT expecting to receive an error:

        $I->seeResponseContainsJson([
            'data' => []
        ]);

You have two options here:

  1. Update the test so it doesn’t generate errors! ← best choice!!
  2. Change the data in the expected JSON to error (this would make sense if is a test that expects that error).

If you are expecting to discover what is the error with this test, then you should compare, or log, the returned error list.