public function testGetResponse()
 {
     $response = new Base();
     $myArray = array("foo" => "bar");
     $response->response = $myArray;
     $this->assertEquals($myArray, $response->getResponse());
 }
Exemple #2
0
 /**
  * Checks if the Browserstack Screenshots Service is online and accessible
  * Can be used prior any requests to ensure that the API is working
  *
  * If anything is fine, returns an Array with index 'success'
  * If any error occured contains an index 'errors' with an error message
  *
  * @return Array
  */
 public function isBrowserstackAccessable()
 {
     $message = null;
     $headers = get_headers(self::API_BASE_URL);
     $response = new Base();
     if (!empty($headers) && isset($headers[0])) {
         $httpCode = $headers[0];
         preg_match('#HTTP\\/1\\.1\\s+(.*?)\\s+#', $httpCode, $matches);
         if (!empty($matches) && isset($matches[1])) {
             $httpCode = $matches[1];
             http_response_code($httpCode);
             switch (substr($httpCode, 0, 1)) {
                 case 2:
                     $response->setApiResponse(['success' => ['Service is available']]);
                     return $response->getResponse();
                 case 4:
                     if ($httpCode == 404) {
                         $message = 'API Endpoint not found';
                     }
                     if ($httpCode == 401) {
                         $message = 'User is not authorized';
                     }
                     if ($httpCode == 401) {
                         $message = 'Bad request';
                     }
                     break;
                 case 5:
                     $message = 'Bad request: ' . $httpCode;
                     break;
             }
         }
     } else {
         $message = 'Could not establish connection to Browserstacks';
     }
     $response->setApiResponse(['errors' => [$message]]);
     return $response->getResponse();
 }