File: EnvHelper.php

package info (click to toggle)
php-composer-xdebug-handler 3.0.5-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: php: 2,501; makefile: 18
file content (58 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download | duplicates (2)
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
<?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.
 */

declare(strict_types=1);

namespace Composer\XdebugHandler\Tests\Helpers;

use Composer\XdebugHandler\Tests\Helpers\BaseTestCase;

/**
 * This helper class provides a central data provider that uses IniHelper to
 * mock environment settings.
 *
 * @phpstan-type envTestData array<string, array{0: string, 1: false|string, 2: false|string}>
 */
class EnvHelper
{
    /**
     * Mock the environment
     *
     * @param string $iniFunc IniHelper method to use
     * @param false|string $scanDir Initial value for PHP_INI_SCAN_DIR
     * @param false|string $phprc Initial value for PHPRC
     */
    public static function setInis(string $iniFunc, $scanDir, $phprc): IniHelper
    {
        $ini = new IniHelper([$scanDir, $phprc]);
        BaseTestCase::safeCall($ini, $iniFunc);

        return $ini;
    }

    /**
     * @phpstan-return envTestData
     */
    public static function dataProvider(): array
    {
        $ini = new IniHelper();
        $loaded = $ini->getLoadedIni();
        $scanDir = $ini->getScanDir();

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