sebastianbergmann/phpunit · error · PHPUnit\TextUI\XmlConfiguration\Exception

Default test suite is not configured

Error message

Default test suite is not configured

What it means

The XML configuration object's defaultTestSuite() getter throws PHPUnit\TextUI\XmlConfiguration\Exception unless the configuration actually declares a default test suite (the defaultTestSuite attribute on <testsuites>). It pairs with the guard hasDefaultTestSuite(); calling the getter unguarded on a config without the attribute is a usage error, not an environment problem.

Source

Thrown at src/TextUI/Configuration/Xml/PHPUnit.php:751

    }

    /**
     * @phpstan-assert-if-true !null $this->defaultTestSuite
     */
    public function hasDefaultTestSuite(): bool
    {
        return $this->defaultTestSuite !== null;
    }

    /**
     * @throws Exception
     *
     * @return non-empty-string
     */
    public function defaultTestSuite(): string
    {
        if (!$this->hasDefaultTestSuite()) {
            throw new Exception('Default test suite is not configured');
        }

        return $this->defaultTestSuite;
    }

    public function executionOrder(): int
    {
        return $this->executionOrder;
    }

    public function resolveDependencies(): bool
    {
        return $this->resolveDependencies;
    }

    public function defectsFirst(): bool
    {
        return $this->defectsFirst;

View on GitHub (pinned to f123cdb2a2)

Solutions

  1. Guard the call: `if ($config->hasDefaultTestSuite()) { $suite = $config->defaultTestSuite(); }`
  2. Declare a default in phpunit.xml: `<testsuites defaultTestSuite="unit">`
  3. Or select explicitly via CLI: `vendor/bin/phpunit --testsuite unit`

Example fix

// before
$suite = $configuration->defaultTestSuite(); // throws when unconfigured

// after
$suite = $configuration->hasDefaultTestSuite()
    ? $configuration->defaultTestSuite()
    : 'default';

<!-- or make it explicit in phpunit.xml -->
<testsuites defaultTestSuite="unit">
Defensive patterns

Strategy: type-guard

Type guard

if ($xmlConfiguration->hasDefaultTestSuite()) {
    $default = $xmlConfiguration->defaultTestSuite(); // now guaranteed to return non-empty-string
} else {
    $default = null; // explicit fallback: --testsuite, 'default', or abort
}

Try / catch

try {
    $suite = $xmlConfiguration->defaultTestSuite();
} catch (\PHPUnit\TextUI\XmlConfiguration\Exception $e) {
    // 'Default test suite is not configured' — fall back to running all suites
    $suite = null;
}

Prevention

When it happens

Trigger: Calling `$xmlConfiguration->defaultTestSuite()` in a custom runner, extension, or test of the configuration when phpunit.xml has <testsuites> without defaultTestSuite="..."; code migrated from a project whose config always had the attribute to one that does not.

Common situations: Custom test-runners or tooling that assume a default suite is configured; freshly generated phpunit.xml files (which omit the attribute) consumed by older tooling.

Related errors


AI-assisted analysis of sebastianbergmann/phpunit@f123cdb2a2 (2026-08-23). Data as JSON: /api/errors/7f6b26429a9113cf. Report an issue: GitHub.