Codeception: [Yii2] A new `\Yii::$app everywhere` sometimes is NULL in 2.4.1

Created on 5 Apr 2018  ยท  16Comments  ยท  Source: Codeception/Codeception

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
Yii

Most helpful comment

@SamMousa gc_collect_cycles(); helped to clear the error. I have no problems with errorHandler

All 16 comments

Hi @nnrudakov, at the start of each testcase you should get a fresh application.
At the end of a test case the application is destroyed.

Could you provide the test output when running with --debug ?

[Database] Transaction cancelled; all changes reverted.
ForumProfileCest: User not found with other email
Signature: tests\functional\ForumProfileCest:userNotFoundWithOtherEmail
Test: tests/functional/ForumProfileCest.php:userNotFoundWithOtherEmail
Scenario --
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [Fixtures] Done
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;dbname=fckfan_test'
  [Database] Transaction started for: pgsql:host=localhost;dbname=fckfan_test
 tests\functional\BaseCest: login "Step\\Functional\\Login"
   I am logged in as "app\\models\\User"
  [yii\web\Session::open] 'Session started'
  [yii\web\User::login] 'User \'1\' logged in from  with duration 0.'
 I am going to check user with different email
 PASSED 

  [Database] Transaction cancelled; all changes reverted.
ForumProfileCest: Send confirmation email when other email
Signature: tests\functional\ForumProfileCest:sendConfirmationEmailWhenOtherEmail
Test: tests/functional/ForumProfileCest.php:sendConfirmationEmailWhenOtherEmail
Scenario --
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [Fixtures] Done
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
 ERROR 

  Starting application
ForumProfileCest: Confirm and connect profile success
Signature: tests\functional\ForumProfileCest:confirmAndConnectProfileSuccess
Test: tests/functional/ForumProfileCest.php:confirmAndConnectProfileSuccess
Scenario --
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [Fixtures] Done
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;dbname=fckfan_test'
  [Database] Transaction started for: pgsql:host=localhost;dbname=fckfan_test
 tests\functional\BaseCest: login "Step\\Functional\\Login"
   I am logged in as "app\\models\\User"
  [yii\web\Session::open] 'Session started'
  [yii\web\User::login] 'User \'1\' logged in from  with duration 0.'
 I am going to confirm success other email
 Page\Forum: confirm {"email":"[email protected]"}
   I am on route "/forum/profile-confirm",{"email":"[email protected]"}
  [Request Headers] []
  [fan] []

  [Redirect with headers]Array
  (
      [location] => Array
          (
              [0] => http://localhost/forum/profile
          )

      [content-type] => Array
          (
              [0] => text/html; charset=UTF-8
          )

  )

  [Page] /forum/profile-confirm?email=samojlov.olga%40ustinov.ru
  [Response] 302
  [Request Cookies] []
  [Response Headers] {"location":["http://localhost/forum/profile"],"content-type":["text/html; charset=UTF-8"]}
  [Redirecting to] http://localhost/forum/profile
  [fan] [
      'method' => 'app\\models\\User::updateProfileApp',
      'response' => 'yii\\web\\ServerErrorHttpException: User\'s auth data not found. in /home/rudnik/www/fckfan/models/User.php:536
  ]

  [Page] http://localhost/forum/profile
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I don't see in current url "profile-confirm"
 I see in current url "profile"
 PASSED 

  [Database] Transaction cancelled; all changes reverted.

The application gets destroyed when an exception occurs. At that point the application gets reset which means Yii::$app is no longer set.

I'll look into it in more detail tomorrow.

I reckon it's related to this line: https://github.com/Codeception/Codeception/blob/2.4/src/Codeception/Lib/Connector/Yii2.php#L191

I guess I could just remove it since there's no real reason not to have the app available for inspection, even when it has failed.

4924 should fix this.

Nope. Didn't fixed.
In 2.4.0 again:

Codeception PHP Testing Framework v2.4.0
Powered by PHPUnit 7.1.2 by Sebastian Bergmann and contributors.
[Groups] ttest 

Acceptance Tests (0) -------------------------------------------

Functional Tests (25) ----------------------------------------------
โœ” ApiCest: No methods (0.01s)
โœ” ApiCest: Api list (0.00s)
โœ” ApiCest: Wrong method (0.00s)
โœ” ApiCest: Api refresh auth key (1.11s)
โœ” ApiCest: Show login form (0.06s)
โœ” BonusesCest: View bonuses (0.49s)
โœ” BonusesCest: Fail getting bonuses (0.47s)
โœ” DepositCest: View connect form (0.49s)
โœ” DepositCest: View transactions with update (0.52s)
โœ” DepositCest: View transactions without update (0.53s)
โœ” DepositCest: Update balance (0.55s)
โœ” DepositCest: Update transactions (0.52s)
โœ” FanProfileCest: View profile (0.48s)
โœ” FanProfileCest: Validate profile (0.75s)
โœ” FanProfileCest: Update profile (0.54s)
โœ” ForumProfileCest: View redirect when not connected (0.52s)
โœ” ForumProfileCest: View form when not connected and not found (0.48s)
โœ” ForumProfileCest: View form when not connected but found (0.48s)
โœ” ForumProfileCest: Connect profile with the same email (0.43s)
โœ” ForumProfileCest: User not found with other email (0.44s)
โœ” ForumProfileCest: Send confirmation email when other email (0.43s)
โœ” ForumProfileCest: Confirm and connect profile success (1.54s)
โœ” ForumProfileCest: Confirm and connect profile fail (0.51s)
โœ” ForumProfileCest: View redirect from confirm (0.55s)
โœ” ForumProfileCest: View profile (0.59s)
------------------------------------------------------------------------

Unit Tests (0) ------------------------------------------------------
Time: 173 ms, Memory: 48.00MB

OK (25 tests, 47 assertions)

I've noticed that every 17-th, 18-th test fails. Look at the same tests in 2.4.1 (with your fix of course):

Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 7.1.2 by Sebastian Bergmann and contributors.
[Groups] ttest 

Acceptance Tests (0) ---------------------------------------

Functional Tests (25) ----------------------------------------------------
โœ” ApiCest: No methods (0.01s)
โœ” ApiCest: Api list (0.00s)
โœ” ApiCest: Wrong method (0.00s)
โœ– ApiCest: Api refresh auth key (0.51s)
1) โœ” ApiCest: Show login form (0.03s)
2) โœ” BonusesCest: View bonuses (0.51s)
3) โœ” BonusesCest: Fail getting bonuses (0.48s)
4) โœ” DepositCest: View connect form (0.49s)
5) โœ” DepositCest: View transactions with update (0.52s)
6) โœ” DepositCest: View transactions without update (0.54s)
7) โœ” DepositCest: Update balance (0.52s)
8) โœ” DepositCest: Update transactions (0.53s)
9) โœ” FanProfileCest: View profile (0.48s)
10) โœ” FanProfileCest: Validate profile (0.55s)
11) โœ” FanProfileCest: Update profile (0.51s)
12) โœ” ForumProfileCest: View redirect when not connected (0.48s)
13) โœ” ForumProfileCest: View form when not connected and not found (0.48s)
14) โœ” ForumProfileCest: View form when not connected but found (0.49s)
15) โœ” ForumProfileCest: Connect profile with the same email (0.44s)
16) โœ” ForumProfileCest: User not found with other email (0.44s)
17) E ForumProfileCest: Send confirmation email when other email (0.44s)
โœ” ForumProfileCest: Confirm and connect profile success (1.50s)
โœ” ForumProfileCest: Confirm and connect profile fail (0.48s)
โœ” ForumProfileCest: View redirect from confirm (0.52s)
โœ” ForumProfileCest: View profile (0.53s)
--------------------------------------------------------------------------

Unit Tests (0) -----------------------------------------------------


Time: 11.75 seconds, Memory: 42.00MB

There was 1 error:

---------
1) ForumProfileCest: Send confirmation email when other email
 Test  tests/functional/ForumProfileCest.php:sendConfirmationEmailWhenOtherEmail

  [Error] Call to a member function getDb() on null  

#1  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/db/ActiveRecord.php:135
#2  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/db/ActiveRecord.php:382
#3  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/db/ActiveRecord.php:211
#4  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/db/ActiveRecord.php:190
#5  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/db/BaseActiveRecord.php:112
#6  /home/rudnik/www/fckfan/models/Group.php:96
#7  /home/rudnik/www/fckfan/models/ProfileMain.php:126
#8  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/base/Model.php:454
#9  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/base/Model.php:420
#10 /home/rudnik/www/fckfan/vendor/yiisoft/yii2/base/Model.php:189

--

There was 1 failure:

---------
1) ApiCest: Api refresh auth key
 Test  tests/functional/ApiCest.php:apiRefreshAuthKey
Form element with '#login-form' was not found.

Scenario Steps:

 6. $I->submitForm("#login-form",{"LoginForm[email]":"[email protected]","LoginForm[password]":"123456"}) at tests/functional/ApiCest.php:70
 5. $I->amOnRoute("/site/login") at tests/functional/ApiCest.php:67
 4. $I->see("error") at tests/functional/ApiCest.php:66
 3. $I->amOnRoute("/fcapi/refresh") at tests/functional/ApiCest.php:65
 2. // I expect to see error when user not logged in
 1. // I am going to refresh user's key


ERRORS!
Tests: 25, Assertions: 45, Errors: 1, Failures: 1.

Firstable, why '#login-form' was not found? But just a moment ago in 2.4.0 there were ok. And the 17-th test after broken test failed. Now, let exclude the ApiCest:

Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 7.1.2 by Sebastian Bergmann and contributors.
[Groups] ttest 

Acceptance Tests (0) ---------------------------------------

Functional Tests (20) ---------------------------------------------------
1) โœ” BonusesCest: View bonuses (0.55s)
2) โœ” BonusesCest: Fail getting bonuses (0.48s)
3) โœ” DepositCest: View connect form (0.49s)
4) โœ” DepositCest: View transactions with update (0.52s)
5) โœ” DepositCest: View transactions without update (0.54s)
6) โœ” DepositCest: Update balance (0.52s)
7) โœ” DepositCest: Update transactions (0.53s)
8) โœ” FanProfileCest: View profile (0.49s)
9) โœ” FanProfileCest: Validate profile (0.55s)
10) โœ” FanProfileCest: Update profile (0.51s)
11) โœ” ForumProfileCest: View redirect when not connected (0.48s)
12) โœ” ForumProfileCest: View form when not connected and not found (0.49s)
13) โœ” ForumProfileCest: View form when not connected but found (0.49s)
14) โœ” ForumProfileCest: Connect profile with the same email (0.44s)
15) โœ” ForumProfileCest: User not found with other email (0.44s)
16) โœ” ForumProfileCest: Send confirmation email when other email (0.44s)
17) โœ” ForumProfileCest: Confirm and connect profile success (1.51s)
18) E ForumProfileCest: Confirm and connect profile fail (0.49s)
โœ” ForumProfileCest: View redirect from confirm (0.51s)
โœ” ForumProfileCest: View profile (0.52s)
------------------------------------------------------------------------

Unit Tests (0) -----------------------------------------------------
1) ForumProfileCest: Confirm and connect profile fail
 Test  tests/functional/ForumProfileCest.php:confirmAndConnectProfileFail

  [Error] Call to a member function getRequest() on null  


Scenario Steps:

 3. $I->amOnRoute("/forum/profile-confirm",{"email":""}) at tests/_support/Page/Forum.php:42
 2. // I am going to confirm fail other email
 1. $I->amLoggedInAs("app\\models\\User") at tests/_support/Step/LoginTrait.php:30

#1  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/helpers/BaseHtml.php:302
#2  yii\helpers\BaseHtml::csrfMetaTags
#3  /home/rudnik/www/fckfan/vendor/yiisoft/yii2-twig/ViewRendererStaticClassProxy.php:78
#4  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Extension/Core.php:1605
#5  /home/rudnik/www/fckfan/vendor/yiisoft/yii2-twig/Template.php:55
#6  /home/rudnik/www/fckfan/runtime/twig/cache/cf/cff4ea4639d8f9d5cd29786d1dcd3e6ba4098001f8f3199774b3636abf2ccfb3.php:49
#7  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:390
#8  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:367
#9  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:375
#10 /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Environment.php:289


Time: 11.23 seconds, Memory: 40.00MB

There was 1 error:

---------

ERRORS!
Tests: 20, Assertions: 33, Errors: 1.

You see, the 18-th test failed. Now exclude the BonusesCest:

Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 7.1.2 by Sebastian Bergmann and contributors.
[Groups] ttest 

Acceptance Tests (0) ---------------------------------------------

Functional Tests (18) --------------------------------------------------
1) โœ” DepositCest: View connect form (0.55s)
2) โœ” DepositCest: View transactions with update (0.54s)
3) โœ” DepositCest: View transactions without update (0.53s)
4) โœ” DepositCest: Update balance (0.52s)
5) โœ” DepositCest: Update transactions (0.53s)
6) โœ” FanProfileCest: View profile (0.48s)
7) โœ” FanProfileCest: Validate profile (0.55s)
8) โœ” FanProfileCest: Update profile (0.51s)
9) โœ” ForumProfileCest: View redirect when not connected (0.48s)
10) โœ” ForumProfileCest: View form when not connected and not found (0.48s)
11) โœ” ForumProfileCest: View form when not connected but found (0.49s)
12) โœ” ForumProfileCest: Connect profile with the same email (0.44s)
13) โœ” ForumProfileCest: User not found with other email (0.44s)
14) โœ” ForumProfileCest: Send confirmation email when other email (0.44s)
15) โœ” ForumProfileCest: Confirm and connect profile success (1.51s)
16) โœ” ForumProfileCest: Confirm and connect profile fail (0.48s)
17) โœ” ForumProfileCest: View redirect from confirm (0.53s)
18) E ForumProfileCest: View profile (0.52s)
------------------------------------------------------------------------

Unit Tests (0) -------------------------------------------------
1) ForumProfileCest: View profile
 Test  tests/functional/ForumProfileCest.php:viewProfile

  [Error] Call to a member function getRequest() on null  


Scenario Steps:

 3. $I->amOnRoute("/forum/profile") at tests/_support/Page/Forum.php:37
 2. // I am going to view page when profile connected
 1. $I->amLoggedInAs("app\\models\\User") at tests/_support/Step/LoginTrait.php:30

#1  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/helpers/BaseHtml.php:302
#2  yii\helpers\BaseHtml::csrfMetaTags
#3  /home/rudnik/www/fckfan/vendor/yiisoft/yii2-twig/ViewRendererStaticClassProxy.php:78
#4  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Extension/Core.php:1605
#5  /home/rudnik/www/fckfan/vendor/yiisoft/yii2-twig/Template.php:55
#6  /home/rudnik/www/fckfan/runtime/twig/cache/cf/cff4ea4639d8f9d5cd29786d1dcd3e6ba4098001f8f3199774b3636abf2ccfb3.php:49
#7  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:390
#8  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:367
#9  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:375
#10 /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Environment.php:289


Time: 10.24 seconds, Memory: 40.00MB

There was 1 error:

---------

ERRORS!
Tests: 18, Assertions: 29, Errors: 1.

The 18-th test failed also. And when I exclude the DepositCest then ForumProfileCest would be passed.

@nnrudakov Please run the tests with --debug and provide only the output of the failing test and the test before the failing test.

Here, please

  [Transaction] Rolling back 1 transactions
  [Database] Transaction cancelled; all changes reverted.
ForumProfileCest: View redirect from confirm
Signature: tests\functional\ForumProfileCest:viewRedirectFromConfirm
Test: tests/functional/ForumProfileCest.php:viewRedirectFromConfirm
Scenario --
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [Fixtures] Done
  Transaction
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;dbname=fckfan_test'
  [Database] Transaction started for: pgsql:host=localhost;dbname=fckfan_test
 tests\functional\BaseCest: login "Step\\Functional\\Login"
   I am logged in as "app\\models\\User"
  [yii\web\Session::open] 'Session started'
  [yii\web\User::login] 'User \'1\' logged in from  with duration 0.'
 I am going to redorect when profile is connected
 Page\Forum: confirm {"email":""}
   I am on route "/forum/profile-confirm",{"email":""}
  [Request Headers] []
  [fan] [
      'method' => 'app\\components\\Apps::load',
      'response' => [

      ],
  ]
  [Redirect with headers]Array
  (
      [location] => Array
          (
              [0] => http://localhost/forum/profile
          )

      [content-type] => Array
          (
              [0] => text/html; charset=UTF-8
          )

  )

  [Page] /forum/profile-confirm?email=
  [Response] 302
  [Request Cookies] []
  [Response Headers] {"location":["http://localhost/forum/profile"],"content-type":["text/html; charset=UTF-8"]}
  [Redirecting to] http://localhost/forum/profile
  [fan] [
      'method' => 'app\\models\\User::updateProfileApp',
      'response' => 'yii\\web\\ServerErrorHttpException: User\'s auth data not found. in /home/rudnik/www/fckfan/models/User.php:536

  ]
  [fan] [
      'method' => 'rudnik\\FanApi\\Api::request',
      'response' => 'yii\\base\\Exception: Invalid access token. in /home/rudnik/www/fckfan/vendor/yiisoft/yii2-authclient/src/BaseOAuth.php:298

  ]
  [fan] [
      'method' => 'app\\controllers\\NewsController::actionImportant',
      'response' => 'yii\\base\\Exception: Invalid access token. in /home/rudnik/www/fckfan/vendor/yiisoft/yii2-authclient/src/BaseOAuth.php:298

  ]
  [Page] http://localhost/forum/profile
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I don't see in current url "profile-confirm"
 PASSED 

  [Transaction] Rolling back 1 transactions
  [Database] Transaction cancelled; all changes reverted.
ForumProfileCest: View profile
Signature: tests\functional\ForumProfileCest:viewProfile
Test: tests/functional/ForumProfileCest.php:viewProfile
Scenario --
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [Fixtures] Done
  Transaction
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;dbname=fckfan_test'
  [Database] Transaction started for: pgsql:host=localhost;dbname=fckfan_test
 tests\functional\BaseCest: login "Step\\Functional\\Login"
   I am logged in as "app\\models\\User"
  [yii\web\Session::open] 'Session started'
  [yii\web\User::login] 'User \'1\' logged in from  with duration 0.'
 I am going to view page when profile connected
 Page\Forum: profile 
   I am on route "/forum/profile"
  [Request Headers] []
  [fan] [
      'method' => 'app\\components\\Apps::load',
      'response' => [

      ],
  ]
  [fan] [
      'method' => 'app\\models\\User::updateProfileApp',
      'response' => 'yii\\web\\ServerErrorHttpException: User\'s auth data not found. in /home/rudnik/www/fckfan/models/User.php:536
  Stack trace:
  #0 /home/rudnik/www/fckfan/models/User.php(485): app\\models\\User->updateProfileApp(Object(app\\models\\ProfileApp))
  #1 /home/rudnik/www/fckfan/controllers/ForumController.php(204): app\\models\\User->getProfileApp(\'irPWI0tp_SVvATq...\', true)
  #2 /home/rudnik/www/fckfan/controllers/ForumController.php(129): app\\controllers\\ForumController->getProfile(true)
  #3 [internal function]: app\\controllers\\ForumController->actionProfile()
  #4 /home/rudnik/www/fckfan/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #5 /home/rudnik/www/fckfan/vendor/yiisoft/yii2/base/Controller.php(157): yii\\base\\InlineAction->runWithParams(Array)
  #6 /home/rudnik/www/fckfan/vendor/yiisoft/yii2/base/Module.php(528): yii\\base\\Controller->runAction(\'profile\', Array)
  #7 /home/rudnik/www/fckfan/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction(\'forum/profile\', Array)
  #8 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Lib/Connector/Yii2.php(178): yii\\web\\Application->handleRequest(Object(app\\components\\Request))
  #9 /home/rudnik/www/fckfan/vendor/symfony/browser-kit/Client.php(312): Codeception\\Lib\\Connector\\Yii2->doRequest(Object(Symfony\\Component\\BrowserKit\\Request))
  #10 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(193): Symfony\\Component\\BrowserKit\\Client->request(\'GET\', \'http://localhos...\', Array, Array, Array, NULL, true)
  #11 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Module/Yii2.php(719): Codeception\\Lib\\InnerBrowser->clientRequest(\'GET\', \'/forum/profile\', Array, Array, Array, NULL, true)
  #12 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(241): Codeception\\Module\\Yii2->clientRequest(\'GET\', \'/forum/profile\', Array, Array, Array, NULL)
  #13 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(345): Codeception\\Lib\\InnerBrowser->_loadPage(\'GET\', Array)
  #14 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Module/Yii2.php(699): Codeception\\Lib\\InnerBrowser->amOnPage(Array)
  #15 [internal function]: Codeception\\Module\\Yii2->amOnRoute(\'/forum/profile\')
  #16 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Step.php(264): call_user_func_array(Array, Array)
  #17 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Scenario.php(72): Codeception\\Step->run(Object(Codeception\\Lib\\ModuleContainer))
  #18 /home/rudnik/www/fckfan/tests/_support/_generated/FunctionalTesterActions.php(667): Codeception\\Scenario->runStep(Object(Codeception\\Step\\Condition))
  #19 /home/rudnik/www/fckfan/tests/_support/Page/Forum.php(37): FunctionalTester->amOnRoute(\'/forum/profile\')
  #20 /home/rudnik/www/fckfan/tests/functional/ForumProfileCest.php(170): Page\\Forum->profile()
  #21 [internal function]: tests\\functional\\ForumProfileCest->viewProfile(Object(FunctionalTester))
  #22 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Lib/Di.php(127): ReflectionMethod->invokeArgs(Object(tests\\functional\\ForumProfileCest), Array)
  #23 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Test/Cest.php(138): Codeception\\Lib\\Di->injectDependencies(Object(tests\\functional\\ForumProfileCest), \'viewProfile\', Array)
  #24 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Test/Cest.php(150): Codeception\\Test\\Cest->invoke(\'viewProfile\', Array)
  #25 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Test/Cest.php(82): Codeception\\Test\\Cest->executeTestMethod(Object(FunctionalTester))
  #26 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Test/Test.php(89): Codeception\\Test\\Cest->test()
  #27 /home/rudnik/www/fckfan/vendor/phpunit/phpunit/src/Framework/TestSuite.php(776): Codeception\\Test\\Test->run(Object(PHPUnit\\Framework\\TestResult))
  #28 /home/rudnik/www/fckfan/vendor/codeception/phpunit-wrapper/src/Runner.php(114): PHPUnit\\Framework\\TestSuite->run(Object(PHPUnit\\Framework\\TestResult))
  #29 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/SuiteManager.php(157): Codeception\\PHPUnit\\Runner->doEnhancedRun(Object(Codeception\\Suite), Object(PHPUnit\\Framework\\TestResult), Array)
  #30 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Codecept.php(189): Codeception\\SuiteManager->run(Object(Codeception\\PHPUnit\\Runner), Object(PHPUnit\\Framework\\TestResult), Array)
  #31 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception\\Codecept->runSuite(Array, \'functional\', NULL)
  #32 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Command/Run.php(466): Codeception\\Codecept->run(\'functional\')
  #33 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Command/Run.php(361): Codeception\\Command\\Run->runSuites(Array, Array)
  #34 /home/rudnik/www/fckfan/vendor/symfony/console/Command/Command.php(252): Codeception\\Command\\Run->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #35 /home/rudnik/www/fckfan/vendor/symfony/console/Application.php(865): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #36 /home/rudnik/www/fckfan/vendor/symfony/console/Application.php(241): Symfony\\Component\\Console\\Application->doRunCommand(Object(Codeception\\Command\\Run), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #37 /home/rudnik/www/fckfan/vendor/symfony/console/Application.php(143): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #38 /home/rudnik/www/fckfan/vendor/codeception/codeception/src/Codeception/Application.php(108): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #39 /home/rudnik/www/fckfan/vendor/codeception/codeception/codecept(42): Codeception\\Application->run()
  #40 {main}',
  ]
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
  Destroying application
 ERROR 

  [Transaction] Rolling back 1 transactions
  [Database] Transaction cancelled; all changes reverted.
  Starting application
  Suite done, restoring $_SERVER to original
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Unit Tests (0) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Asserts, \Helper\Unit, Yii2, Redis
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Suite done, restoring $_SERVER to original
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) ForumProfileCest: View profile
 Test  tests/functional/ForumProfileCest.php:viewProfile

  [Error] Call to a member function getRequest() on null  


Scenario Steps:

 3. $I->amOnRoute("/forum/profile") at tests/_support/Page/Forum.php:37
 2. // I am going to view page when profile connected
 1. $I->amLoggedInAs("app\\models\\User") at tests/_support/Step/LoginTrait.php:30

#1  /home/rudnik/www/fckfan/vendor/yiisoft/yii2/helpers/BaseHtml.php:302
#2  yii\helpers\BaseHtml::csrfMetaTags
#3  /home/rudnik/www/fckfan/vendor/yiisoft/yii2-twig/ViewRendererStaticClassProxy.php:78
#4  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Extension/Core.php:1605
#5  /home/rudnik/www/fckfan/vendor/yiisoft/yii2-twig/Template.php:55
#6  /home/rudnik/www/fckfan/runtime/twig/cache/cf/cff4ea4639d8f9d5cd29786d1dcd3e6ba4098001f8f3199774b3636abf2ccfb3.php:49
#7  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:390
#8  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:367
#9  /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Template.php:375
#10 /home/rudnik/www/fckfan/vendor/twig/twig/lib/Twig/Environment.php:289
  Destroying application


Time: 10.27 seconds, Memory: 40.00MB

There was 1 error:

---------

ERRORS!
Tests: 18, Assertions: 29, Errors: 1.

@SamMousa , have you a good news? How could I help you else?

Will try to spend some time on it today

I have the same issue

@puku are you on the absolute latest version? This should be resolved there...

We have the same error on version 2.4.1. Having looked at https://github.com/Codeception/Codeception/commit/08e487b0854bcc1f8a8478a5d5b7cf9713cbbc76#diff-94abe3ee46e86aa1477f9565b6d2f9f5L52 I can assume that the method Codeception\Lib\Connector\Yii2::__destruct is called with a delay while there is another instance of the application in Yii::$app from another test

Yes that's why we no longer use the destructor.

I just noticed something similar myself which seems to be related to the errorhandler component not getting unregistered.
@mikebelozorov could you check if changing resetApplication works?

public function resetApplication()
    {
        codecept_debug('Destroying application');
        if (isset(Yii::$app) && Yii::$app->has('errorHandler', true)) {
            Yii::$app->errorHandler->unregister();
        }
        Yii::$app = null;
        \yii\web\UploadedFile::reset();
        if (method_exists(\yii\base\Event::className(), 'offAll')) {
            \yii\base\Event::offAll();
        }
        Yii::setLogger(null);
        // This resolves an issue with database connections not closing properly.
        gc_collect_cycles();
    }

I'll make a PR today or tomorrow.

@SamMousa gc_collect_cycles(); helped to clear the error. I have no problems with errorHandler

may be open issue?

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.

Was this page helpful?
0 / 5 - 0 ratings