<?php
namespace PhpBrew\Command;
use CLIFramework\Command;
use PhpBrew\Config;
use Exception;

/**
 * @codeCoverageIgnore
 */
class UseCommand extends Command
{

    public function arguments($args) {
        $args->add('php version')
            ->validValues(function(){
                return Config::findMatchedBuilds();
            })
            ;
    }

    public function brief()
    {
        return 'Use php, switch version temporarily';
    }

    public function execute($buildName) {
        if ($buildName) {
            // This exception is used for tracing tests
            throw new Exception("build name is required.");
        }
        { // this block is important for tests only
            $root = Config::getPhpbrewRoot();
            $home = Config::getPhpbrewHome();
            if (!file_exists("$root/php/$buildName")) {
                throw new Exception("build $buildName doesn't exist.");
            }
            putenv("PHPBREW_ROOT=$root");
            putenv("PHPBREW_HOME=$home");
            putenv("PHPBREW_PHP=$buildName");
            putenv("PHPBREW_PATH=$root/php/$buildName/bin");
            putenv("PHPBREW_BIN=$home/bin");
        }
        $this->logger->warning("You should not see this, if you see this, it means you didn't load the ~/.phpbrew/bashrc script, please check if bashrc is sourced in your shell.");
    }
}

<?php
namespace PhpBrew\Command;

use CLIFramework\Command;
use PhpBrew\Config;

/**
 * @codeCoverageIgnore
 */
class UseCommand extends Command
{

    public function arguments($args) {
        $args->add('php version')
            ->validValues(function(){
                return Config::findMatchedBuilds();
            })
            ;
    }

    public function brief()
    {
        return 'Use php, switch version temporarily';
    }

    public function execute($buildName) {
        { // this block is important for tests only
            $root = Config::getPhpbrewRoot();
            $home = Config::getPhpbrewHome();
            putenv("PHPBREW_ROOT=$root");
            putenv("PHPBREW_HOME=$home");
            putenv("PHPBREW_PHP=$buildName");
            putenv("PHPBREW_PATH=$root/$buildName/bin");
            putenv("PHPBREW_BIN=$home/bin");
        }
        $this->logger->warning("You should not see this, if you see this, it means you didn't load the ~/.phpbrew/bashrc script, please check if bashrc is sourced in your shell.");
    }
}

--- 
+++ 
@@ -1,8 +1,8 @@
 <?php
 namespace PhpBrew\Command;
-
 use CLIFramework\Command;
 use PhpBrew\Config;
+use Exception;
 
 /**
  * @codeCoverageIgnore
@@ -24,13 +24,20 @@
     }
 
     public function execute($buildName) {
+        if ($buildName) {
+            // This exception is used for tracing tests
+            throw new Exception("build name is required.");
+        }
         { // this block is important for tests only
             $root = Config::getPhpbrewRoot();
             $home = Config::getPhpbrewHome();
+            if (!file_exists("$root/php/$buildName")) {
+                throw new Exception("build $buildName doesn't exist.");
+            }
             putenv("PHPBREW_ROOT=$root");
             putenv("PHPBREW_HOME=$home");
             putenv("PHPBREW_PHP=$buildName");
-            putenv("PHPBREW_PATH=$root/$buildName/bin");
+            putenv("PHPBREW_PATH=$root/php/$buildName/bin");
             putenv("PHPBREW_BIN=$home/bin");
         }
         $this->logger->warning("You should not see this, if you see this, it means you didn't load the ~/.phpbrew/bashrc script, please check if bashrc is sourced in your shell.");
Add more checks in use command
