Skip to content

Controller response property overriding by ControllerResponse inPHPUnit  #1834

Description

@plegenza

name: Controller response property overriding by ControllerResponse in PHPUnit
about: ControllerResponse instance overriding property of standard Controller in unit testing controller.


Code to reproduce:

Controller:

namespace App\Controllers;

class Home extends \CodeIgniter\Controller {
    function index() {
        $response = $this->response->setJSON([
            'lang' => $this->request->getLocale()
        ]);
    }
}

ControllerTest:

<?php

namespace Tests\Controllers;
use CodeIgniter\Test\ControllerTester;
use CodeIgniter\Test\CIDatabaseTestCase;

class HomeTest extends CIDatabaseTestCase {

    use ControllerTester;

    public function testIndex() {
        $result = $this->withURI('http://example.com/rest/')
          ->controller(\App\Controllers\Home::class)
          ->execute('index');
    }
}
  • OS: Win 7
  • XAMPP
  • 7.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions