繁体   English   中英

在代码接收中丢失会话/ Cookie-如何保持登录我的网站的状态?

[英]Loses session/cookies in codeception - how can I stay logged into my site?

这是我正在运行的代码:

$zf1 = $this->getModule('ZF1');
$zf1->_loadPage('POST', '/user/login', $params);
$zf1->setCookie('PHPSESSID', $zf1->grabCookie('PHPSESSID'));

输出看起来像这样:

[Page] /user/login
[Response] 200
[Request Cookies] []
[Response Headers] []
[Session] []
[Cookie Jar] []
[Cookie Jar] ["PHPSESSID=; path=/; httponly"]

它没有显示标题或cookie。

我正在尝试测试登录该站点,获取cookie,然后将cookie设置为执行其他操作。

此外,还使用REST模块进行了测试:

$this->getModule('REST')->sendPOST('/user/login', $params);
$this->debugSection('Cookies', $this->getModule('REST')->client->getCookieJar()->all());

尽管它具有Set-Cookie标头,但它也不会返回cookie:

[Request headers] []
[Request] POST https://www.domain.com/user/login {"email":"testing@testing.com","password":"testing"}
[Response] <html> ....html goes here..... </html>
[Headers] {"Date":["Thu, 10 Dec 2015 07:29:07 GMT"],"Server":["Apache/2.4.16 (Unix) PHP/7.0.0 OpenSSL/0.9.8zg"],"X-Powered-By":["PHP/7.0.0"],"Set-Cookie":["PHPSESSID=d8ov6rpd7ggg00npe4dinubpi7; path=/"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate"],"Pragma":["no-cache"],"Content-Length":["866"],"Content-Type":["text/html; charset=UTF-8"]}
[Status] 200
[Cookies] [{}]

到底是怎么回事? 我使用的是Codeception版本2.1.4和PHP7。我也尝试过使用PHP 5.5获得相同的结果。 并且也运行了“ composer update”,但这并没有改变任何东西。

codeception.yml

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    colors: true
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed
modules:
    config:
        Db:
            dsn: 'mysql:host=127.0.0.1;dbname=somedb_test'
            user: 'root'
            password: ''
            dump: tests/_data/dump.sql
            populate: true
            cleanup: false
            reconnect: true

functional.suite.yml:

class_name: FunctionalTester
modules:
    enabled:
        - ZF1:
        - Db
        - \Helper\Functional
        - REST:
            depends: PhpBrowser
            url: 'https://www.domain.com'
    config:
        ZF1:
            env: testing
            config: application/configs/application.ini
            app_path: application
            lib_path: library

UPDATE

现在...我真的很困惑。 我能够登录,但是尝试在助手中调用_request()之后,它将丢失会话? 例如,

我可以使用$ I-> amOnPage(...),它会转到该页面,但随后我尝试执行_request(),请求调用不再具有该会话?

它执行以下操作,并且已明确记录,但随后丢失了会话?:

    $I->amOnPage('/');
    $I->login();
    $I->amOnPage('/user/questions');
    $I->see('No active questions');
    $I->sendPOST('/chat/upload', $params, $files);

sendPOST是这样的:

$this->getModule('ZF1')->_loadPage('POST', $uri, $params, $files);

已经发布了一个类似的问题,但与我的问题不同( Codeception:保持登录状态

如果我用amOnPage替换sendPost,它将维护会话(wtf ???)

显然,在REST模块中定义了一个名为sendPOST的辅助方法与sendPOST冲突,因此它实际上并未执行我的代码。 我将其重命名,然后开始工作。 并且,报告给Codeception: https : //github.com/Codeception/Codeception/issues/2627

我在functional.suite.yml中同时启用了ZF1和REST模块。

在我的\\ Helper \\ Functional.php的FunctionalTester帮助器类中,我有一个名为sendPOST的方法。 从我的* Cest类调用sendPOST时,它将在REST模块中执行sendPOST。 将sendPOST重命名为其他名称后,它可以工作了。

的确,我可能不需要同时加载两个ZF1 / REST模块(这对此代码接收功能仍然是新的),但是即使如此,它也从未引发过错误,即存在重复的sendPOST方法并导致混乱。 理想情况下,它将对重复方法引发异常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM