We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

responseStatusCode

Hi ; I am writing PHPUnit test cases for my application.

I wonder how can i get http status codes?

My test like this :


public function testIndexActionCanBeAccessed()
    {
        $this->application->handle('/');
        $this->assertEquals('index', $this->application->dispatcher->getActionName());
        $this->assertEquals('index', $this->application->dispatcher->getControllerName());
        $this->assertEquals('welcome', $this->application->dispatcher->getModuleName());
    }

I want to add another one assertion


$this->assertEquals(200, HTTP_RESPONSE_STATUS_CODE); 

how can i do this?

if $this->application is an instance of Phalcon\Mvc\Application you can obtain an instance of Phalcon\Http\Response this way:

$response = $this->application->handle('/');

Then:

$this->assertEquals(200, $response->getHeaders()->get("Status"));
edited Apr '15

Hello;

Yes, $this->application is an instance of Phalcon\Mvc\Application


 $response->getHeaders()->get("Status")

return fasle

I tryed in my application too . My application is working well , response content OK. but response header status return false . is it the bug or something?


    /**
     * The core of all the work of the controller occurs when handle() is invoked:
     * Gets the HTTP response body
     */
    echo $application->handle()->getContent();

    var_dump( $application->handle()->getHeaders()->get('Status')); //its render bool(false)

I am working with Phalcon Version 1.3.4.