{"record":{"id":"83f97574234ebd43","repo":"sebastianbergmann/phpunit","slug":"the-tests-aggregated-by-this-testsuite-were-alread","errorCode":null,"errorMessage":"The tests aggregated by this TestSuite were already run","messagePattern":"The tests aggregated by this TestSuite were already run","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Framework/TestSuite.php","lineNumber":398,"sourceCode":"\n            $tests[] = $test;\n        }\n\n        return $tests;\n    }\n\n    /**\n     * @throws Event\\RuntimeException\n     * @throws Exception\n     * @throws InvalidArgumentException\n     * @throws NoPreviousThrowableException\n     * @throws UnintentionallyCoveredCodeException\n     */\n    public function run(): void\n    {\n        if ($this->wasRun) {\n            // @codeCoverageIgnoreStart\n            throw new Exception('The tests aggregated by this TestSuite were already run');\n            // @codeCoverageIgnoreEnd\n        }\n\n        $this->wasRun = true;\n\n        if ($this->isEmpty()) {\n            return;\n        }\n\n        $emitter                       = Event\\Facade::emitter();\n        $testSuiteValueObjectForEvents = Event\\TestSuite\\TestSuiteBuilder::from($this);\n\n        $emitter->testSuiteStarted($testSuiteValueObjectForEvents);\n\n        if (!$this->invokeMethodsBeforeFirstTest($emitter, $testSuiteValueObjectForEvents)) {\n            return;\n        }\n","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Framework/TestSuite.php#L380-L416","documentation":"Thrown by TestSuite::run() when the same TestSuite instance is run a second time; the wasRun flag is set on the first run and never reset. The guard exists because TestSuite mutates state while running (counts, iterators, attached listeners), so reusing an instance would corrupt results.","triggerScenarios":"Calling $suite->run() twice on the same object, e.g. running a cached/shared TestSuite once manually and again through a TestRunner, or re-running inside a custom orchestrator loop without rebuilding the suite.","commonSituations":"Custom test runners or retry logic that reuses a suite built once; embedding PHPUnit in another tool that runs suites on multiple phases; caching suites in long-running worker processes.","solutions":["Build a fresh TestSuite (re-run the suite builder/loader) for every run instead of reusing the instance","Remove the manual $suite->run() call if a TestRunner already executes the suite","Restructure retry logic to rebuild the suite between attempts"],"exampleFix":"// before\n$suite = $loader->load('tests');\n$suite->run();\n$suite->run(); // Exception: already run\n\n// after\nforeach (range(1, 2) as $i) {\n    $loader->load('tests')->run(); // fresh suite each time\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat TestSuite objects as single-use: rebuild via the loader for every run","Never cache suites across retry attempts or runner phases","Let a single TestRunner own the run() call; remove manual invocations"],"tags":["phpunit","test-suite","state-reuse","runner"],"backgroundTag":"double-execution-guard","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}