Skip to content

Add support cookie testing in controller tests - #88

Merged
kenjis merged 3 commits into
masterfrom
cookie-testing
Jan 8, 2016
Merged

Add support cookie testing in controller tests#88
kenjis merged 3 commits into
masterfrom
cookie-testing

Conversation

@kenjis

@kenjis kenjis commented Jan 7, 2016

Copy link
Copy Markdown
Owner

This PR adds the functionality to test response cookies in controller testing.
See #86.

controller:

        $cookie = [
            'name'   => 'The-Cookie-Name',
            'value'  => 'The Value',
            'expire' => '86500',
            'domain' => '.some-domain.com',
            'path'   => '/',
            'prefix' => 'myprefix_',
            'secure' => TRUE
        ];
        $this->input->set_cookie($cookie);

You can assert the cookie value.

test code:

        $output = $this->request('GET', 'set_cookie/all_params');
        $this->assertResponseCookie(
            'myprefix_The-Cookie-Name', 'The Value'
        );

You can also assert more cookie params.

test code:

        $cookie = [
            'value'  => 'The Value',
            'domain' => '.some-domain.com',
            'path'   => '/',
            'secure' => TRUE,
            'httponly' => FALSE,
        ];
        $this->assertResponseCookie(
            'myprefix_The-Cookie-Name', $cookie
        );

@esetnik

esetnik commented Jan 7, 2016

Copy link
Copy Markdown

@kenjis it's working well for me. I did notice that the PR is failing tests due to CI_Input::post() expected to be invoked 1 times, but invoked 0 times.

I'm getting the same error in my tests when I try to use $this->verifyInvokedOnce() but it's not specific to this PR it also fails with that error on v0.10.1

@kenjis

kenjis commented Jan 7, 2016

Copy link
Copy Markdown
Owner Author

Thank you.

Yes, I have to check the test. I will look into it.
Actually, all the tests pass on my Mac OS X.

@kenjis

kenjis commented Jan 7, 2016

Copy link
Copy Markdown
Owner Author

@esetnik

I'm getting the same error in my tests when I try to use $this->verifyInvokedOnce() but it's not specific to this PR it also fails with that error on v0.10.1

The error with this PR is using MonkeyPatch::verifyInvokedOnce(), not $this->verifyInvokedOnce().
And $this->verifyInvokedOnce() is just a wrapper to method of PHPUnit mock object.
I think your error has nothing to do with the error.

@kenjis

kenjis commented Jan 8, 2016

Copy link
Copy Markdown
Owner Author

All tests pass on my Linux...

@kenjis

kenjis commented Jan 8, 2016

Copy link
Copy Markdown
Owner Author

I was able to reproduce the fail. It seems there is a bug in build process for travis-ci.

@kenjis

kenjis commented Jan 8, 2016

Copy link
Copy Markdown
Owner Author

No, it is a bug in Monkey Patching.

kenjis added a commit that referenced this pull request Jan 8, 2016
Add support cookie testing in controller tests
@kenjis
kenjis merged commit 6fedc84 into master Jan 8, 2016
@kenjis
kenjis deleted the cookie-testing branch January 8, 2016 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants