0

I'm trying to use Sessions in my application. However, I fail to get them to work in a very simple phpunit test. Take the following test:

<?php

namespace Tests\App;

class SessionTest extends \PHPUnit_Framework_TestCase
{

    public function testSession()
    {
        $session = new \Phalcon\Session\Adapter\Files(array('uniqueId' => 'my-private-app'));
        $session->start();

        $session->set('foo', 'bar');
        $this->assertEquals('bar', $session->get('foo'));
    }

}

Which results in:

There was 1 failure:

1) Tests\App\SessionTest::testSession Failed asserting that null matches expected 'bar'.

Am I missing something here? According to the docs, that's exactly how the simple session should be working.

Using var_dump on the session object right after $session->start() also reveals that the session object believes not be started:

class Phalcon\Session\Adapter\Files#226 (3) {
  protected $_uniqueId =>
  string(14) "my-private-app"
  protected $_started =>
  bool(false)
  protected $_options =>
  array(1) {
    'uniqueId' =>
    string(14) "my-private-app"
  }
}

Shouldn't there be some kind of catchable feedback that the session, apparently, has trouble starting? I'm using Phalcon 1.0.1 at the moment. Thanks in advance for any suggestion!

4

1 回答 1

1

由于 PHPUnit 会自动产生一些输出,这隐含地使要在请求中发送的标头使 Phalcon 无法启动会话。在这种情况下,您可以使用 @session_start() 强制启动会话,使 _SESSION 超全局可用

于 2013-04-29T02:53:41.350 回答