N98\Magento\Command\TestCase::getTestMagentoRootFromEnvironment PHP Method

getTestMagentoRootFromEnvironment() public static method

public static getTestMagentoRootFromEnvironment ( string $varname, string $basename ) : string | null
$varname string name of the environment variable containing the test-root
$basename string name of the stopfile containing the test-root
return string | null
    public static function getTestMagentoRootFromEnvironment($varname, $basename)
    {
        $root = getenv($varname);
        if (empty($root) && strlen($basename)) {
            $stopfile = getcwd() . '/' . $basename;
            if (is_readable($stopfile) && ($buffer = rtrim(file_get_contents($stopfile)))) {
                $root = $buffer;
            }
        }
        if (empty($root)) {
            return;
        }
        # directory test
        if (!is_dir($root)) {
            throw new RuntimeException(sprintf("%s path '%s' is not a directory", $varname, $root));
        }
        # resolve root to realpath to be independent to current working directory
        $rootRealpath = realpath($root);
        if (false === $rootRealpath) {
            throw new RuntimeException(sprintf("Failed to resolve %s path '%s' with realpath()", $varname, $root));
        }
        return $rootRealpath;
    }

Usage Example

コード例 #1
0
ファイル: bootstrap.php プロジェクト: netz98/n98-magerun
<?php

use N98\Magento\Command\TestCase;
$base = TestCase::getTestMagentoRootFromEnvironment('N98_MAGERUN_TEST_MAGENTO_ROOT', '.n98-magerun');
if (false === $base) {
    unset($base);
    return;
}
@session_start();
$loader = (require __DIR__ . '/../vendor/autoload.php');
/* @var $loader \Composer\Autoload\ClassLoader */
$loader->setUseIncludePath(true);
$paths = array($base . '/app/code/local', $base . '/app/code/community', $base . '/app/code/core', $base . '/lib');
set_include_path(implode(PATH_SEPARATOR, $paths) . PATH_SEPARATOR . get_include_path());
unset($paths, $base);