parseFromString() public method

Parse a RAML spec from a string
public parseFromString ( string $ramlString, string $rootDir ) : ApiDefinition
$ramlString string
$rootDir string
return ApiDefinition
    /**
     * Returns a valid api def
     *
     * @throws \Exception
     *
     * @return \Raml\ApiDefinition
     */
    private function getValidDef()
    {
        $raml = <<<RAML
#%RAML 0.8
title: Users API
version: 1.2
baseUri: https://{apiDomain}.someapi.com/{version}
/users:
  displayName: retrieve all users
  baseUriParameters:
    apiDomain:
      enum: [ "api" ]
  /{userId}/image:
    displayName: access users pictures
    baseUriParameters:
      apiDomain:
        enum: [ "static" ]
    get:
      displayName: retrieve a user's picture
    put:
      displayName: update a user's picture
      baseUriParameters:
        apiDomain:
          enum: [ "content-update" ]
RAML;
        return $this->parser->parseFromString($raml, '');
    }
    /**
     * @return \Raml\Schema\Definition\XmlSchemaDefinition
     */
    private function getSchema()
    {
        $raml = <<<'RAML'
#%RAML 0.8

title: World Music API
baseUri: http://example.api.com/{version}
version: v1
/songs:
  get:
    responses:
        200:
          body:
            text/xml:
              schema: |
                <xs:schema attributeFormDefault="unqualified"
                elementFormDefault="qualified"
                xmlns:xs="http://www.w3.org/2001/XMLSchema">
                    <xs:element name="api-request">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element type="xs:string" name="input"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:schema>
RAML;
        $simpleRaml = $this->parser->parseFromString($raml, '');
        $resource = $simpleRaml->getResourceByUri('/songs');
        $method = $resource->getMethod('get');
        $response = $method->getResponse(200);
        $body = $response->getBodyByType('text/xml');
        return $body->getSchema();
    }
    /** @test */
    public function shouldCorrectlyParseBaseUriParameters()
    {
        $raml = <<<RAML
#%RAML 0.8
title: User API
version: 1.2
/user:
  /{userId}:
    displayName: Get a user
    uriParameters:
      userId:
        type: integer
    get:
      displayName: retrieve a user's picture
RAML;
        $apiDef = $this->parser->parseFromString($raml, '');
        $resource = $apiDef->getResourceByUri('/user/1');
        $this->assertInstanceOf('\\Raml\\Resource', $resource);
    }
    /** @test */
    public function shouldCorrectlyParseRegexUriParameters()
    {
        $raml = <<<RAML
#%RAML 0.8
title: User API
version: 1.2
/user:
  /{userName}:
    displayName: Get a user by name
    uriParameters:
      userName:
        type: string
        pattern: ^[a-z0-9]+\$
    get:
      displayName: retrieve a user's picture by user name
RAML;
        $apiDef = $this->parser->parseFromString($raml, '');
        $resource = $apiDef->getResourceByUri('/user/alec');
        $this->assertInstanceOf('\\Raml\\Resource', $resource);
    }
    /** @test */
    public function shouldThrowExceptionOnInvalidFile()
    {
        $raml = <<<RAML
#%RAML 0.8
title: Test named parameters
/:
  post:
    body:
      application/x-www-form-urlencoded:
        formParameters:
          param:
            type: file
            default: 1
RAML;
        $this->setExpectedException('Exception', 'A default value cannot be set for a file');
        $this->parser->parseFromString($raml, '');
    }
    /** @test */
    public function shouldSupportGenericResponseType()
    {
        $raml = <<<'RAML'
#%RAML 0.8
title: Test body
/:
  get:
    description: A post to do something
    responses:
      200:
        body:
          "*/*":
            description: A generic description
RAML;
        $apiDefinition = $this->parser->parseFromString($raml, '');
        $resource = $apiDefinition->getResourceByUri('/');
        $method = $resource->getMethod('get');
        $response = $method->getResponse(200);
        $body = $response->getBodyByType('text/xml');
        $this->assertEquals('A generic description', $body->getDescription());
    }
    /** @test */
    public function shouldBeAbleToGetAllParameters()
    {
        $raml = <<<RAML
#%RAML 0.8
title: Test named parameters
/:
  post:
    body:
      multipart/form-data:
        formParameters:
          string:
            type: string
            default: A string
RAML;
        $apiDefinition = $this->parser->parseFromString($raml, '');
        $resource = $apiDefinition->getResourceByUri('/');
        $method = $resource->getMethod('post');
        $body = $method->getBodyByType('multipart/form-data');
        $parameters = $body->getParameters();
        $expectedParameter = new \Raml\NamedParameter('string');
        $expectedParameter->setDefault('A string');
        $this->assertEquals(['string' => $expectedParameter], $parameters);
    }