Codeception: [Yii2] A new `\Yii::$app everywhere` sometimes is NULL in 2.4.1
What are you trying to achieve?
I’m trying to run tests after update from 2.4.0.
What do you get instead?
Some tests fails. Output in 2.4.0
Codeception PHP Testing Framework v2.4.0
Powered by PHPUnit 7.1.15 by Sebastian Bergmann and contributors.
Acceptance Tests (0) ---------------------------------------
Functional Tests (62) --------------------------------------
✔ ApiCest: No methods (0.17s)
✔ ApiCest: Api list (0.07s)
✔ ApiCest: Wrong method (0.09s)
✔ ApiCest: Api refresh auth key (8.72s)
✔ ApiCest: Show login form (0.40s)
✔ BonusesCest: View bonuses (2.17s)
✔ BonusesCest: Fail getting bonuses (1.60s)
✔ DepositCest: View connect form (2.54s)
✔ DepositCest: View transactions with update (3.20s)
✔ DepositCest: View transactions without update (1.96s)
✔ DepositCest: Update balance (2.13s)
✔ DepositCest: Update transactions (1.86s)
✔ FanProfileCest: View profile (4.65s)
✔ FanProfileCest: Validate profile (6.02s)
✔ FanProfileCest: Update profile (3.44s)
✔ FanbaseCest: View connect form (1.62s)
✔ FanbaseCest: Retry verification code (1.48s)
✔ ForumProfileCest: View redirect when not connected (1.61s)
✔ ForumProfileCest: View form when not connected and not found (2.63s)
✔ ForumProfileCest: View form when not connected but found (1.63s)
✔ ForumProfileCest: Connect profile with the same email (4.03s)
✔ ForumProfileCest: User not found with other email (1.57s)
✔ ForumProfileCest: Send confirmation email when other email (2.03s)
✔ ForumProfileCest: Confirm and connect profile success (3.09s)
✔ ForumProfileCest: Confirm and connect profile fail (1.67s)
✔ ForumProfileCest: View redirect from confirm (1.92s)
✔ ForumProfileCest: View profile (2.35s)
Output in 2.4.1 (fails in ForumProfileCest: View form when not connected but found):
Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 7.1.15 by Sebastian Bergmann and contributors.
Acceptance Tests (0) ---------------------------------------------------
Functional Tests (64) ---------------------------------------------------
✔ ApiCest: No methods (0.01s)
✔ ApiCest: Api list (0.00s)
✔ ApiCest: Wrong method (0.00s)
✔ ApiCest: Api refresh auth key (0.95s)
✔ ApiCest: Show login form (0.03s)
✔ BonusesCest: View bonuses (0.50s)
✔ BonusesCest: Fail getting bonuses (0.48s)
✔ DepositCest: View connect form (0.50s)
✔ DepositCest: View transactions with update (0.54s)
✔ DepositCest: View transactions without update (0.53s)
✔ DepositCest: Update balance (0.51s)
✔ DepositCest: Update transactions (0.53s)
✔ FanProfileCest: View profile (0.49s)
✔ FanProfileCest: Validate profile (0.54s)
✔ FanProfileCest: Update profile (0.51s)
✔ FanbaseCest: View connect form (0.49s)
✔ FanbaseCest: Retry verification code (0.51s)
✔ ForumProfileCest: View redirect when not connected (0.48s)
✔ ForumProfileCest: View form when not connected and not found (0.49s)
E ForumProfileCest: View form when not connected but found (0.44s)
✔ ForumProfileCest: Connect profile with the same email (1.50s)
✔ ForumProfileCest: User not found with other email (0.48s)
✔ ForumProfileCest: Send confirmation email when other email (0.48s)
✔ ForumProfileCest: Confirm and connect profile success (1.50s)
✔ ForumProfileCest: Confirm and connect profile fail (0.48s)
✔ ForumProfileCest: View redirect from confirm (0.51s)
✔ ForumProfileCest: View profile (0.51s)
Error:
[Error] Call to a member function getDb() on null
It happens at yii\db\ActiveRecord::getDb
when calling Yii::$app
.
If I exclude FanbaseCest
an error appears in ForumProfileCest: Send confirmation email when other email
and previous finish with success. If I exclude BonusesCest
an error appears in ForumProfileCest: Confirm and connect profile fail
and other with success. But in this case it was:
[Error] Call to a member function getUrlManager() on null
when calling Yii::$app
also.
From different set of tests on null
error may appears in any place with different Yii::$app
calls. I can’t catch where exactly and what’s wrong in tests. But if I run tests separately, one by one, all of them finished with success!
Details
- Codeception version: 2.4.1
- PHP Version: 7.0, 7.1
- Operating System: Ubuntu
- Installation type: Composer
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 16
@SamMousa gc_collect_cycles(); helped to clear the error. I have no problems with errorHandler
This issue is not open, this issue is resolved you were just not using the latest version of the code.
gc_collect_cycles
has been in the code for a while.