/**
  * Returns the executable path
  *
  * Allows returning a customized command for cygwin when the
  * command is just displayed, when using exec(), system() and
  * friends we stay with DIRECTORY_SEPARATOR as they use the
  * normal cmd.exe (in Windows).
  *
  * @param  bool $custombyterm  If the provided command should depend on the terminal where it runs
  * @return string
  */
 public static final function get_behat_command($custombyterm = false)
 {
     $separator = DIRECTORY_SEPARATOR;
     $exec = 'behat';
     // Cygwin uses linux-style directory separators.
     if ($custombyterm && testing_is_cygwin()) {
         $separator = '/';
         // MinGW can not execute .bat scripts.
         if (!testing_is_mingw()) {
             $exec = 'behat.bat';
         }
     }
     return 'vendor' . $separator . 'bin' . $separator . $exec;
 }
예제 #2
0
파일: lib.php 프로젝트: covex-nn/moodle
/**
 * Returns relative path against current working directory,
 * to be used for shell execution hints.
 * @param string $moodlepath starting with "/", ex: "/admin/tool/cli/init.php"
 * @return string path relative to current directory or absolute path
 */
function testing_cli_argument_path($moodlepath)
{
    global $CFG;
    if (isset($CFG->admin) and $CFG->admin !== 'admin') {
        $moodlepath = preg_replace('|^/admin/|', "/{$CFG->admin}/", $moodlepath);
    }
    $cwd = getcwd();
    if (substr($cwd, -1) !== DIRECTORY_SEPARATOR) {
        $cwd .= DIRECTORY_SEPARATOR;
    }
    $path = realpath($CFG->dirroot . $moodlepath);
    if (strpos($path, $cwd) === 0) {
        $path = substr($path, strlen($cwd));
    }
    if (testing_is_cygwin()) {
        $path = str_replace('\\', '/', $path);
    }
    return $path;
}
예제 #3
0
 /**
  * Return feature key for featurepath
  *
  * @param string $featurepath
  * @return array key and featurepath.
  */
 public function get_clean_feature_key_and_path($featurepath)
 {
     global $CFG;
     // Fix directory path.
     $featurepath = str_replace('\\', DIRECTORY_SEPARATOR, $featurepath);
     $featurepath = str_replace('/', DIRECTORY_SEPARATOR, $featurepath);
     if (testing_is_cygwin()) {
         $featurepath = str_replace('\\', '/', $featurepath);
     }
     $key = basename($featurepath, '.feature');
     // Get relative path.
     $featuredirname = str_replace($CFG->dirroot . DIRECTORY_SEPARATOR, '', $featurepath);
     // Get 5 levels of feature path to ensure we have a unique key.
     for ($i = 0; $i < 5; $i++) {
         if (($featuredirname = dirname($featuredirname)) && $featuredirname !== '.') {
             if ($basename = basename($featuredirname)) {
                 $key .= '_' . $basename;
             }
         }
     }
     return array($key, $featurepath);
 }
예제 #4
0
 /**
  * Test if clean features key and path is returned.
  * @dataProvider clean_features_path_list
  */
 public function test_get_clean_feature_key_and_path($featurepath, $key, $cleanfeaturepath)
 {
     global $CFG;
     // This is a hack so directory name is correctly detected in tests.
     //FIXME: MDL-55722 work out why this is necessary..
     $oldroot = $CFG->dirroot;
     $CFG->dirroot = 'C:';
     $behatconfigutil = $this->behatconfigutil;
     // Fix expected directory path for OS.
     $cleanfeaturepath = str_replace('\\', DIRECTORY_SEPARATOR, $cleanfeaturepath);
     $cleanfeaturepath = str_replace('/', DIRECTORY_SEPARATOR, $cleanfeaturepath);
     if (testing_is_cygwin()) {
         $featurepath = str_replace('\\', '/', $cleanfeaturepath);
     }
     list($retkey, $retcleanfeaturepath) = $behatconfigutil->get_clean_feature_key_and_path($featurepath);
     $this->assertEquals($key, $retkey);
     $this->assertEquals($cleanfeaturepath, $retcleanfeaturepath);
     //FIXME: MDL-55722 work out why this is necessary..
     $CFG->dirroot = $oldroot;
 }
 /**
  * Returns the behat config file path used by the behat cli command.
  *
  * @return string
  */
 public static function get_behat_cli_config_filepath()
 {
     global $CFG;
     $command = $CFG->behat_dataroot . DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'behat.yml';
     // Cygwin uses linux-style directory separators.
     if (testing_is_cygwin()) {
         $command = str_replace('\\', '/', $command);
     }
     return $command;
 }
 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
 {
     global $CFG;
     parent::printDefectTrace($defect);
     $failedTest = $defect->failedTest();
     $testName = get_class($failedTest);
     $exception = $defect->thrownException();
     $trace = $exception->getTrace();
     if (class_exists('ReflectionClass')) {
         $reflection = new ReflectionClass($testName);
         $file = $reflection->getFileName();
     } else {
         $file = false;
         $dirroot = realpath($CFG->dirroot) . DIRECTORY_SEPARATOR;
         $classpath = realpath("{$CFG->dirroot}/lib/phpunit/classes") . DIRECTORY_SEPARATOR;
         foreach ($trace as $item) {
             if (strpos($item['file'], $dirroot) === 0 and strpos($item['file'], $classpath) !== 0) {
                 if ($content = file_get_contents($item['file'])) {
                     if (preg_match('/class\\s+' . $testName . '\\s+extends/', $content)) {
                         $file = $item['file'];
                         break;
                     }
                 }
             }
         }
     }
     if ($file === false) {
         return;
     }
     $cwd = getcwd();
     if (strpos($file, $cwd) === 0) {
         $file = substr($file, strlen($cwd) + 1);
     }
     $executable = null;
     if (isset($_SERVER['argv'][0])) {
         if (preg_match('/phpunit(\\.bat|\\.cmd)?$/', $_SERVER['argv'][0])) {
             $executable = $_SERVER['argv'][0];
             for ($i = 1; $i < count($_SERVER['argv']); $i++) {
                 if (!isset($_SERVER['argv'][$i])) {
                     break;
                 }
                 if (in_array($_SERVER['argv'][$i], array('--colors', '--verbose', '-v', '--debug', '--strict'))) {
                     $executable .= ' ' . $_SERVER['argv'][$i];
                 }
             }
         }
     }
     if (!$executable) {
         $executable = 'phpunit';
         if (testing_is_cygwin()) {
             $file = str_replace('\\', '/', $file);
             if (!testing_is_mingw()) {
                 $executable = 'phpunit.bat';
             }
         }
     }
     $this->write("\nTo re-run:\n {$executable} {$testName} {$file}\n");
 }
예제 #7
0
 /**
  * Returns the behat config file path used by the behat cli command.
  *
  * @param int $runprocess Runprocess.
  * @return string
  */
 public static function get_behat_cli_config_filepath($runprocess = 0)
 {
     global $CFG;
     if ($runprocess) {
         if (isset($CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'])) {
             $command = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'];
         } else {
             $command = $CFG->behat_dataroot . $runprocess;
         }
     } else {
         $command = $CFG->behat_dataroot;
     }
     $command .= DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'behat.yml';
     // Cygwin uses linux-style directory separators.
     if (testing_is_cygwin()) {
         $command = str_replace('\\', '/', $command);
     }
     return $command;
 }
예제 #8
0
/**
 * Returns whether a mingw CLI is running.
 *
 * MinGW sets $_SERVER['TERM'] to cygwin, but it
 * can not run .bat files; this function may be useful
 * when we need to output proposed commands to users
 * using Windows CLI interfaces.
 *
 * @link http://sourceforge.net/p/mingw/bugs/1902
 * @return bool
 */
function testing_is_mingw()
{
    if (!testing_is_cygwin()) {
        return false;
    }
    if (!empty($_SERVER['MSYSTEM'])) {
        return true;
    }
    return false;
}
예제 #9
0
 /**
  * Returns the executable path
  *
  * Allows returning a customized command for cygwin when the
  * command is just displayed, when using exec(), system() and
  * friends we stay with DIRECTORY_SEPARATOR as they use the
  * normal cmd.exe (in Windows).
  *
  * @param  bool $custombyterm  If the provided command should depend on the terminal where it runs
  * @param bool $parallelrun If parallel run is installed.
  * @param bool $absolutepath return command with absolute path.
  * @return string
  */
 public static final function get_behat_command($custombyterm = false, $parallerun = false, $absolutepath = false)
 {
     $separator = DIRECTORY_SEPARATOR;
     $exec = 'behat';
     // Cygwin uses linux-style directory separators.
     if ($custombyterm && testing_is_cygwin()) {
         $separator = '/';
         // MinGW can not execute .bat scripts.
         if (!testing_is_mingw()) {
             $exec = 'behat.bat';
         }
     }
     // If relative path then prefix relative path.
     if ($absolutepath) {
         $pathprefix = testing_cli_argument_path('/') . $separator;
     } else {
         $pathprefix = '';
     }
     if (!$parallerun) {
         $command = $pathprefix . 'vendor' . $separator . 'bin' . $separator . $exec;
     } else {
         $command = 'php ' . $pathprefix . 'admin' . $separator . 'tool' . $separator . 'behat' . $separator . 'cli' . $separator . 'run.php';
     }
     return $command;
 }
예제 #10
0
파일: lib.php 프로젝트: janeklb/moodle
/**
 * Fix DIRECTORY_SEPARATOR for windows.
 *
 * In PHP on Windows, DIRECTORY_SEPARATOR is set to the backslash (\)
 * character. However, if you're running a Cygwin/Msys/Git shell
 * exec() calls will return paths using the forward slash (/) character.
 *
 * NOTE: Because PHP on Windows will accept either forward or backslashes,
 * paths should be built using ONLY forward slashes, regardless of
 * OS. MOODLE_DIRECTORY_SEPARATOR should only be used when parsing
 * paths returned by the shell.
 *
 * @param string $path
 * @return string.
 */
function testing_cli_fix_directory_separator($path)
{
    global $CFG;
    static $dirseparator = null;
    if (!$dirseparator) {
        // Default directory separator.
        $dirseparator = DIRECTORY_SEPARATOR;
        // On windows we need to find what directory separator is used.
        if ($CFG->ostype = 'WINDOWS') {
            if (!empty($_SERVER['argv'][0])) {
                if (false === strstr($_SERVER['argv'][0], '\\')) {
                    $dirseparator = '/';
                } else {
                    $dirseparator = '\\';
                }
            } else {
                if (testing_is_cygwin()) {
                    $dirseparator = '/';
                }
            }
        }
    }
    // Normalize \ and / to directory separator.
    $path = str_replace('\\', $dirseparator, $path);
    $path = str_replace('/', $dirseparator, $path);
    return $path;
}
예제 #11
0
 /**
  * Returns the executable path
  *
  * Allows returning a customized command for cygwin when the
  * command is just displayed, when using exec(), system() and
  * friends we stay with DIRECTORY_SEPARATOR as they use the
  * normal cmd.exe (in Windows).
  *
  * @param  bool $custombyterm  If the provided command should depend on the terminal where it runs
  * @param bool $parallelrun If parallel run is installed.
  * @return string
  */
 public static final function get_behat_command($custombyterm = false, $parallerun = false)
 {
     $separator = DIRECTORY_SEPARATOR;
     if (!$parallerun) {
         $exec = 'behat';
         // Cygwin uses linux-style directory separators.
         if ($custombyterm && testing_is_cygwin()) {
             $separator = '/';
             // MinGW can not execute .bat scripts.
             if (!testing_is_mingw()) {
                 $exec = 'behat.bat';
             }
         }
         $command = 'vendor' . $separator . 'bin' . $separator . $exec;
     } else {
         $command = 'php admin' . $separator . 'tool' . $separator . 'behat' . $separator . 'cli' . $separator . 'run.php';
     }
     return $command;
 }