以下是我正在运行的代码:
$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和PHP 7.我也尝试使用PHP 5.5,结果相同。并且也运行'作曲家更新',但这并没有改变任何东西。
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()之后会丢失会话?例如,
我可以使用$ I-&gt; 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: Keep a logged in state)
不同如果我用amOnPage替换sendPost,它会保持会话(wtf ???)
答案 0 :(得分:0)
显然,定义一个名为sendPOST的辅助方法与REST模块中的sendPOST冲突,因此它实际上并没有执行我的代码。我重命名它然后它开始工作。并报告给代码:https://github.com/Codeception/Codeception/issues/2627
我在functional.suite.yml中启用了ZF1和REST模块。
在我的FunctionalTester帮助器类\ Helper \ Functional.php中,我有一个名为sendPOST的方法。从我的* Cest类调用sendPOST时,它将在REST模块中执行sendPOST。将sendPOST重命名为其他功能之后。
确实,我可能不需要同时加载ZF1 / REST模块(对于这个代码问题仍然是新的),但即便如此,它也从未触发错误,即存在重复的sendPOST方法并导致混乱。理想情况下,它会抛出关于重复方法的例外。