Skip to content

Conversation

@padraic
Copy link

@padraic padraic commented Jan 11, 2015

Should a test use register_shutdown_function(), freeing properties is likely to make this trigger a fatal error if a property is used by the function. This just adds an optional constructor flag to disable property freeing for those test files referencing register_shutdown_function().
See Issue #4

@scrutinizer-notifier
Copy link

The inspection completed: 2 updated code elements

@keyvanakbary keyvanakbary mentioned this pull request Jan 16, 2015
@keyvanakbary
Copy link
Contributor

Hi @padraic, thanks a lot for highlighting this problem. Sorry for the delay, but I've been just got back from holiday ☀️ 🌴 🍺

Getting to the point, you are correct - you should be able to skip tests, given some circumstances. The issue I have is with pushing a very intricate and particular solution to a broad reaching library like this one. This particular solution should remain in your domain, as a vast majority of users using this library do not have this issue. Thinking hard about how to solve it, I came to the conclusion that allowing an extension point for an ignore policy will suffice, so I've created a new release that includes this new feature.

Solving your problem should be as easy as implementing the IgnoreTestPolicy as follows

<?php

use MyBuilder\PhpunitAccelerator\IgnoreTestPolicy;

class ShutdownIgnoreTestPolicy implements IgnoreTestPolicy {
    public function shouldIgnore(\ReflectionObject $testReflection) {
        $fp = fopen($testReflection->getFilename(), 'rb');
        while (!feof($fp)) {
            if (false !== stripos(fread($fp, 4096), 'register_shutdown_function(')) {
                return true;
            }
        }
        fclose($fp);

        return false;
    }
}

And add the policy to the listener phpunit.xml configuration

<phpunit>
    <listeners>
        <listener class="\MyBuilder\PhpunitAccelerator\TestListener">
            <arguments>
                <object class="\Namespace\Of\Your\ShutdownIgnoreTestPolicy"/>
            </arguments>
        </listener>
    </listeners>
</phpunit>

Hope it solves your issue! Thanks a lot for your contribution 😃

@padraic
Copy link
Author

padraic commented Jan 17, 2015

I like it! Thanks for the new release also - I'll switch across to it shortly.

@padraic padraic closed this Jan 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants