Created
May 12, 2015 18:16
-
-
Save mkorostoff/8ee27d9cc517850a4e8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Given /^I send a request to google page speed for "([^"]*)" with "([^"]*)" strategy$/ | |
*/ | |
public function iSendARequestToGooglePageSpeedForWithStrategy($path, $strategy) { | |
if ($path === 'the homepage') { | |
$url = $this->getMinkParameter('base_url'); | |
} | |
else { | |
$url = $this->getMinkParameter('base_url') . $path; | |
} | |
//Try google page speed up to 5 times | |
for ($i=0; $i<5; $i++) { | |
$this->restClient = new Client(); | |
$this->restClient->response = $this->restClient->get('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=' . $url . '&filter_third_party_resources=false&strategy=' . $strategy . '&fields=ruleGroups'); | |
//Grab the response code from google | |
$response_code = !empty($this->restClient->response->code) ? $this->restClient->response->code : FALSE; | |
//Stop sending requests to google page speed if we get a valid response | |
if (!empty($response_code) && $response_code == 200) { | |
break; | |
} | |
} | |
// If google does not respond, throw a PendingException. This allows us to | |
// continue executing the remaining steps without failing the whole build | |
if (empty($response_code) || $response_code != 200) { | |
throw new PendingException('Google did respond as with a ' . $response_code . 'code'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Matt! There is only one small thing. We should use:
instead of:
when we are defining $response_code variable.