Beispiel #1
0
 public function testGettingAllResources()
 {
     /* Given... (Fixture) */
     // Quite justifiable.
     $rawRaml = Yaml::parse(__DIR__ . self::DEFAULT_SCHEMA_RAML);
     $ramlDoc = new RamlDoc($rawRaml, self::DEFAULT_SCHEMA_RAML);
     /* When... (Action) */
     $types = $ramlDoc->getResources();
     /* Then... (Assertions) */
     $this->assertEquals(['some-resources'], $types);
 }
Beispiel #2
0
 /**
  * @param array &$map
  * @param string $fileDir
  * @return array
  */
 protected function dereferenceIncludes(array &$map, $fileDir = __DIR__)
 {
     foreach ($map as &$value) {
         if (is_string($value)) {
             if (RamlDoc::isInclude($value)) {
                 $value = $this->dereferenceInclude($value, $fileDir);
             } else {
                 throw new \ErrorException(self::ERROR_UNEXPECTED_VALUE);
             }
         }
     }
     return $map;
 }
Beispiel #3
0
 /**
  * @param mixed $raml
  * @param string $key
  * @return mixed
  * @throws \ErrorException
  * @throws PathNotFoundException
  */
 private static function dig($raml, $key = NULL)
 {
     $args = array_slice(func_get_args(), 2);
     if (!empty($key)) {
         if (!is_scalar($key)) {
             throw new \ErrorException(self::ERROR_INVALID_KEY);
         } elseif (RamlDoc::isResource($key)) {
             $parts = explode('/', substr($key, 1));
             if (1 < count($parts)) {
                 $callback = function ($part) {
                     return '/' . $part;
                 };
                 $parts = array_map($callback, $parts);
                 $parts = array_merge([$raml], $parts);
                 $raml = call_user_func_array(__METHOD__, $parts);
                 $key = array_shift($args);
             } elseif (self::isIdList($key)) {
                 // @todo Support non-num Ids.
                 $found = FALSE;
                 foreach (array_keys($raml) as $property) {
                     if (RamlDoc::isParameter($property)) {
                         $found = TRUE;
                         $key = $property;
                         break;
                     }
                 }
                 if (!$found) {
                     $message = sprintf(self::ERROR_PARAM_NOT_FOUND, $key);
                     throw new PathNotFoundException($message);
                 }
             }
         }
         if (!isset($raml[$key])) {
             $message = sprintf(self::ERROR_KEY_NOT_FOUND, $key);
             throw new PathNotFoundException($message);
         }
         $args = array_merge([$raml[$key]], $args);
         $raml = call_user_func_array(__METHOD__, $args);
     }
     return $raml;
 }