sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.67k stars 2.2k forks source link

Support testsuite-specific bootstrap scripts #3795

Open sebastianbergmann opened 5 years ago

sebastianbergmann commented 5 years ago

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 commented 5 years ago

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.

othercorey commented 4 years ago

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

mariusjp commented 1 year ago

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!

chadyred commented 2 months ago

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.

roxblnfk commented 2 months ago

Hi.

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