phpcookiescloud9-idecodeception

How to use the "cookies" setting for PhpBrowser in codeception's acceptance.suite.yml?


I've tried googling this but I wasn't able to find an answer so I'm posting here.

I'm trying out codeception 2.1.5 on Cloud9 IDE using PHP 5.5.9, looking at writing acceptance tests, and configuring my acceptance.suite.yml file.

I'm trying to have a cookie included in the request made by PhpBrowser as described on the codeception PhpBrowser page. I thought I could do this with the "cookies" setting in acceptance.suite.yml.

acceptance.suite.yml

# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

class_name: AcceptanceTester
modules:
    enabled:
        - PhpBrowser:
            url: https://dm1-cboudreausf.c9users.io
            cookies: 
                 c9_user_cookie:
                    Name: c9.live.user.sso
                    Value: somevaluehere
                    Path: /
                    Domain: .c9users.io
         - \Helper\Acceptance

Here's my HomepageCept.php:

<?php 
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure the homepage renders correctly');
$I->amOnPage('/'); 
$I->see('welcome');

But when I run my test in debug mode like this:

php codecept.phar run --debug

I can see that there are no request cookies:

Ensure the homepage renders correctly (HomepageCept)
Scenario:
* I am on page "/"

  [Page] /
  [Response] 302
  [Request Cookies] []
  [Response Headers] {"Location":["https://c9users.io/_user_content/authorize?redirect=https%3A%2F%2Fdm1-cboudreausf.c9users.io%2F"],"Date":["Mon, 21 Dec 2015 22:38:44 GMT"],"Transfer-Encoding":["chunked"],"X-BACKEND":["apps-proxy"],"Content-Type":["text/html"]}
  [Redirecting to] https://c9users.io/_user_content/authorize?redirect=https%3A%2F%2Fdm1-cboudreausf.c9users.io%2F

What is the correct syntax for this??


Solution

  • Cookies parameter is not processed by PhpBrowser but passed to Guzzle HTTP Client.

    If you run your test and PHP 5.4, then you use Guzzle 5.3, http://docs.guzzlephp.org/en/5.3/clients.html?highlight=cookies

    Types: bool / array / GuzzleHttp\Cookie\CookieJarInterface

    I don't know if the format that you used works with Guzzle 5.3, but the key-value pairs should be working

    cookies: 'c9.live.user.sso': 'somevaluehere'

    If you run your test on a newer version of PHP, then you probably use Guzzle 6 http://docs.guzzlephp.org/en/latest/request-options.html#cookies
    You must specify the cookies option as a GuzzleHttp\Cookie\CookieJarInterface or false.

    I see no way cookies option could be working with Guzzle 6, so I raised the issue in Github: https://github.com/Codeception/Codeception/issues/2653.