Welcome Guest, Not a member yet? Register   Sign In
testing redirect in controllers

here is the following method inside the controller I am trying to test:
function index(){
$data['username'] = $this->session->userdata('username');
$data['path'] = $this->session->userdata('logo');
$this->load->view('home', $data);

//If no session, redirect to login page
redirect('login', 'refresh');

here is the test method:
public function test_index($userid, $username, $logo_path, $permissions, $tour, $is_admin, $expected){

        //to skip this test uncomment below line

        $_SESSION = [
            'userid' => $userid,
            'username' => $username,
            'logo' => $logo_path,
            'permissions' => $permissions,
            'tour' => $tour,
            'is_admin' => $is_admin

        $output = $this->request('GET', ['Home', 'index']);

        //check if redirect or not
            $this->assertContains($expected, $output);

I keep getting the following error: 
Risky Test: Test code or tested code did not (only) close its own output buffers. 
I don't know what am I doing wrong? Can someone please help

Well, I guess I found a temporary solution. The ci_phpunit-test framework throws an exception and causes phpunit to consider it as a risky test. What I did is I did not throw the exception and saved in the $_SERVER variable that the redirect function was called. I am a newbie and this is my first internship and I believe there are better solutions out there.

Theme © iAndrew 2016 - Forum software by © MyBB