Codeception / module-yii2

Codeception module for Yii2 framework
MIT License
16 stars 36 forks source link

Set Session inside functional test #25

Closed davist11 closed 2 years ago

davist11 commented 4 years ago

What are you trying to achieve?

I'm trying to set a session variable inside of a functional test (which is required by the template)

What do you get instead?

 Test  tests/functional/UserGroupPermissionsCest.php:noAccessUserGroup

  [Exception] No content was sent from Yii application  

Scenario Steps:

 1. $I->amOnPage("/discounts") at tests/functional/UserGroupPermissionsCest.php:51

/var/www/html/vendor/codeception/codeception/src/Codeception/Lib/Connector/Yii2.php:364
/var/www/html/vendor/symfony/browser-kit/Client.php:407
/var/www/html/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:216
/var/www/html/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:715
/var/www/html/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:264
/var/www/html/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php:368
/var/www/html/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:698
/var/www/html/vendor/codeception/codeception/src/Codeception/Step.php:266
/var/www/html/vendor/codeception/codeception/src/Codeception/Scenario.php:72
/var/www/html/tests/_support/_generated/FunctionalTesterActions.php:515
/var/www/html/tests/functional/UserGroupPermissionsCest.php:51
/var/www/html/vendor/codeception/codeception/src/Codeception/Lib/Di.php:127
/var/www/html/vendor/codeception/codeception/src/Codeception/Test/Cest.php:138
/var/www/html/vendor/codeception/codeception/src/Codeception/Test/Cest.php:150
/var/www/html/vendor/codeception/codeception/src/Codeception/Test/Cest.php:82
/var/www/html/vendor/codeception/codeception/src/Codeception/Test/Test.php:88
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:746
/var/www/html/vendor/codeception/phpunit-wrapper/src/Runner.php:118
/var/www/html/vendor/codeception/codeception/src/Codeception/SuiteManager.php:158
/var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php:193
/var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php:160
/var/www/html/vendor/codeception/codeception/src/Codeception/Command/Run.php:391
/var/www/html/vendor/symfony/console/Command/Command.php:255
/var/www/html/vendor/symfony/console/Application.php:1012
/var/www/html/vendor/symfony/console/Application.php:272
/var/www/html/vendor/symfony/console/Application.php:148
/var/www/html/vendor/codeception/codeception/src/Codeception/Application.php:107
/var/www/html/vendor/codeception/codeception/codecept:43
public function noAccessUserGroup(FunctionalTester $I)
{
    $session = new Session();
    $session->open();
    $session['profile'] = 'some session data';
    $session->close();

    $I->amOnPage('/discounts');
    $I->cantSee('Discounts');
    $I->see('Access Denied');
}

Details

actor: FunctionalTester
modules:
    enabled:
        - \craft\test\Craft
        - \Helper\Functional
    step_decorators: ~
Naktibalda commented 4 years ago

Looks like Yii2 issue to me.

SamMousa commented 3 years ago

Well first of all, that way is not the best way to open a session it makes a lot of assumptions about internal implementation of the Session component..

Try using Yii::$app. Second, the error means the yii application did not send data or the module was not able to capture it. So I'd look at how your code generates its output.

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.