fmalk / codeigniter-phpunit

Hack to make CodeIgniter work with PHPUnit.
234 stars 61 forks source link

Using session error #10

Closed AlessandroMinoccheri closed 10 years ago

AlessandroMinoccheri commented 10 years ago

Hi all, I'm trying to test a model which use sessions.

This is my test code:

        $CI =& get_instance();
        $CI->load->model('backend/Booking_Model');

        $CI->session->set_userdata('username', 'administrator');
        $CI->session->set_userdata('user_id', '1');
        $CI->session->set_userdata('agency_id', '1');

        $return = $CI->Booking_Model->add_booking($data, $CI->Hotel_Model->getLastBookingHotelDatabase());

Return me some error like this:

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at /var/www/public/project.com/application/tests/._CITest.php:1)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 675</p>

How can I use session?

Thanks

AlessandroMinoccheri commented 10 years ago

I have already solved in this way:

        $CI =& get_instance();
        $CI->load->model('backend/Booking_Model');
        $CI->load->model('backend/User_Model');

        require_once(BASEPATH.'libraries/Session.php');
        $this->_ci->session = $this->getMock('CI_Session');
        $this->_ci->session->set_userdata('username', 'administrator');
        $this->_ci->session->set_userdata('user_id', '1');
        $this->_ci->session->set_userdata('agency_id', '1');

        $data = array(
            "0" => array(
                "provider_id" => 3,
                "provider_code" => 'DB_0000000135_2014/0',
                "provider_reference" => $CI->Hotel_Model->getLastBookingHotelDatabase(),
                "booking_status_id" => 2,
                "room_code" => '2'
            )
        );