Project on YII2. Roles are tested, all individually pass the test normally and two too, but when they are tested all at once, the test produces the following error for the third role:

Scenario Steps: 1071. $I->seeResponseCodeIs(200) at tests/functional/RoleCest.php:60 1070. $I->amOnRoute("/catalog/catalog/index") at tests/functional/RoleCest.php:48 PHP Fatal error: Uncaught Error: Call to a member function getDb() on null in /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php:135 Stack trace: #0 /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php(382): yii\db\ActiveRecord::getDb() #1 /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php(418): yii\db\ActiveRecord::getTableSchema() #2 /var/www/html/site.info/vendor/yiisoft/yii2/db/BaseActiveRecord.php(492): yii\db\ActiveRecord->attributes() #3 /var/www/html/site.info/vendor/yiisoft/yii2/db/BaseActiveRecord.php(289): yii\db\BaseActiveRecord->hasAttribute('__mocked') #4 /var/www/html/site.info/vendor/yiisoft/yii2/db/BaseActiveRecord.php(335): yii\db\BaseActiveRecord->__get('__mocked') #5 /var/www/html/site.info/vendor/codeception/base/src/Codeception/Step.php(176): yii\db\BaseActiveRecord->__isset('__mocked') #6 /var/www/html/site.info/vendor/codeception/base/src/Codeception/Step.php(164): Codeception\Step->getC in /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php on line 135 FATAL ERROR. TESTS NOT FINISHED. Uncaught Error: Call to a member function getDb() on null in /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php:135 Stack trace: #0 /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php(382): yii\db\ActiveRecord::getDb() #1 /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php(418): yii\db\ActiveRecord::getTableSchema() #2 /var/www/html/site.info/vendor/yiisoft/yii2/db/BaseActiveRecord.php(492): yii\db\ActiveRecord->attributes() #3 /var/www/html/site.info/vendor/yiisoft/yii2/db/BaseActiveRecord.php(289): yii\db\BaseActiveRecord->hasAttribute('__mocked') #4 /var/www/html/site.info/vendor/yiisoft/yii2/db/BaseActiveRecord.php(335): yii\db\BaseActiveRecord->__get('__mocked') #5 /var/www/html/site.info/vendor/codeception/base/src/Codeception/Step.php(176): yii\db\BaseActiveRecord->__isset('__mocked') #6 /var/www/html/site.info/vendor/codeception/base/src/Codeception/Step.php(164): Codeception\Step->getC in /var/www/html/site.info/vendor/yiisoft/yii2/db/ActiveRecord.php:135 PHP Fatal error: Uncaught Error: Call to a member function has() on null in /var/www/html/site.info/vendor/yiisoft/yii2/web/ErrorHandler.php:91 Stack trace: #0 /var/www/html/site.info/vendor/yiisoft/yii2/base/ErrorHandler.php(262): yii\web\ErrorHandler->renderException(Object(yii\base\ErrorException)) #1 [internal function]: yii\base\ErrorHandler->handleFatalError() #2 {main} thrown in /var/www/html/site.info/vendor/yiisoft/yii2/web/ErrorHandler.php on line 91 

It was thought that the problem was in the used memory, since the error always occurred in the place where the memory used by the test was displayed at 68 megabytes, no matter what role they started. Raised all the limits in php.ini FPM, codeception.yml, php.ini CLI, but this is probably not the problem. Tell me which way to dig.

    1 answer 1

    Since I do not know the whole story, I dare to point out that such breakdowns of the database can occur when it comes to multithreading. If yes, then you need to force the restart of the database in each executing thread. How to do it nugglte, or in the evening after work, look, look at myself

    V2.0 In testing, it seems that the DB is not used directly, but instead, mockup data is written, similar to the entries in the table.

    • The test is constructed in such a way - all roles from the database are obtained, and for each individual role, accessibility checks are performed on all routes on the site, and then the results are compared with the permissions for each role. Roles are tested sequentially. - John Roget
    • @JohnRoget AccessControl to help you. Set up the dots correctly, and don’t suffer from such tests) - Alex Khonko
    • The fact is that this is in fact the Legacy code and its testing has already revealed a bunch of jambs, I still want to finish the job, because unexpected things come out in unexpected places. And the roles work like, just a test should be some kind. - John Roget