这是我正在运行的代码:
$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());
它也不会返回cookie,尽管它有Set 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版本和PHP 7。我也刚刚尝试了PHP 5.5,得到了同样的结果。并运行了"composer update",但这并没有改变任何事情。
共感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()后,它会丢失会话??例如,
我可以使用$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??)
显然,定义一个名为sendPOST的助手方法与REST模块中的sendPOST冲突,因此它实际上并没有执行我的代码。我重新命名了它,然后它开始工作。并且,向codeception报告:https://github.com/Codeception/Codeception/issues/2627
我在函数.suite.yml.中启用了ZF1和REST模块
在''helper''Functional.php中的FunctionalTester助手类中,我有一个名为sendPOST的方法。当从我的*Cest类调用sendPOST时,它将在REST模块中执行sendPOST。将sendPOST重命名为其他名称后,它就工作了。
的确,我可能不需要同时加载ZF1/REST模块(对于这个代码感知来说仍然是新的),但即使如此,它也从未触发错误,即存在重复的sendPOST方法并导致混乱。理想情况下,它会抛出一个关于重复方法的异常。