Re: [RFC][DISCUSSION] Deprecation of fallback to root scope
| From: | Marco Pivetta | Date: | Sat, 03 Feb 2018 12:18:48 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Deprecation of fallback to root scope | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101752@lists.php.net to get a copy of this message | ||
On Sat, Feb 3, 2018 at 1:15 PM, Wes <netmo.php@gmail.com> wrote:
> question was:
> > Do I get that right that it will then no longer be possible to mock
> functions from the root namespace during tests?
> > At least when the functions are "use"d or are explicitly namespaced...
> > Being able to mock functions like "date" or "time" or
> > "mt_rand" is
> currently extremely helpful.
>
I think there's something quite broken with the current approach in mocking
core functions, specifically because already having them hardcoded in your
codebase means that the code relies on hidden shared global state.
Can strongly suggest injecting a
Clock object as is done in
https://github.com/lcobucci/clock, for example.
Same goes for sources of randomness.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/