phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

Support testsuite-specific bootstrap scripts

Open sebastianbergmann opened this issue 6 years ago • 5 comments

It should be possible to have <testsuite> specific bootstrap scripts:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.4/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         executionOrder="depends,defects"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         verbose="true">
    <testsuites>
        <testsuite name="unit">
            <directory suffix="Test.php">tests/unit</directory>
        </testsuite>

        <testsuite name="integration">
            <directory suffix="Test.php">tests/integration</directory>
            <bootstrap>tests/integration/bootstrap.php</bootstrap>
        </testsuite>

        <testsuite name="edge-to-edge">
            <directory suffix="Test.php">tests/edge-to-edge</directory>
            <bootstrap>tests/integration/bootstrap.php</bootstrap>
            <bootstrap>tests/edge-to-edge/bootstrap.php</bootstrap>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>

phpunit should load vendor/autoload.php, tests/integration/bootstrap.php, and tests/edge-to-edge/bootstrap.php.

phpunit --testsuite unit should only load vendor/autoload.php.

phpunit --testsuite integration should load vendor/autoload.php and tests/integration/bootstrap.php.

phpunit --testsuite edge-to-edge should load vendor/autoload.php, tests/integration/bootstrap.php, and tests/edge-to-edge/bootstrap.php.

Each bootstrap script, even if configured multiple times, must only be loaded once.

sebastianbergmann avatar Aug 20 '19 08:08 sebastianbergmann

For this to work properly, we need to know for each test to which <testsuite> it belongs. Otherwise we cannot skip loading bootstrap scripts that are not required when, for instance, --filter or --group are used.

sebastianbergmann avatar Aug 27 '19 11:08 sebastianbergmann

Would multiple bootstrap scripts mean the tests in the directory are iterated over once per bootstrap?

othercorey avatar Nov 25 '19 07:11 othercorey

Is this still planned to be implemented? I'm actually just now running into this "issue" where it would be most ideal to have different bootstraps (unit tests don't need a db migrate/seed but the feature tests do).

Thanks!

mariusjp avatar Jan 27 '23 11:01 mariusjp

Same here : for example, it is required for Smoke test to have a little bit of data, and nothing else fancy, so a dedicated bootstrap could be great to achieve that.

chadyred avatar Jul 07 '24 15:07 chadyred

Hi.

Is there any way inside bootstrap to know which test suite is running? Excluding hacks like $GLOBALS['argv']

roxblnfk avatar Jul 22 '24 19:07 roxblnfk