call a controller inside a test in cakephp

1

I can not call a controller in a cakephp2 test, I want to call a controller but using App::import or App::uses will not let me, nor will I call the $this->testAction

How could I call him?

I have used it in the following way:

App::uses('Controller', 'Api2Controller');

/**
 * Api2Controller Test Case
 *
 */
class Api2ControllerTest extends ControllerTestCase {   
     // public $fixtures = array('Api2Controller.crearDireccion');

    function setUp(){
        parent::setUp();
     $this->Api2 = ClassRegistry::init('Api2Controller');
    }

    function tearDown(){
        parent::tearDown();

    }

    public function testArraySearchRecursive() {
       $this->Api2->mimetodo();
    }

but it does not work, I have also called the controller from the same method for App::import('Controller', 'Api2Controller') then I make an instance of it but I see PHP Fatal error: Class 'Api2Controller' not found

    
asked by soldat25 06.04.2016 в 05:22
source

1 answer

1

apparently this function ClassRegistry::init instance only the models and App::uses('Controller', 'Api2Controller'); was using it upside down is App::uses('Api2Controller' ,'Controller')

    
answered by 06.04.2016 в 18:20