Skip to content

Add `setupFunctions()` method to `Mocker`. #871

Closed
wants to merge 1 commit into from

3 participants

@blainesch
Union of RAD member

This allows you to declare which methods you are going to define later on. This, for instance, may be helpful if something like apc is caching the full namespace of a method. The first time you call a global function, it might be cached, so stubbing it would not work.

Blaine Schmeisser Add `setupFunctions()` method to `Mocker`.
This allows you to declare which methods you are going to define later on. This, for instance, may be helpful if something like apc is caching the full namespace of a method. The first time you call a global function, it might be cached, so stubbing it would not work.
cc2638c
@blainesch
Union of RAD member

Looks like it failed hitting google.com in two of the sets in the matrix. These are integration tests, but I still feel we should be stubbing external requests. Imo death to _hasNetwork().

@nateabele
Union of RAD member

Sounds like a good opportunity to eat your own setupFunctions() dog food. ;-)

@jails
Union of RAD member
jails commented Mar 29, 2013

Yeah Google seems to fail answering pretty often...

@jails
Union of RAD member
jails commented Apr 18, 2013

Ok after some experiments looks like there's no other way to make things works w/o a executing a setup at a bootstrap level.

Maybe we can complete this PR with a kind of :

if (!Environment::is('production')) {
    Mocker::setupFunctions(array(
        'lithium\util\getmxrr',
        'lithium\console\command\shell_exec',
        'lithium\console\command\is_dir',
        'lithium\net\socket\feof',
        'lithium\net\socket\fopen',
        'lithium\net\socket\stream_socket_client',
        'lithium\net\socket\stream_get_contents',
        'lithium\net\socket\stream_context_create',
        'lithium\net\socket\stream_get_meta_data',
        'lithium\tests\cases\net\socket\stream_context_get_options',
        'lithium\net\socket\curl_init',
        'lithium\net\socket\curl_setopt',
        'lithium\net\socket\curl_close',
        'lithium\net\socket\curl_exec'
    );
}

in a config/boostrap.php in the lithium repo.

I know Environment is not accessible at this stage, but I hope we can refactor the framework on day to set the environnment earlier.

Did you find other solutions ?

@jails
Union of RAD member
jails commented Apr 20, 2013

Vote up on the bug guys: https://bugs.php.net/bug.php?id=63201, with any luck it'll be solved in the next decade ;-)

@blainesch blainesch closed this Jun 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.