예제 #1
0
 public function testGetCache()
 {
     setDummyCredentials();
     $cache = Terminus::getCache();
     setDummyCredentials();
     $session = $cache->getData('session');
     $this->assertEquals($session->user_uuid, '0ffec038-4410-43d0-a404-46997f672d7a');
 }
예제 #2
0
 /**
  * @vcr utils#checkCurrentVersion
  */
 public function testCheckForUpdate()
 {
     $log_file = getLogFileName();
     setOutputDestination($log_file);
     Terminus::getCache()->putData('latest_release', ['check_date' => strtotime('8 days ago')]);
     Utils\checkForUpdate();
     $file_contents = explode("\n", file_get_contents($log_file));
     $this->assertFalse(strpos(array_pop($file_contents), 'An update to Terminus is available.'));
     resetOutputDestination($log_file);
 }
예제 #3
0
 /**
  * Instantiates object, sets cache and session
  *
  * @return [TerminusCommand] $this
  */
 public function __construct()
 {
     //Load commonly used data from cache
     $this->cache = Terminus::getCache();
     $this->logger = Terminus::getLogger();
     $this->outputter = Terminus::getOutputter();
     $this->session = Session::instance();
     if (!Terminus::isTest()) {
         $this->checkForUpdate();
     }
 }
예제 #4
0
 public function testSetCache()
 {
     //Default target
     $terminus = new Terminus();
     $root = Terminus::getCache()->getRoot();
     $this->assertTrue(strpos($root, getenv('HOME')) !== false);
     //Giving no env var for explicitly set cache dir
     putenv('TERMINUS_CACHE_DIR=');
     $terminus->setCache();
     $root = Terminus::getCache()->getRoot();
     $this->assertTrue(strpos($root, getenv('HOME')) !== false);
     //Targeting a dir the Windows way
     exec('mkdir /tmp/out');
     $home = getenv('HOME');
     putenv('HOME=0');
     putenv('HOMEDRIVE=/tmp');
     putenv('HOMEPATH=out');
     $terminus->setCache();
     $root = Terminus::getCache()->getRoot();
     $this->assertTrue(strpos($root, '/tmp/out') !== false);
     //Clean-up
     putenv("HOME={$home}");
     exec("rm -r /tmp/out");
 }
예제 #5
0
 /**
  * Make a request to the Pantheon API
  *
  * @param [string] $realm   Permissions realm for data request (e.g. user,
  *   site organization, etc. Can also be "public" to simply pull read-only
  *   data that is not privileged.
  * @param [string] $uuid    The UUID of the item in the realm to access
  * @param [string] $path    API path (URL)
  * @param [string] $method  HTTP method to use
  * @param [mixed]  $options A native PHP data structure (e.g. int, string,
  *   array, or stdClass) to be sent along with the request
  * @return [array] $data
  */
 public static function request($realm, $uuid, $path = false, $method = 'GET', $options = null)
 {
     if (!in_array($realm, array('login', 'user', 'public'))) {
         Auth::loggedIn();
     }
     try {
         $cache = Terminus::getCache();
         if (!in_array($realm, array('login', 'user'))) {
             $options['cookies'] = array('X-Pantheon-Session' => Session::getValue('session'));
             $options['verify'] = false;
         }
         $url = Endpoint::get(array('realm' => $realm, 'uuid' => $uuid, 'path' => $path));
         if (Terminus::getConfig('debug')) {
             Terminus::log('debug', 'Request URL: ' . $url);
         }
         $resp = Request::send($url, $method, $options);
         $json = $resp->getBody(true);
         $data = array('info' => $resp->getInfo(), 'headers' => $resp->getRawHeaders(), 'json' => $json, 'data' => json_decode($json), 'status_code' => $resp->getStatusCode());
         return $data;
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
         throw new TerminusException($response->getBody(true));
     } catch (Guzzle\Http\Exception\HttpException $e) {
         $request = $e->getRequest();
         $sanitized_request = TerminusCommand::stripSensitiveData((string) $request, TerminusCommand::$blacklist);
         throw new TerminusException('API Request Error. {msg} - Request: {req}', array('req' => $sanitized_request, 'msg' => $e->getMessage()));
     } catch (Exception $e) {
         throw new TerminusException('API Request Error: {msg}', array('msg' => $e->getMessage()));
     }
 }
예제 #6
0
 public function __construct()
 {
     $this->file_cache = Terminus::getCache();
 }