Ejemplo n.º 1
0
 /**
  * @covers ::factory
  * @dataProvider dataFactory
  */
 public function testFactory($status, $class)
 {
     $exception = Exception\Factory::factory("Testing", $status);
     $this->assertInstanceOf($class, $exception);
     $this->assertEquals("Testing", $exception->getMessage());
     $this->assertEquals($status, $exception->getCode());
 }
Ejemplo n.º 2
0
 /**
  * Sends a request to the Nexmo API
  * 
  * @param array $query The query parameters
  *
  * @return Response
  * @throws Exception\Exception
  */
 protected function send(array $query)
 {
     if (!$this->key || !$this->secret || !$this->from) {
         throw new Exception\ConfigurationException("Invalid configuration. Missing key, secret, or from.");
     }
     $query["api_key"] = $this->key;
     $query["api_secret"] = $this->secret;
     $query["from"] = $this->from;
     $query["status-report-req"] = $this->status_report_req;
     if ($this->ttl) {
         $query["ttl"] = $this->ttl;
     }
     $response = $this->guzzle->get(self::API_URI, ["query" => $query])->json();
     /**
      * @var Message[] $messages
      * @var Exception\Exception[] $exceptions
      */
     $messages = [];
     $exceptions = [];
     foreach ($response["messages"] as $message) {
         if ($message["status"] != 0) {
             $exceptions[] = Exception\Factory::factory($message["error-text"], $message["status"]);
         } else {
             $messages[] = new Message($message);
         }
     }
     $response = new Response($messages, $exceptions);
     if ($exceptions) {
         $exceptions[0]->setResponse($response);
         throw $exceptions[0];
     }
     return $response;
 }