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 ability to set custom filename rewrite callbacks #2116

Closed
wants to merge 1 commit into from

Conversation

YuriyNasretdinov
Copy link

We implemented "soft mocks" project that is intended to be able to replace runkit and uopz. We do it by rewriting code "on the fly".

Project: https://github.com/badoo/soft-mocks

We used Soft Mocks to rewrite our tests (60k tests) so that PHP7 is supported on our website.

Here is the suggested patch to be able to use Soft Mocks with phpunit.

@YuriyNasretdinov
Copy link
Author

Here is an example of test that passes with our patches:

https://github.com/badoo/soft-mocks/blob/master/example-phpunit/ExampleTest.php

@YuriyNasretdinov
Copy link
Author

Here is an article that talks a little bit about history of Soft Mocks as well:

https://techblog.badoo.com/blog/2016/03/14/how-badoo-saved-one-million-dollars-switching-to-php7/

@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Mar 14, 2016
@sebastianbergmann
Copy link
Owner

Thank you for your contribution. It looks interesting but at first glance I do not fully understand why it does what and how and what the consequences of merging it may be. I will try to look into this ASAP but it might take a while.

@sebastianbergmann
Copy link
Owner

By any chance, is there English documentation available for Soft Mocks?

@YuriyNasretdinov
Copy link
Author

English documentation for Soft Mocks is on the way. It should be there in
several hours. Patch is needed because phpunit "sniffs" too much about file
names that are loaded :)
On Mon, 14 Mar 2016 at 20:09, Sebastian Bergmann notifications@github.com
wrote:

By any chance, is there English documentation available for Soft Mocks?


Reply to this email directly or view it on GitHub
#2116 (comment)
.

@YuriyNasretdinov
Copy link
Author

English README is complete: https://github.com/badoo/soft-mocks/blob/master/README.md

@sebastianbergmann
Copy link
Owner

Thank you, Yuriy, for providing English documentation for Soft Mocks.

After reading "Soft Mocks will work even without any phpunit patches" I have to say, though, that my motivation to add additional complexity to PHPUnit for this is rather limited. The two limitations listed, "unreadable" stack traces and not being able to redefine code units declared in test code, don't sound too bad, to be honest.

@YuriyNasretdinov
Copy link
Author

You haven't seen this ugly stack trace yet. It contains paths to
autogenerated files and has additional layers of soft mocks wrappers which
make understanding the trace much more difficult. Actually you modify stack
trace for the same reasons, I guess ;), in order to make stacktrace
readable and not containing trace lines from the framework itself.

I agree that modification is done in a very "straightforward" fashion and
there are probably better ways to be able to hook into phpunit code during initialization in bootstrap.php (providing ability to enable and disable soft mocks usage on-the-fly instead of doing it using a config file). I
could not find better solution after spending some time with phpunit
codebase, sadly.

Soft Mocks is intended to be runkit and uopz-compatible and a lot of tests
that people wrote using these extensions are unusable now. At least in our
repository several hundred tests were assuming that you can redefine code
in test files so it was worth it for us to add this functionality than to
rewrite a lot of tests.
So, basically, these patches are just intended to provide more consistency
and usability for our framework which usually is not a bad thing :).
On Tue, 15 Mar 2016 at 10:34, Sebastian Bergmann notifications@github.com
wrote:

Thank you, Yuriy, for providing English documentation for Soft Mocks.

After reading "Soft Mocks will work even without any phpunit patches" I
have to say, though, that my motivation to add additional complexity to
PHPUnit for this is rather limited. The two limitations listed,
"unreadable" stack traces and not being able to redefine code units
declared in test code, don't sound too bad, to be honest.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:

#2116 (comment)

@sebastianbergmann
Copy link
Owner

Thank you for your contribution but I decided not to merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants