Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access PHPUNIT_SELENIUM_TEST_ID cookie in PHPUnit Coverage

To use phpunit_coverage.php I need to set auto_prepend_file and auto_append_file properties in php.ini to specified files prepend.php and append.php. In both scripts cookies are checked to make sure that test is running:

if ( isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) &&

The problem is that this cookie is kept as localhost's cookie, not the webserver's. So when it is checked, it is not set and xdebug doesn't start.

Selenium and webserver are located on different machines, could this be the cause of this error?

Situation is displayed here:

firefox cookies manager

like image 508
Ilya Khaustov Avatar asked Dec 13 '25 16:12

Ilya Khaustov


1 Answers

Similar issue. I thought at first of a domain problem as the tested web site is on a vhost.

But I found out that calling $this->url('some_url') seemed to silently delete the PHPUNIT_SELENIUM_TEST_ID cookie.

My workaround was overriding the url() method in my test cases, in order to reset the cookie once url() is called.

protected function url($url =null)
{
    try {
        $cookie = $this->cookie()->get('PHPUNIT_SELENIUM_TEST_ID');
    }
    catch (Exception $e) {}

    $result = parent::url($url);

    if (isset($cookie)) {
        $this->cookie()->add('PHPUNIT_SELENIUM_TEST_ID', $cookie)->set();
    }

    return $result;
}

The code coverage files are now correctly created.

like image 149
Jérôme Avatar answered Dec 15 '25 16:12

Jérôme



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!