public function testApiErrorResponseWithCriticalException()
 {
     $e = new CriticalException('Test');
     $e->addMetaData('test', 'Test');
     $response = new ApiErrorResponse($e);
     $result = json_decode($response->getContent(), true);
     static::assertEquals(500, $response->getStatusCode());
     static::assertEquals('error', $result['status']);
     static::assertEquals(1, $result['count']);
     static::assertCount(1, $result['results']);
     static::assertEquals('Test', $result['results'][0]['message']);
     static::assertEquals('Test', $result['results'][0]['data']['test']);
 }
Пример #2
0
 /**
  * @param mixed $data
  *
  * @return array
  * @throws CriticalException
  */
 protected function getResults($data)
 {
     switch (gettype($data)) {
         case 'array':
             if ($this->isCollection($data)) {
                 $results = [];
                 foreach ($data as $subArray) {
                     $results[] = $this->handleArray($subArray);
                 }
                 return $results;
             }
             return [$this->handleArray($data)];
         case 'object':
             return [$this->handleObject($data)];
         case 'NULL':
             break;
         default:
             $e = new CriticalException('Data could not be formatted!');
             $e->addMetaData('input', $data);
             throw $e;
     }
     return [];
 }