Codeception / module-yii2

Codeception module for Yii2 framework
MIT License
17 stars 35 forks source link

Yii 2: [yii\base\InvalidConfigException] Failed to instantiate component or class "db" #28

Closed samdark closed 2 years ago

samdark commented 5 years ago

See https://github.com/yiisoft/yii2-app-advanced/issues/404

What are you trying to achieve?

Connect to MongoDB and apply fixtures.

What do you get instead?

root@1a3d00a6fe60:/var/www/rest.testsite.com# ./vendor/bin/codecept run unit -c common
Codeception PHP Testing Framework v2.3.7
Powered by PHPUnit 6.4.4 by Sebastian Bergmann and contributors.

Common\tests.unit Tests (1) ---------------------------------------------------------------------------------------------------------------------------------------------------------
E LoginFormTest: Fixture user (0.11s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 1.42 seconds, Memory: 12.00MB

There was 1 error:

---------
1) LoginFormTest: Fixture user
 Test  tests/unit/models/LoginFormTest.php:testFixtureUser

  [yii\base\InvalidConfigException] Failed to instantiate component or class "db".

Codeception/Codeception#1  /var/www/rest.testsite.com/vendor/yiisoft/yii2/di/Instance.php:139
Codeception/Codeception#2  /var/www/rest.testsite.com/vendor/yiisoft/yii2/test/DbFixture.php:42
Codeception/Codeception#3  /var/www/rest.testsite.com/vendor/yiisoft/yii2/base/BaseObject.php:108
Codeception/Codeception#4  yii\base\BaseObject->__construct
Codeception/Codeception#5  /var/www/rest.testsite.com/vendor/yiisoft/yii2/di/Container.php:375
Codeception/Codeception#6  /var/www/rest.testsite.com/vendor/yiisoft/yii2/di/Container.php:156
Codeception/Codeception#7  /var/www/rest.testsite.com/vendor/yiisoft/yii2/BaseYii.php:349
Codeception/Codeception#8  /var/www/rest.testsite.com/vendor/yiisoft/yii2/test/FixtureTrait.php:208
Codeception/Codeception#9  /var/www/rest.testsite.com/vendor/yiisoft/yii2/test/FixtureTrait.php:145
Codeception/Codeception#10 /var/www/rest.testsite.com/vendor/yiisoft/yii2/test/FixtureTrait.php:112

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Details

Culprit details: https://github.com/yiisoft/yii2-app-advanced/issues/404#issuecomment-488167386

SamMousa commented 5 years ago

Could it be that fixtures are loaded too early? Need a minimal test case in codeception/yii2-tests. The hack of commenting out resetApplication() in _after() suggests that this code is called before the application is (re-)initialized.

XzAeRo commented 5 years ago

Just wanted to make a note that it seems that it doesn't matter if you're trying to use MongoDB or MySQL/MariaDB. The problem triggers with both database systems.

SamMousa commented 2 years ago

I'm closing this due to its age. If it is still relevant in current versions feel free to create a new issue.

nicomollet commented 2 years ago

I still have this issue with:

"phpunit/phpunit": "^9.3",
"codeception/codeception": "^5.0",
"codeception/verify": "^2.2",
"codeception/module-asserts": "^3.0",
"codeception/module-yii2": "^1.1",
"codeception/module-phpbrowser": "^3.0",
"codeception/module-filesystem": "^3.0 || ^1.1"

The resetApplication comment hack works, but without it I get:

[yii\di\NotInstantiableException]
Failed to instantiate component or class "db".  

Using the yii-starter-kit and trying to run tests with PHP 8 and Codeception 5. So far I can't find a definitive way to fix it.

Previously on PHP 7.4 and Codeception 2.4 and without codeception/module-yii2, run passed the tests.

SamMousa commented 2 years ago

free to create a new issue.