Question

I currently have multiple test runners which only differs from each other in the working directory. All of them uses the same bootstrap.php which configures the class autoload. I recently added test group annotations to my tests and I exclude tests depending on PHP versions. Currently I add test runner options for example --exclude-group closure-binding under php 5.4, but for those I have to duplicate every test runner and set the options manually. I think it would be much better if I could add modifications to the bootstrap.php and setup the group exclusion from there. Is there a way to do that?

(phpunit version 3.7.x)

Était-ce utile?

La solution 2

According to Sebastian, it is not possible, I have to use the @requires annotation instead of that.

note: The @requires annotation works well, but I always got parse error because of the usage of yield and ::class in the lower versions... So I ended up not to care about this, however I'll keep the annotations. Maybe later I'll write a project which can automatically comment out test code depending on the annotation and the php version.

For the case the code is not parsable by older php versions, yo have to move it to separate files, give them appropriate suffixes and set a configuration xml file like this:

    <testsuite name="unit tests">
        <directory suffix="Test.php" phpVersion="5.3.0" phpVersionOperator=">=">test/unit</directory>
        <directory suffix="Test54.php" phpVersion="5.4.0" phpVersionOperator=">=">test/unit</directory>
        <directory suffix="Test55.php" phpVersion="5.5.0" phpVersionOperator=">=">test/unit</directory>
    </testsuite>

Autres conseils

Don't think you can do that on your bootstrap.php but you can use different XML configuration files, with distinct group configurations (example copied from the docs):

File: closure-binding.xml

<groups>
  <include>
    <group>whatever</group>
  </include>
  <exclude>
    <group>closure-binding</group>
  </exclude>
</groups>

phpunit -c closure-binding.xml

Is this what you need?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top