{"record":{"id":"c8b826e00f313086","repo":"sebastianbergmann/phpunit","slug":"getrusage-returned-non-integer-values-for-s-a","errorCode":null,"errorMessage":"getrusage() returned non-integer values for \"%s\" and/or \"%s\".","messagePattern":"getrusage\\(\\) returned non-integer values for \"(.+?)\" and/or \"(.+?)\"\\.","errorType":"exception","errorClass":"PHPUnit\\Event\\RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Event/Value/Telemetry/SystemCpuTimeMeter.php","lineNumber":73,"sourceCode":"\n        if (!isset($usage[$secondsKey]) || !isset($usage[$microsecondsKey])) {\n            // @codeCoverageIgnoreStart\n            throw new RuntimeException(\n                sprintf(\n                    'getrusage() did not return the expected keys \"%s\" and \"%s\".',\n                    $secondsKey,\n                    $microsecondsKey,\n                ),\n            );\n            // @codeCoverageIgnoreEnd\n        }\n\n        $seconds      = $usage[$secondsKey];\n        $microseconds = $usage[$microsecondsKey];\n\n        if (!is_int($seconds) || !is_int($microseconds)) {\n            // @codeCoverageIgnoreStart\n            throw new RuntimeException(\n                sprintf(\n                    'getrusage() returned non-integer values for \"%s\" and/or \"%s\".',\n                    $secondsKey,\n                    $microsecondsKey,\n                ),\n            );\n            // @codeCoverageIgnoreEnd\n        }\n\n        return CpuTime::fromSecondsAndNanoseconds($seconds, $microseconds * 1000);\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":86,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Event/Value/Telemetry/SystemCpuTimeMeter.php#L55-L86","documentation":"SystemCpuTimeMeter validates that the values under the rusage keys are PHP ints before handing them to CpuTime::fromSecondsAndNanoseconds(); non-integer values (strings, floats) throw this RuntimeException. Stock PHP always returns ints, so like the sibling getrusage guards this is @codeCoverageIgnore'd and points at an intercepted or patched getrusage() returning coerced values.","triggerScenarios":"A mocked getrusage() that returns string numbers ('42') or floats; serialization round-trips (e.g. a result cache) that turned ints into strings; PHP builds or extensions that alter the array's value types.","commonSituations":"Test doubles for getrusage() written without int casts; telemetry data crossing process boundaries through JSON; debugging tooling that rewrites native return values.","solutions":["Cast the stub's values to int: ['ru_utime.tv_sec' => (int) $sec, ...].","Validate the environment with php -r '$u = getrusage(); var_dump(is_int($u[\"ru_utime.tv_sec\"]));'.","Catch PHPUnit\\Event\\RuntimeException around userCpuTime()/systemCpuTime() and degrade to time-only telemetry in constrained environments."],"exampleFix":"// before\nfunction getrusage(): array { return ['ru_utime.tv_sec' => '12', 'ru_utime.tv_usec' => '345']; } // strings\n\n// after\nfunction getrusage(): array { return ['ru_utime.tv_sec' => 12, 'ru_utime.tv_usec' => 345]; } // ints","handlingStrategy":"fallback","validationCode":"$usage = getrusage();\nif ($usage === false || !is_int($usage['ru_utime.tv_sec'] ?? null) || !is_int($usage['ru_utime.tv_usec'] ?? null)) {\n    // non-integer rusage values: skip CPU-time telemetry in this environment\n}","typeGuard":null,"tryCatchPattern":"try {\n    $cpu = $meter->userCpuTime();\n} catch (PHPUnit\\Event\\RuntimeException $e) {\n    // Values not trustworthy as ints: fall back to time-only telemetry\n}","preventionTips":["Cast stubbed rusage values to int in test doubles.","Avoid round-tripping rusage arrays through JSON/string serialization without recasting types.","Keep CPU-time reads behind one guarded helper in custom runners so the fallback lives in a single place."],"tags":["phpunit","telemetry","getrusage","type-mismatch","environment","php"],"backgroundTag":"system-call-failed","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}