hugues-m / phpunit-vw

VW PHPUnit extension makes your failing test cases succeed under CI tools scrutiny
MIT License
1.75k stars 37 forks source link

Feature request: Report 1/2 memory #8

Open hopeseekr opened 9 years ago

hopeseekr commented 9 years ago

Please have PHPUnit report half the amount of actual memory used in the CI environment ;-)

hugues-m commented 9 years ago

Any idea how to spoof memory_get_peak_usage() ? ^^

radekk commented 9 years ago

You could use runkit extension. Remember to set appropriate flag (internal_override) inside php configuration file i.e. /etc/php/5.5/conf.d/ext-runkit.ini:

[runkit]
extension="/usr/local/opt/php55-runkit/runkit.so"
runkit.internal_override = On

Result:

php > var_dump(memory_get_peak_usage());
int(236288)
php > runkit_function_copy('memory_get_peak_usage', 'memory_get_peak_usage_old');
php > runkit_function_redefine('memory_get_peak_usage', '', 'return (memory_get_peak_usage_old() / 2);');
php > var_dump(memory_get_peak_usage());
int(122432)

Ref:

evillemez commented 9 years ago

+1 my job depends on this

hugues-m commented 9 years ago

The moment you install the runkit extension you loose the battle !
It would be easy to even rewrite PhpUnit methods to display unicorns instead of test results. But I don't see any dev in his right mind installing this php extension, and I think part of the fun of this component is its ease of installation and usage ^^

hopeseekr commented 9 years ago

We will not say how I know this, but you can manipulate the literal text of PHPUnit using ob_get_clean() and judicious use of preg_replace() followed with an echo. Try doing this in your endTestSuite() of the listener.