TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
A bug in unittest module - Error reading session data
  • Hi, It seems to me, that when we use unittest module, and we test class uses Session following error occurs: Session_Exception: Error reading session data for unknown reasons.

    When I used phpunit.xml configuration file listen below: <phpunit colors="false" bootstrap="../../modules/unittest/bootstrap_all_modules.php"> <testsuites> <testsuite name="My Tests"> <directory>./</directory> </testsuite> </testsuites> </phpunit> and run command from tests directory (cmd: phpunit testTest.php) error occured:

    PHPUnit 3.6.7 by Sebastian Bergmann.
    Configuration read from D:\xampp\htdocs\testing_app\application\tests\phpunit.xml
    Time: 1 second, Memory: 4.75Mb
    There was 1 error:
    1) TestTest::test_add
    Session_Exception: Error reading session data.
    Tests: 1, Assertions: 0, Errors: 1.

    What is important, when I ommit bootstrap from modules/unittest/bootstrap.php and just use application index.php file

    (cmd: phpunit --bootstrap=index.php application/tests/classes/testTest.php) error gone...

    What i found more, whem i change line in test.php file in _save() method:

    $this->_example = Session::instance()->get('example', 123 );


    $this->_example = Session::instance('cookie')->get('example', 123 );

    error gone again...

    Therefore, for some unknown reasons when you use unittest module and bootstrap file from there something wrong happened with Native Session

    Files: - application/classes/test.php -> http://pastie.org/private/azdzkref9isnymjqrx5bw

    • application/tests/classes/testTest.php -> http://pastie.org/private/vphhpvxkyswdld4vkzslg

    • application/tests/phpunit.xml-> http://pastie.org/private/hdw0c8ldwvgzcbecnk6edq

  • sorry for bad formatting. Cant edit post any more..

  • Problem has been resolved. All you need is add new file application/config/session.php with custom session name.

    <?php defined('SYSPATH') or die('No direct script access.');
    return array(
        'native' => array(
            'name' => 'custom_session_name',
            'lifetime' => 60*30, 
        'cookie' => array(
            'name' => 'custom_session_name',
            'encrypted' => TRUE,
            'lifetime' => 60*30,
  • Agggrrr.... That solution works..but when I change all Session::instance('cookie') occurrences to native..but now phpunit error is back ;)..

    PS. Editing posts are off after some minutes?...

  • Workaround for Session & unittest module & phpunit from CLI: add to bootstrap.php if( Kohana::$is_cli ) { Session::$default = 'cookie'; }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion