ParametersHolder.php 1.8 KB
Newer Older
Ketan's avatar
Ketan committed
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
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\TestFramework\Deploy;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Shell;
use Magento\Setup\Console\Command\InstallCommand;

/**
 * The purpose of this class is enable/disable module and upgrade commands execution.
 */
class ParametersHolder
{
    /**
     * Initialize params.
     *
     * @var array
     */
    private $initParams;

    /**
     * Return application initialization parameters.
     *
     * @return array
     */
    public function getInitParams()
    {
        if (!isset($this->initParams)) {
            $customDirs = $this->getCustomDirs();
            $initParams = [
                \Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => $customDirs,
            ];
            $this->initParams = ['magento-init-params' => urldecode(http_build_query($initParams))];
        }
        return $this->initParams;
    }

    /**
     * Include data from config file and convert it to db format:
     * -db-name
     * -db-user-name
     * -db-password
     * -db-host
     *
     * @param  string $resource can be default, checkout, sales
     * @return array
     */
    public function getDbData($resource)
    {
        $dbData = include TESTS_INSTALLATION_DB_CONFIG_FILE;
        return $dbData[$resource];
    }

    /**
     * Get customized directory paths.
     *
     * @return array
     */
    private function getCustomDirs()
    {
        $installDir = TESTS_TEMP_DIR;
        $path = DirectoryList::PATH;
        $var = "{$installDir}/var";
        $customDirs = [
            DirectoryList::CONFIG => [$path => "{$installDir}/etc"],
            DirectoryList::VAR_DIR => [$path => $var],
        ];
        return $customDirs;
    }
}