Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support cookie testing in controller tests #88

Merged
merged 3 commits into from
Jan 8, 2016
Merged

Conversation

kenjis
Copy link
Owner

@kenjis kenjis commented Jan 7, 2016

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
Copy link

esetnik commented Jan 7, 2016

@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
Copy link
Owner Author

kenjis commented Jan 7, 2016

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
Copy link
Owner Author

kenjis commented Jan 7, 2016

@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
Copy link
Owner Author

kenjis commented Jan 8, 2016

All tests pass on my Linux...

@kenjis
Copy link
Owner Author

kenjis commented Jan 8, 2016

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

@kenjis
Copy link
Owner Author

kenjis commented Jan 8, 2016

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.

None yet

2 participants