{"record":{"id":"7f6b26429a9113cf","repo":"sebastianbergmann/phpunit","slug":"default-test-suite-is-not-configured","errorCode":null,"errorMessage":"Default test suite is not configured","messagePattern":"Default test suite is not configured","errorType":"exception","errorClass":"PHPUnit\\TextUI\\XmlConfiguration\\Exception","httpStatus":null,"severity":"error","filePath":"src/TextUI/Configuration/Xml/PHPUnit.php","lineNumber":751,"sourceCode":"    }\n\n    /**\n     * @phpstan-assert-if-true !null $this->defaultTestSuite\n     */\n    public function hasDefaultTestSuite(): bool\n    {\n        return $this->defaultTestSuite !== null;\n    }\n\n    /**\n     * @throws Exception\n     *\n     * @return non-empty-string\n     */\n    public function defaultTestSuite(): string\n    {\n        if (!$this->hasDefaultTestSuite()) {\n            throw new Exception('Default test suite is not configured');\n        }\n\n        return $this->defaultTestSuite;\n    }\n\n    public function executionOrder(): int\n    {\n        return $this->executionOrder;\n    }\n\n    public function resolveDependencies(): bool\n    {\n        return $this->resolveDependencies;\n    }\n\n    public function defectsFirst(): bool\n    {\n        return $this->defectsFirst;","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/TextUI/Configuration/Xml/PHPUnit.php#L733-L769","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Guard the call: `if ($config->hasDefaultTestSuite()) { $suite = $config->defaultTestSuite(); }`","Declare a default in phpunit.xml: `<testsuites defaultTestSuite=\"unit\">`","Or select explicitly via CLI: `vendor/bin/phpunit --testsuite unit`"],"exampleFix":"// before\n$suite = $configuration->defaultTestSuite(); // throws when unconfigured\n\n// after\n$suite = $configuration->hasDefaultTestSuite()\n    ? $configuration->defaultTestSuite()\n    : 'default';\n\n<!-- or make it explicit in phpunit.xml -->\n<testsuites defaultTestSuite=\"unit\">","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"if ($xmlConfiguration->hasDefaultTestSuite()) {\n    $default = $xmlConfiguration->defaultTestSuite(); // now guaranteed to return non-empty-string\n} else {\n    $default = null; // explicit fallback: --testsuite, 'default', or abort\n}","tryCatchPattern":"try {\n    $suite = $xmlConfiguration->defaultTestSuite();\n} catch (\\PHPUnit\\TextUI\\XmlConfiguration\\Exception $e) {\n    // 'Default test suite is not configured' — fall back to running all suites\n    $suite = null;\n}","preventionTips":["Always pair defaultTestSuite() with hasDefaultTestSuite(); the getter has no default","Declare `<testsuites defaultTestSuite=\"unit\">` if your tooling relies on a default suite","When writing tests for configuration loading, cover both the configured and unconfigured cases"],"tags":["phpunit","xml","test-suite","configuration","api-misuse"],"backgroundTag":"missing-configuration-value","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}