3

Here is the code I am running:

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

The output looks like this:

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

It is displaying no headers or cookies.

I am trying to test logging into the site, get the cookie, then set the cookie to perform another action.

Also, tested using the REST module:

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

Which also doesn't return a cookie although it has the 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] [{}]

What is going on? I am using Codeception version 2.1.4 and PHP 7. I also just tried with PHP 5.5 with the same result. And ran 'composer update' too but that didn't change anything.

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

Now... I'm just really confused. I am able to login but then after I try to call _request() in my helper it loses the session?? For example,

I can use $I->amOnPage(...) and it goes to the page but then I try to perform a _request(), the request call no longer has the session?

It does the following and it is clearly logged but then loses the session?:

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

the sendPOST is this:

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

There is a similar question already posted but it's different then my problem ( Codeception: Keep a logged in state )

If I replace the sendPost with amOnPage it maintains the session (wtf???)

Community
  • 1
  • 1
Clay
  • 4,700
  • 3
  • 33
  • 49

1 Answers1

1

Apparently defining a helper method called sendPOST conflicted with the sendPOST in the REST module so it was not actually executing my code. I renamed it then it began to work. And, reported to 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.

Community
  • 1
  • 1
Clay
  • 4,700
  • 3
  • 33
  • 49