在代码接收中丢失 session/cookies - 我怎样才能保持登录到我的网站?

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"]

没有显示 headers 或 cookie。

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

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

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

它也不是 return cookie,尽管它有 Set-Cookie header:

[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 和 PHP 7。我也刚刚尝试使用 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

更新

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

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

它执行以下操作并清楚地记录下来,但随后丢失了 session?:

    $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: Keep a logged in state)

如果我将 sendPost 替换为 amOnPage,它会保持 session (wtf???)

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

I had both the ZF1 and REST module enabled in my functional.suite.yml.

In my FunctionalTester helper class in \Helper\Functional.php I had a method called sendPOST. When calling sendPOST from my *Cest class it would execute the sendPOST in the REST module. After renaming sendPOST to something else it worked.

It's true I probably don't need to load both the ZF1/REST module at the same time (still new to this codeception thing), but even so it never triggered an error that there was a duplicate sendPOST method and led to confusion. Ideally it'll throw an exception about the duplicate methods.