Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



2.0k
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('http://my_site_url/api/user/login', null, $data);
        $response = $request->send();
        $response->getBody(true);
    }
}

It is simple example :)

That is all.

Thanks all.