Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional test error #221

Closed
ilgiz-badamshin opened this issue Nov 22, 2016 · 2 comments
Closed

Functional test error #221

ilgiz-badamshin opened this issue Nov 22, 2016 · 2 comments
Assignees
Milestone

Comments

@ilgiz-badamshin
Copy link

ilgiz-badamshin commented Nov 22, 2016

What steps will reproduce the problem?

  • Create new application.
  • Create component:
class Bootstrapit implements BootstrapInterface
{
    public function bootstrap($app)
    {
        Yii::warning(Yii::$app->user->id, 'Bootstrapit');
    }
}
  • Add component to config file (frontend/main.php) :
    'bootstrap' => ['log', 'bootstrapit'],
  'components' => [
        'bootstrapit' => [
            'class' => 'frontend\components\Bootstrapit',
        ],
  • Run test from frontend folder: codecept run functional LoginCest:checkValidLogin -d

What's expected?

Test run seccesseful.

What do you get instead?

Test failed because user is not authorized.
Login link displayed in file ./_output/frontend.tests.functional.LoginCest.checkValidLogin.fail.html

Additional info

Run with default bootstrap config 'bootstrap' => ['log']:

Codeception PHP Testing Framework v2.2.6
Powered by PHPUnit 5.6.2 by Sebastian Bergmann and contributors.

Frontend\tests.functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Filesystem, Yii2
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LoginCest: Check valid login
Signature: frontend\tests\functional\LoginCest:checkValidLogin
Test: tests/functional/LoginCest.php:checkValidLogin
Scenario --
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;port=5432;dbname=yii-advanced-test'
 I have fixtures {"user":{"class":"common\\fixtures\\User","dataFile":"\/home\/ilgiz\/www\/yii-advanced\/frontend\/tests\/_data\/login_data.php"}}
 I am on route "site/login"
  [Request Headers] []
  [yii\web\Session::open] 'Session started'
  [Page] /index-test.php?r=site%2Flogin
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I submit form "#login-form",{"LoginForm[username]":"erau","LoginForm[password]":"password_0"}
  [Uri] http://localhost/index-test.php?r=site%2Flogin
  [Method] POST
  [Parameters] {"_csrf-frontend":"MDJKUzg4RUVzcT4xVQEXBEoLfioMC3BoVGUGElpKKzVxcy85YA8gKQ==","LoginForm[username]":"erau","LoginForm[password]":"password_0","LoginForm[rememberMe]":"1"}
  [Request Headers] []
  [yii\web\Session::init] 'Session is already started'
  [yii\web\User::login] 'User \'1\' logged in from  with duration 2592000.'
  [Headers] {"location":["http://localhost/index-test.php"],"content-type":["text/html; charset=UTF-8"]}
  [Page] http://localhost/index-test.php?r=site%2Flogin
  [Response] 302
  [Request Cookies] {"_csrf-frontend":"e71763b6459091306d0c8602d59a4743afea9154f6c55b6061ed5a53756e0302a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"CCtbm9RAz94y435-dWLAbrnpAAejX7el";}"}
  [Response Headers] {"location":["http://localhost/index-test.php"],"content-type":["text/html; charset=UTF-8"]}
  [Redirecting to] http://localhost/index-test.php
  [yii\web\Session::init] 'Session is already started'
  [Page] http://localhost/index-test.php
  [Response] 200
  [Request Cookies] {"_csrf-frontend":"e71763b6459091306d0c8602d59a4743afea9154f6c55b6061ed5a53756e0302a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"CCtbm9RAz94y435-dWLAbrnpAAejX7el";}","_identity-frontend":"f7f720c2399fcc76711a4807c955fdd6a3925dabcd428a71a25a5da857f7a8b4a:2:{i:0;s:18:"_identity-frontend";i:1;s:46:"[1,"tUu1qHcde0diwUol3xeI-18MuHkkprQI",2592000]";}"}
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I see "Logout (erau)","form button[type=submit]"
 I don't see link "Login"
 I don't see link "Signup"
 PASSED 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 641 ms, Memory: 23.25MB

OK (1 test, 1 assertion)

Run with my bootstrap 'bootstrap' => ['log', 'bootstrapit'], :

Codeception PHP Testing Framework v2.2.6
Powered by PHPUnit 5.6.2 by Sebastian Bergmann and contributors.

Frontend\tests.functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Filesystem, Yii2
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LoginCest: Check valid login
Signature: frontend\tests\functional\LoginCest:checkValidLogin
Test: tests/functional/LoginCest.php:checkValidLogin
Scenario --
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;port=5432;dbname=yii-advanced-test'
 I have fixtures {"user":{"class":"common\\fixtures\\User","dataFile":"\/home\/ilgiz\/www\/yii-advanced\/frontend\/tests\/_data\/login_data.php"}}
 I am on route "site/login"
  [Request Headers] []
  [yii\web\Session::open] 'Session started'
  [Page] /index-test.php?r=site%2Flogin
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I submit form "#login-form",{"LoginForm[username]":"erau","LoginForm[password]":"password_0"}
  [Uri] http://localhost/index-test.php?r=site%2Flogin
  [Method] POST
  [Parameters] {"_csrf-frontend":"aC1FV3hnUDgaHg0/KBcADQJfdhkcHxtQIhlyGhQWEUkNfjQZCSRnSw==","LoginForm[username]":"erau","LoginForm[password]":"password_0","LoginForm[rememberMe]":"1"}
  [Request Headers] []
  [yii\web\Session::init] 'Session is already started'
  [Bootstrapit] null
  [yii\web\User::login] 'User \'1\' logged in from  with duration 2592000.'
  [Headers] {"location":["http://localhost/index-test.php"],"content-type":["text/html; charset=UTF-8"]}
  [Page] http://localhost/index-test.php?r=site%2Flogin
  [Response] 302
  [Request Cookies] {"_csrf-frontend":"6db06f60475e3bdf8350671e7e7cf7e7feb1878d020227d8e7411fa5e15ef6b0a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"r3HhPpP5jr3NdxKhJ47MlqAqeSqNqC7s";}"}
  [Response Headers] {"location":["http://localhost/index-test.php"],"content-type":["text/html; charset=UTF-8"]}
  [Redirecting to] http://localhost/index-test.php
  [yii\web\Session::init] 'Session is already started'
  [yii\db\Connection::open] 'Opening DB connection: pgsql:host=localhost;port=5432;dbname=yii-advanced-test'
  [Bootstrapit] null
  [Page] http://localhost/index-test.php
  [Response] 200
  [Request Cookies] {"_csrf-frontend":"6db06f60475e3bdf8350671e7e7cf7e7feb1878d020227d8e7411fa5e15ef6b0a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"r3HhPpP5jr3NdxKhJ47MlqAqeSqNqC7s";}","_identity-frontend":"f7f720c2399fcc76711a4807c955fdd6a3925dabcd428a71a25a5da857f7a8b4a:2:{i:0;s:18:"_identity-frontend";i:1;s:46:"[1,"tUu1qHcde0diwUol3xeI-18MuHkkprQI",2592000]";}"}
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I see "Logout (erau)","form button[type=submit]"
 FAIL 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 658 ms, Memory: 23.25MB

There was 1 failure:

---------
1) LoginCest: Check valid login
 Test  tests/functional/LoginCest.php:checkValidLogin
 Step  See "Logout (erau)","form button[type=submit]"
 Fail  Element located either by name, CSS or XPath element with 'form button[type=submit]' was not found.

Scenario Steps:

 4. $I->see("Logout (erau)","form button[type=submit]") at tests/functional/LoginCest.php:45
 3. $I->submitForm("#login-form",{"LoginForm[username]":"erau","LoginForm[password]":"password_0"}) at tests/functional/LoginCest.php:44
 2. $I->amOnRoute("site/login") at tests/functional/LoginCest.php:18
 1. $I->haveFixtures({"user":{"class":"common\\fixtures\\User","dataFile":"\/home\/ilgiz\/www\/yii-advanced\/frontend\/tests\/_data\/login_data.php"}}) at tests/functional/LoginCest.php:17


FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

When i try to access to Yii::$app->user-id, application create new db connection, out of the transaction which used for user fixtures, so application can't find User model and client stay as guest.
Have you any ideas why it happened?

Q A
Yii vesion 2.0.10
PHP version 5.6.23
Operating system 14.04.1-Ubuntu
@samdark
Copy link
Member

samdark commented Nov 2, 2017

Verified. No idea why it happens though.

@samdark samdark added the type:bug Bug label Nov 2, 2017
@samdark samdark added this to the 2.0.x milestone Nov 2, 2017
@samdark samdark added the status:ready for adoption Feel free to implement this issue. label Nov 2, 2017
SilverFire added a commit to SilverFire/base that referenced this issue Nov 2, 2017
SilverFire added a commit to SilverFire/Codeception that referenced this issue Nov 2, 2017
@samdark samdark removed this from the 2.0.x milestone Nov 2, 2017
@SilverFire
Copy link
Member

To be fixed in codeception repo Codeception/Codeception#4601

@SilverFire SilverFire added this to the 2.0.13 milestone Nov 2, 2017
@SilverFire SilverFire self-assigned this Nov 2, 2017
@SilverFire SilverFire removed the status:ready for adoption Feel free to implement this issue. label Nov 2, 2017
@samdark samdark closed this as completed Nov 2, 2017
samdark pushed a commit to Codeception/Codeception that referenced this issue Nov 2, 2017
Naktibalda pushed a commit to Codeception/module-yii2 that referenced this issue Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants