markTestSkipped('CactiSecureHeaders is present in this runtime; the delegation path is covered by the isolated-process test.'); } expect(plugin_monitor_csp_nonce())->toBe(''); }); test('csp nonce helper is declared to return a string', function () { $ref = new ReflectionFunction('plugin_monitor_csp_nonce'); expect((string) $ref->getReturnType())->toBe('string'); }); test('csp nonce delegates to CactiSecureHeaders when the class is available', function () { $wrapper = realpath(__DIR__ . '/../../setup.php'); expect($wrapper)->not->toBeFalse(); // Run in a clean child process so the double never leaks into the rest // of the suite and the delegation branch is genuinely invoked. $script = <<<'CHILD' >>"; CHILD; $tmp = tempnam(sys_get_temp_dir(), 'csp_'); expect($tmp)->not->toBeFalse(); try { file_put_contents($tmp, $script); $command = escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($tmp) . ' ' . escapeshellarg($wrapper); $output = shell_exec($command); expect($output)->not->toBeNull(); preg_match('/<<<(.*)>>>/s', (string) $output, $matches); expect($matches)->toHaveKey(1); expect($matches[1])->toBe(' nonce="pest-controlled-double"'); } finally { @unlink($tmp); } });