Skip to content

Commit

Permalink
Merge pull request #12 from faouzic/feature/27411
Browse files Browse the repository at this point in the history
[FEATURE#27411] Namespace and exceptions
  • Loading branch information
faouzic committed May 3, 2016
2 parents 789a278 + 14b181e commit 04e9575
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions src/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function jeFaisUneRequetteHTTP($method, $url, $body = null)
if ($body !== null) {
$body = file_get_contents($this->requests_path . $body);
if (!$body) {
throw new Exception("File not found : {$this->requests_path}${body}");
throw new \Exception("File not found : {$this->requests_path}${body}");
}
}
$this->jeFaisUneRequetteHTTPAvecDuJSON($method, $url, $body);
Expand Down Expand Up @@ -98,7 +98,7 @@ public function leStatusHTTPDevraitEtre($code)
$retCode = $this->response["http_code"];
if ("$retCode" !== "$code") {
echo $this->response["body"];
throw new Exception("Bad http response code {$retCode} != {$code}");
throw new \Exception("Bad http response code {$retCode} != {$code}");
}
}

Expand All @@ -108,7 +108,7 @@ public function leStatusHTTPDevraitEtre($code)
public function leMessageHTTPDevraitEtre($mess)
{
if (trim($this->response['http_message']) != "$mess") {
throw new Exception("Bad message response message {$this->response['http_message']} != {$mess}");
throw new \Exception("Bad message response message {$this->response['http_message']} != {$mess}");
}
}

Expand All @@ -118,15 +118,15 @@ public function leMessageHTTPDevraitEtre($mess)
public function jeDevraisAvoirUnResultatDApiEnJSON()
{
if ("application/json" !== $this->response["headers"]["content-type"]) {
throw new Exception("Invalid response type");
throw new \Exception("Invalid response type");
}
if ("" == $this->response['body']) {
throw new Exception("No response");
throw new \Exception("No response");
}
$json = json_decode($this->response['body']);

if (null === $json && json_last_error()) {
throw new Exception("Invalid response");
throw new \Exception("Invalid response");
}
$this->data = $json;
}
Expand All @@ -137,7 +137,7 @@ public function jeDevraisAvoirUnResultatDApiEnJSON()
public function jeDevraisAvoirUnResultatDApiEnPdf()
{
if ("application/pdf" !== $this->response["headers"]["content-type"]) {
throw new Exception("Invalid response type");
throw new \Exception("Invalid response type");
}
}

Expand All @@ -147,7 +147,7 @@ public function jeDevraisAvoirUnResultatDApiEnPdf()
public function jeDevraisAvoirUnResultatDApiEnCsv()
{
if ("text/csv; charset=UTF-8" !== $this->response["headers"]["content-type"]) {
throw new Exception("Invalid response type");
throw new \Exception("Invalid response type");
}
}

Expand All @@ -162,7 +162,7 @@ public function leNomDuCsvDevraitEtre($filename)
$this->handleErrors($matches[1], $errors);
}
} else {
throw new Exception("Invalid filename");
throw new \Exception("Invalid filename");
}
}

Expand All @@ -172,7 +172,7 @@ public function leNomDuCsvDevraitEtre($filename)
public function leHeaderDoitEtre($header, $value)
{
if ($this->response["headers"][strtolower($header)] != $value) {
throw new Exception("Invalid header '{$header}'. Value should be '{$value}' but received '{$this->response["headers"][$header]}'");
throw new \Exception("Invalid header '{$header}'. Value should be '{$value}' but received '{$this->response["headers"][$header]}'");
}
}

Expand All @@ -185,11 +185,11 @@ public function jeDevraisAvoirUnTableauDeResultatsDeElements($length = null)
return;
}
if (!is_array($this->data)) {
throw new Exception("Response is not an array");
throw new \Exception("Response is not an array");
}
if (null !== $length) {
if (count($this->data) != $length) {
throw new Exception("Invalid response length " . count($this->data) . " != {$length}");
throw new \Exception("Invalid response length " . count($this->data) . " != {$length}");
}
}
}
Expand All @@ -205,7 +205,7 @@ public function leResultatDevraitRessemblerAuJsonSuivant($string)
{
$result = json_decode($string);
if (null === $result) {
throw new Exception("json_decode error");
throw new \Exception("json_decode error");
}

$this->check($result, $this->data, "result", $errors);
Expand All @@ -227,7 +227,7 @@ public function leResultatDevraitRessemblerAuFichier($file)
public function jeDevraisAvoirUnObjetCommeResultat()
{
if (!is_object($this->data)) {
throw new Exception("{$this->data} is not an object");
throw new \Exception("{$this->data} is not an object");
}
}
}
4 changes: 2 additions & 2 deletions src/BaseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setUp(BeforeScenarioScope $scope)
protected function getContext($context)
{
if (false === isset(self::$contexts[$context])) {
throw new Exception("Context {$context} not found");
throw new \Exception("Context {$context} not found");
}

return self::$contexts[$context];
Expand Down Expand Up @@ -63,7 +63,7 @@ protected function handleErrors($data, $errors)
{
if ($nb_err = count($errors)) {
echo json_encode($data, JSON_PRETTY_PRINT);
throw new Exception("{$nb_err} errors :\n" . implode("\n", $errors));
throw new \Exception("{$nb_err} errors :\n" . implode("\n", $errors));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MainContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getSilexApp()
public function getParameter($name)
{
if (false === isset(self::$parameters[$name])) {
throw new Exception("Parameter {$name} not set");
throw new \Exception("Parameter {$name} not set");
}

return self::$parameters[$name];
Expand Down
12 changes: 6 additions & 6 deletions src/RabbitContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function getNode($node, $response)

foreach ($nodes as $key_node => $node) {
if (!in_array($node, array_keys($current_node))) {
throw new Exception("Node {$node} not found");
throw new \Exception("Node {$node} not found");
}
$current_node = $current_node[$node];
}
Expand All @@ -92,7 +92,7 @@ public function devraitContenir($node, $node_value, $queue_name = null)

$this->check($node_value, $current_node_value, '', $errors);
if ($nb_err = count($errors)) {
throw new Exception("{$nb_err} errors :\n" . implode("\n", $errors));
throw new \Exception("{$nb_err} errors :\n" . implode("\n", $errors));
}
}

Expand All @@ -105,7 +105,7 @@ public function devraitContenirResultats($node, $length, $queue_name = null)

$current_node = $this->getNode($node, $response);
if ($length != count($current_node)) {
throw new Exception("Invalid node length " . count($current_node) . " != {$length}");
throw new \Exception("Invalid node length " . count($current_node) . " != {$length}");
}
}

Expand All @@ -119,7 +119,7 @@ function ($msg) {
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
$body = json_decode($msg->body);
if (empty($body)) {
throw new Exception("{$msg->body}");
throw new \Exception("{$msg->body}");
}
},
false,
Expand All @@ -137,7 +137,7 @@ public function ilDoitYAvoirUnMessageDansLaFileAvecLeCorpsContenuDans($queue = n
{
if (null !== $body) {
if (!file_exists($this->results_path . $body)) {
throw new Exception("File not found : {$this->results_path}${body}");
throw new \Exception("File not found : {$this->results_path}${body}");
}
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public function ilDoitYAvoirUnMessageDansLaFileEnJSON($queue = null)
$this->response[$queue] = $parsed_response;

if (!$parsed_response) {
throw new Exception("Error: Queue {$queue} is empty");
throw new \Exception("Error: Queue {$queue} is empty");
}
}

Expand Down

0 comments on commit 04e9575

Please sign in to comment.