Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlobalState::getIniSettingsAsString() generates code that triggers warnings #5270

Closed
sebastianbergmann opened this issue Mar 3, 2023 · 0 comments
Assignees
Labels
feature/process-isolation Issues related to running tests in separate PHP processes feature/test-runner CLI test runner type/bug Something is broken version/9 Something affects PHPUnit 9 version/10 Something affects PHPUnit 10

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Mar 3, 2023

We have this code (PHPUnit 9.6, PHPUnit 10.0)

$result = '';

foreach (ini_get_all(null, false) as $key => $value) {
    $result .= sprintf(
        '@ini_set(%s, %s);' . "\n",
        self::exportVariable($key),
        self::exportVariable((string) $value)
    );
}

to generate code that when run in a separate process reproduces the PHP configuration in the parent process.

This can, for instance, lead to

@ini_set('mbstring.internal_encoding', '');

being run, which triggers a warning because mbstring.internal_encoding is deprecated.

We should avoid generating ini_set() calls for values that are not configured in the parent process.

It is unclear whether $value === null can be safely used to detect whether a value is configured or not.

As the error suppression operator @ is used, this should only ever be a problem when a custom error handler does not honor the fact that such a warning should be ignored.

@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/test-runner CLI test runner feature/process-isolation Issues related to running tests in separate PHP processes version/9 Something affects PHPUnit 9 version/10 Something affects PHPUnit 10 labels Mar 3, 2023
@sebastianbergmann sebastianbergmann changed the title GlobalState::getIniSettingsAsString() generates code that triggers warnings GlobalState::getIniSettingsAsString() generates code that triggers warnings Mar 6, 2023
@sebastianbergmann sebastianbergmann self-assigned this Mar 23, 2023
sebastianbergmann added a commit that referenced this issue Mar 23, 2023
sebastianbergmann added a commit that referenced this issue Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/process-isolation Issues related to running tests in separate PHP processes feature/test-runner CLI test runner type/bug Something is broken version/9 Something affects PHPUnit 9 version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

1 participant