Add project root to path.

@param $fileName
@param $suite

@return string
774236
public function addProjectRootPath($fileName, $suite)
    {
        if (starts_with($fileName, DIRECTORY_SEPARATOR) || empty($suite)) {
            return $fileName;
        }

        return $suite->project->path.DIRECTORY_SEPARATOR.$fileName;
    }
1101058
private function extractFooter(Suite $suite, Definition $definition)
    {
        $lines = array();
        $lines[] = strtr(
            '{space}<def_dimmed>|</def_dimmed> at `{path}`', array(
                '{space}' => str_pad('', mb_strlen($suite->getName(), 'utf8') + 1),
                '{path}'  => $definition->getPath()
            )
        );

        if ($this->isVerbose()) {
            $lines[] = strtr(
                '{space}<def_dimmed>|</def_dimmed> on `{filepath}[{start}:{end}]`', array(
                    '{space}' => str_pad('', mb_strlen($suite->getName(), 'utf8') + 1),
                    '{filepath}' => $definition->getReflection()->getFileName(),
                    '{start}' => $definition->getReflection()->getStartLine(),
                    '{end}' => $definition->getReflection()->getEndLine()
                )
            );
        }

        return $lines;
    }
423162
public function replaceProjectNamespace(string $replacement, string $filePath): self
    {
        $this->findReplace(
            AbstractGenerator::FIND_PROJECT_NAMESPACE,
            $this->namespaceHelper->tidy($replacement),
            $filePath
        );

        return $this;
    }
873260
public function editFile($fileName, $suite_id, $line = null)
    {
        $this->executor->exec(
            $command = $this->dataRepository->makeEditFileCommand($fileName, $line, $suite_id)
        );

        return $this->success();
    }
1100955
public function getSuiteByName(string $suiteName)
    {
        $nodes = $this->xml->xpath(sprintf('//testsuite[@name="%s"]', $suiteName));

        $suites = [];
        $excludedPaths = [];
        foreach ($nodes as $node) {
            foreach ($this->availableNodes as $nodeName) {
                foreach ($node->{$nodeName} as $nodeContent) {
                    switch ($nodeName) {
                        case 'exclude':
                            foreach ($this->getSuitePaths((string) $nodeContent) as $excludedPath) {
                                $excludedPaths[$excludedPath] = $excludedPath;
                            }
                            break;
                        case 'testsuite':
                            $suites = array_merge_recursive($suites, $this->getSuiteByName((string) $nodeContent));
                            break;
                        case 'directory':
                            // Replicate behaviour of PHPUnit
                            // if a directory is included and excluded at the same time, then it is considered included
                            foreach ($this->getSuitePaths((string) $nodeContent) as $dir) {
                                if (\array_key_exists($dir, $excludedPaths)) {
                                    unset($excludedPaths[$dir]);
                                }
                            }
                            // no break on purpose
                        default:
                            foreach ($this->getSuitePaths((string) $nodeContent) as $path) {
                                $suites[(string) $node['name']][] = new SuitePath(
                                    $path,
                                    $excludedPaths,
                                    (string) $nodeContent->attributes()->suffix
                                );
                            }
                            break;
                    }
                }
            }
        }

        return $suites;
    }
792850
public function setProjectRoot($projectRoot)
    {
        $projectRootRegex = $projectRoot ? '/^'.preg_quote($projectRoot, '/').'[\\/]?/i' : null;
        $this->setProjectRootRegex($projectRootRegex);
    }
395420
private function addFile($pathToAdd, $fileName = null)
    {
        if (!$fileName) {
            $info = pathinfo($pathToAdd);
            $fileName = isset($info['extension']) ?
                $info['filename'].'.'.$info['extension'] :
                $info['filename'];
        }

        $this->repository->addFile($pathToAdd, $this->getInternalPath().$fileName);
    }
436255
public static function suite($name, $fn)
    {
        $suite = new Suite(new InvocationContext(), $fn, $name);
        $suite->build();
        return $suite;
    }
238579
protected function getSuiteRoot(array $suites): \DOMElement
    {
        $testsuites = $this->document->createElement('testsuites');
        $this->document->appendChild($testsuites);
        if (\count($suites) === 1) {
            return $testsuites;
        }
        $rootSuite = $this->document->createElement('testsuite');
        $attrs = $this->getSuiteRootAttributes($suites);
        foreach ($attrs as $attr => $value) {
            $rootSuite->setAttribute($attr, (string) $value);
        }
        $testsuites->appendChild($rootSuite);

        return $rootSuite;
    }
670612
public function addSuite($description, callable $fn, $pending = null, $focused = false)
    {
        $suite = $this->createSuite($description, $fn, $pending, $focused);

        $this->getCurrentSuite()->addTest($suite);
        array_unshift($this->suites, $suite);
        $suite->define();
        array_shift($this->suites);

        return $suite;
    }
1349363
protected function createProject($projectName = 'myProj') {
        $this->showHeader();
        Console::stdout("Creating $projectName \n");

        Utils::getInstance()->createDirectory("./apps/" . $projectName, ['src', 'routes', 'config', 'public', 'doc', 'templates']);
        echo "\n";
        foreach (self::FILES_APP as $pathname => $contents) {
            Utils::getInstance()->createFile("./apps/" . $projectName . "/" . $pathname, $contents);
        }
        echo "\n Don't forget to run 'composer update' in your root project folder (apps/" . $projectName . ") before start to use! \n";
    }
1163816
protected static function trimRootPath( $fileName )
	{
		$rootPath	= realpath( getEnv( 'DOCUMENT_ROOT' ) );
		if( strlen( trim( $fileName ) ) && $rootPath )
			$fileName	= preg_replace( "/^".preg_quote( $rootPath.'/', '/' )."/", "", $fileName );
		return $fileName;
	}
1091968
protected function offerBranchChoice(Project $project, $projectRoot)
    {
        $environments = $this->api()->getEnvironments($project);
        $currentEnvironment = $this->getCurrentEnvironment($project);
        if ($currentEnvironment) {
            $this->stdErr->writeln("The current environment is " . $this->api()->getEnvironmentLabel($currentEnvironment) . ".");
            $this->stdErr->writeln('');
        }
        $environmentList = [];
        foreach ($environments as $id => $environment) {
            // The $id will be an integer for numeric environment names (as
            // it was assigned to an array key), so it's cast back to a
            // string for this comparison.
            if ($currentEnvironment && (string) $id === $currentEnvironment->id) {
                continue;
            }
            $environmentList[$id] = $this->api()->getEnvironmentLabel($environment, false);
        }
        /** @var \Platformsh\Cli\Local\LocalProject $localProject */
        $localProject = $this->getService('local.project');
        $projectConfig = $localProject->getProjectConfig($projectRoot);
        if (!empty($projectConfig['mapping'])) {
            foreach ($projectConfig['mapping'] as $branch => $id) {
                if (isset($environmentList[$id]) && isset($environmentList[$branch])) {
                    unset($environmentList[$id]);
                    $environmentList[$branch] = sprintf('%s (%s)', $environments[$id]->title, $branch);
                }
            }
        }
        if (!count($environmentList)) {
            $this->stdErr->writeln(sprintf(
                'Use <info>%s branch</info> to create an environment.',
                $this->config()->get('application.executable')
            ));

            return false;
        }

        /** @var \Platformsh\Cli\Service\QuestionHelper $helper */
        $helper = $this->getService('question_helper');

        // If there's more than one choice, present the user with a list.
        if (count($environmentList) > 1) {
            $chooseEnvironmentText = "Enter a number to check out another environment:";

            // The environment ID will be an integer if it was numeric
            // (because PHP does that with array keys), so it's cast back to
            // a string here.
            return (string) $helper->choose($environmentList, $chooseEnvironmentText);
        }

        // If there's only one choice, QuestionHelper::choose() does not
        // interact. But we still need interactive confirmation at this point.
        $environmentId = key($environmentList);
        if ($environmentId !== false) {
            $label = $this->api()->getEnvironmentLabel($environments[$environmentId]);
            if ($helper->confirm(sprintf('Check out environment %s?', $label))) {
                return $environmentId;
            }
        }

        return false;
    }
1255439
protected function runIncludedSuites($suites, $parent_dir)
    {
        foreach ($suites as $relativePath) {
            $current_dir = rtrim($parent_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $relativePath;
            $config = Configuration::config($current_dir);
            $suites = Configuration::suites();

            $namespace = $this->currentNamespace();
            $this->output->writeln(
                "\n<fg=white;bg=magenta>\n[$namespace]: tests from $current_dir\n</fg=white;bg=magenta>"
            );

            $this->executed += $this->runSuites($suites, $this->options['skip']);
            if (!empty($config['include'])) {
                $this->runIncludedSuites($config['include'], $current_dir);
            }
        }
    }
719468
protected static function trimRootPath( $fileName )
	{
		$rootPath	= isset( $_SERVER['DOCUMENT_ROOT'] ) ? $_SERVER['DOCUMENT_ROOT'] : "";
		if( !$rootPath || !$fileName )
			return;
		$fileName	= str_replace( '\\', "/", $fileName );
		$cut		= substr( $fileName, 0, strlen( $rootPath ) );
		if( $cut == $rootPath )
			$fileName	= substr( $fileName, strlen( $rootPath ) );
		return $fileName;
	}
84341
public function addFile($filename)
    {
        if (file_exists($this->path . $filename) && preg_match('/\.' . $this->type . '$/i', $filename)) {
            $this->files[] = $filename;
        } elseif (!empty($this->domains)) {
            foreach ($this->domains as $domain => $paths) {
                $domainFilename = str_replace($domain, $paths["public"], $filename);
                if (file_exists($domainFilename) && preg_match('/\.' . $this->type . '$/i', $domainFilename)) {
                    $this->files[] = $domainFilename;
                }
            }
        }
        return $this;
    }
1148772
protected function createFullFilePath($fileName)
    {
        $tempPath = $this->documentConfig->getTempPath();

        if (!is_dir($tempPath)) {
            mkdir($tempPath, 777, true);
        }

        return sprintf('%s/%s', $tempPath, $fileName);
    }