Commands

osdd:phpunit

Sync phpunit.xml with the test suite and source directory of each layer.

osdd:phpunit adds a <testsuite> to phpunit.xml for each layer that has a tests/ folder, and adds each layer's source directory to the code coverage.

php artisan osdd:phpunit

Options

OptionDescription
--pruneRemove the test suites of layers that no longer exist, and the <source><include> directories that are gone, such as app after osdd:start.

What it does

  1. Reads phpunit.xml at the root of the project. It fails if the file or its <testsuites> element is missing, or if a layer composer.json is invalid.
  2. Excludes the migrations of each layer path from code coverage, under <source><exclude>: functional/*/database/migrations, technical/*/database/migrations.
  3. Adds a test suite named after each layer that has a tests/ folder and no suite yet.
  4. Adds each layer's source directory, such as functional/orders/src, to <source><include>.
  5. With --prune, removes the suites and include directories that are gone.
  6. Writes the file back when something changed.

Each change prints one line:

  Coverage exclusion functional/*/database/migrations ............... ADDED
  Coverage exclusion technical/*/database/migrations ................ ADDED
  Testsuite functional/orders → functional/orders/tests ............. ADDED
  Coverage source functional/orders/src ............................. ADDED
  Testsuite functional/users → functional/users/tests ............... ADDED
  Coverage source functional/users/src .............................. ADDED

  INFO  phpunit.xml updated.

Run it again after creating a layer: entries already present are left alone. When nothing changes, it prints phpunit.xml is already up to date..

Without --prune, the command only adds entries. osdd:remove removes the entries of the layer it removes; after deleting a layer by hand, run osdd:phpunit --prune.

Result

With the functional/users and functional/orders layers, phpunit.xml gets:

phpunit.xml
<testsuites>
    <testsuite name="Unit">
        <directory>tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
        <directory>tests/Feature</directory>
    </testsuite>
    <testsuite name="functional/orders">
        <directory>functional/orders/tests</directory>
    </testsuite>
    <testsuite name="functional/users">
        <directory>functional/users/tests</directory>
    </testsuite>
</testsuites>
<source>
    <include>
        <directory suffix=".php">functional/orders/src</directory>
        <directory suffix=".php">functional/users/src</directory>
    </include>
    <exclude>
        <directory suffix=".php">functional/*/database/migrations</directory>
        <directory suffix=".php">technical/*/database/migrations</directory>
    </exclude>
</source>

Layers are added in name order.

Running a layer's tests

# One layer
php artisan test --testsuite=functional/orders

# Every suite
php artisan test

See Tests and CI to write tests in a layer and run them in CI.

The osdd:phpunit command needs the dom PHP extension, a requirement of the package.