Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to install Fastest in global mode #119

Merged
merged 1 commit into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Our old codebase run in 30 minutes, now in 7 minutes with 4 Processors.
4. As input you could use a `phpunit.xml.dist` file or use pipe (see below).
5. Includes a Behat extension to easily pipe scenarios into fastest.
6. Increase Verbosity with -v option.
7. Works with a installation in project or global mode

## How

Expand Down
41 changes: 38 additions & 3 deletions src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ProcessFactory
private $commandToExecuteTemplate;
private $maxParallelProcessesToExecute;

private static $cacheBinCmd;

public function __construct($maxParallelProcessesToExecute, $commandToExecuteTemplate = null, EnvCommandCreator $envCommandCreator = null)
{
if (null === $envCommandCreator) {
Expand Down Expand Up @@ -67,8 +69,41 @@ private function createProcess($executeCommand, $arrayEnv)

public static function getDefaultCommandToExecute()
{
return ('\\' === DIRECTORY_SEPARATOR)
? 'bin\phpunit {}'
: 'bin/phpunit {}';
if (null !== self::$cacheBinCmd) {
return self::$cacheBinCmd;
}

return self::$cacheBinCmd = self::isWindows() ? self::getWindowsBinCmd() : self::getUnixBinCmd();
}

private static function isWindows()
{
return '\\' === DIRECTORY_SEPARATOR;
}

private static function getWindowsBinCmd()
{
if (file_exists(getcwd().'/bin/phpunit')) {
$cmd = 'bin\phpunit {}';
} elseif (file_exists(getenv('APPDATA').'\Composer\vendor\bin\phpunit')) {
$cmd = '%APPDATA%\Composer\vendor\bin\phpunit {}';
} else {
$cmd = 'phpunit {}';
}

return $cmd;
}

private static function getUnixBinCmd()
{
if (file_exists(getcwd().'/bin/phpunit')) {
$cmd = 'bin/phpunit {}';
} elseif (file_exists(getenv('HOME').'/.composer/vendor/bin/phpunit')) {
$cmd = '~/.composer/vendor/bin/phpunit {}';
} else {
$cmd = 'phpunit {}';
}

return $cmd;
}
}