evan108108 / RESTFullYii

RESTFull API for your Yii application

Home Page:http://evan108108.github.com/RESTFullYii/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I create an end to end unit test using ERestTestRequestHelper

firecentaur opened this issue · comments

Hi there, I have created my own Controller called GroupController that is set up to use restful yii.

I have created a custom DELETE behavior that checks access using Yii's built in RBAC.
I want to create a unit test to see if my delete works on the GroupController by emitting a restful yii event. I saw that Restful yii has ERestTestRequestHelper

How can I use this class in my unit tests?
Please help

@firecentaur :> Yes you can. Just take a look at the existing unit tests.

https://github.com/evan108108/RESTFullYii/blob/master/starship/RestfullYii/tests/unit/DELETEResourceUnitTest.php

Here is a sample test

public function testDELETEResourceCategoryRequest()
    {
        $request = new ERestTestRequestHelper();
        $request['config'] = [
            'url'           => 'http://api/category/4',
            'type'      => 'DELETE',
            'data'      => null,
            'headers' => [
                'X_REST_USERNAME' => 'admin@restuser',
                'X_REST_PASSWORD' => 'admin@Access',
            ],
        ];

        $request_response = $request->send();
        $expected_response = '{"success":true,"message":"Record Deleted","data":{"totalCount":1,"category":{"id":"4","name":"cat4"}}}';
        $this->assertJsonStringEqualsJsonString($request_response, $expected_response);
    }