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

PhpUnit: How to covers action

Hi all.

I would like to do phpUnit covers of my project actions .

I already covered models.

Does anybody know, how cover actions or where I can read about that?



3.5k
Accepted
answer

Ok, I resolved it.

I use Guzzle for this.

If somebody want knows how to do it I show my example code.

  1. Install Guzzle. Add to your composer.json next "guzzle/guzzle":"~3.9" or use php composer.phar require guzzle/guzzle:~3.9

  2. My test Class extends UnitTestCase

Code example

class UserControllerTest extends \UnitTestCase
{
    /**
     * @covers Controllers\UserController::loginAction
     */
    public function testLoginAction()
    {
        $client = new \Guzzle\Http\Client();

        $nickname = 'User nickName';
        $data = array(
            'nickname' => $nickname,
            'avatarNumber' => 5,
            'tagLine' => 'a test dev!'
        );

        $request = $client->post('https://my_site_url/api/user/login', null, $data);
        $response = $request->send();
        $response->getBody(true);
    }
}

It is simple example :)

That is all.

Thanks all.