File: EnvHelper.php

package info (click to toggle)
php-composer-xdebug-handler 1.4.5-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 264 kB
  • sloc: php: 1,412; makefile: 16
file content (89 lines) | stat: -rw-r--r-- 2,532 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

/*
 * This file is part of composer/xdebug-handler.
 *
 * (c) Composer <https://github.com/composer>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Composer\XdebugHandler\Helpers;

/**
 * This helper class provides a central data provider that uses IniHelper to
 * mock environment settings.
 */
class EnvHelper
{
    /**
     * Mock the environment
     *
     * @param callable $iniFunc IniHelper method to use
     * @param mixed $scanDir Initial value for PHP_INI_SCAN_DIR
     * @param mixed $phprc Initial value for PHPRC
     *
     * @return IniHelper
     */
    public static function setInis($iniFunc, $scanDir, $phprc)
    {
        $ini = new IniHelper(array($scanDir, $phprc));
        call_user_func(array($ini, $iniFunc));

        return $ini;
    }

    public static function dataProvider()
    {
        $ini = new IniHelper();
        $loaded = $ini->getLoadedIni();
        $scanDir = $ini->getScanDir();

        // $iniFunc, $scanDir, $phprc
        return array(
            'loaded false myini' => array('setLoadedIni', false, '/my.ini'),
            'loaded empty false' => array('setLoadedIni', '', false),
            'scanned false file' => array('setScannedInis', false, $loaded),
            'scanned dir false' => array('setScannedInis', $scanDir, false),
        );
    }

    /**
     * Checks if php_ini_scanned_files is supported.
     *
     * The process will not be restarted if there are scanned inis but PHP
     * is unable to list them. See https://bugs.php.net/73124
     *
     * This method tests the behaviour of XdebugHandler::checkScanDirConfig by
     * checking each requirement separately.
     *
     * @param mixed $scanDir Initial value for PHP_INI_SCAN_DIR
     *
     * @return null|string The skip message
     */
    public static function shouldSkipTest($scanDir)
    {
        // Not relevant if no scan dir or it has been overriden
        if ($scanDir === false || $scanDir === '') {
            return;
        }

        // Not relevant if --with-config-file-scan-dir was used
        if (PHP_CONFIG_FILE_SCAN_DIR !== '') {
            return;
        }

        // Bug fixed in 7.1.13
        if (PHP_VERSION_ID >= 70113 && PHP_VERSION_ID < 70200) {
            return;
        }

        // Bug fixed in 7.2.1
        if (PHP_VERSION_ID >= 70201) {
            return;
        }

        return 'php_ini_scanned_files not functional on '.PHP_VERSION;
    }
}