From 61420aab40a6ff2bdbcfb1e32656a2d5b04ee927 Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Mon, 22 Apr 2019 09:04:43 +0200 Subject: [PATCH] Add method to detect difference between current and configuration settings for sebastianbergmann/phpunit#3506 --- src/Runtime.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Runtime.php b/src/Runtime.php index 839b66d..b92f73b 100644 --- a/src/Runtime.php +++ b/src/Runtime.php @@ -218,4 +218,34 @@ public function hasPCOV(): bool { return $this->isPHP() && \extension_loaded('pcov') && \ini_get('pcov.enabled'); } + + /* + * Returns the current settings for the given set of php configuration values + */ + public function getCurrentSettings(array $values) : array { + $diff = []; + $files = []; + + if (($file = \php_ini_loaded_file())) { + $files[] = $file; + } + + if ($scanned = \php_ini_scanned_files()) { + $files = \array_merge($files, $scanned); + } + + foreach ($files as $ini) { + $config = \parse_ini_file($ini, true); + + foreach ($values as $value) { + $set = \ini_get($value); + + if (isset($config[$value]) && $set != $config[$value]) { + $diff[] = sprintf("%s=%s", $value, $set); + } + } + } + + return $diff; + } }