Application handler functionality #4068

Merged
merged 1 commit into from Mar 25, 2017

Conversation

Projects
None yet
2 participants
@janhenkgerritsen
Contributor

janhenkgerritsen commented Mar 20, 2017

A generic solution for handling issues such as reported in #4062.

The names of the new methods are haveApplicationHandler and clearApplicationHandlers, I am open to suggestions for better names.

An example test using this functionality would be:

<?php
$I = new FunctionalTester($scenario);

$I->haveApplicationHandler(function($app) {
    $app->make('config')->set(['test_value' => 10]);
});
$I->sendGET('/test-value');
$I->see('Test value is 10');

$I->haveApplicationHandler(function($app) {
    $app->make('config')->set(['test_value' => 15]);
});
$I->sendGET('/test-value');
$I->see('Test value is 15');

$I->clearApplicationHandlers();
$I->sendGET('/test-value');
$I->see('Test value is 5'); // 5 is the default value
@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Mar 21, 2017

Member

What else can be done inside haveApplicationHandler?
What other purposes than changing config?

Member

DavertMik commented Mar 21, 2017

What else can be done inside haveApplicationHandler?
What other purposes than changing config?

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Mar 21, 2017

Contributor

You can change whatever you want via the Laravel application object, this is just a generic implementation to give users this ability.

One other example would be overriding bindings in the container, however, the Laravel module already has a few dedicated methods for this like haveBinding, haveInstance, etc.

I could also have created a dedicated method such as haveConfigValue, but I think this generic approach is better. I don't think the use case of changing config values between multiple requests in the same test warrants a new method, and this new generic functionality also allows users to do other things we haven't thought of right now.

One other option is to implement this functionality as a hidden API method and not as public methods, so users have to access it via a helper. But personally I like the current implementation better.

Contributor

janhenkgerritsen commented Mar 21, 2017

You can change whatever you want via the Laravel application object, this is just a generic implementation to give users this ability.

One other example would be overriding bindings in the container, however, the Laravel module already has a few dedicated methods for this like haveBinding, haveInstance, etc.

I could also have created a dedicated method such as haveConfigValue, but I think this generic approach is better. I don't think the use case of changing config values between multiple requests in the same test warrants a new method, and this new generic functionality also allows users to do other things we haven't thought of right now.

One other option is to implement this functionality as a hidden API method and not as public methods, so users have to access it via a helper. But personally I like the current implementation better.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Mar 25, 2017

Member

Thanks

Member

DavertMik commented Mar 25, 2017

Thanks

@DavertMik DavertMik merged commit 3cdb383 into Codeception:2.2 Mar 25, 2017

3 of 4 checks passed

semaphoreci The build failed on Semaphore.
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
wercker/build Wercker pipeline passed
Details

chris1312 added a commit to chris1312/Codeception that referenced this pull request Jun 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment