コード例 #1
0
 /**
  * @param array $provider
  *
  * @dataProvider provider
  */
 public function testCreate($provider)
 {
     $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock();
     $expressionFunctionProvider = $this->getMock('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface');
     $routeCollection = $this->getMockBuilder('Symfony\\Component\\Routing\\RouteCollection')->getMock();
     if (!empty($provider['route'])) {
         $routeCollection->expects($this->any())->method('get')->with($provider['route'])->willReturn($route);
     }
     $router = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Routing\\Router')->disableOriginalConstructor()->getMock();
     $router->expects($this->any())->method('getRouteCollection')->willReturn($routeCollection);
     $apiDocFactory = new ApiDocFactory($router);
     $output = $apiDocFactory->create($provider);
     /** @var ApiDoc $apiDoc */
     $apiDoc = $output['annotation'];
     $this->assertArrayHasKey('resource', $output);
     $this->assertEquals($provider['resource'], $output['resource']);
     $this->assertArrayHasKey('annotation', $output);
     $testRequirements = $this->requirementsBuilder($provider['requirements']);
     $this->assertEquals($testRequirements, $apiDoc->getRequirements());
     $testParameters = $this->parametersBuilder($provider['parameters']);
     $this->assertEquals($testParameters, $apiDoc->getParameters());
     if (!empty($provider['route'])) {
         $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $apiDoc->getRoute());
     }
     $this->assertEquals($provider['description'], $apiDoc->getDescription());
     $this->assertEquals($provider['section'], $apiDoc->getSection());
     $this->assertEquals($provider['output'], $apiDoc->getOutput());
 }
コード例 #2
0
 /**
  * @param array|string[] $files
  *
  * @return bool
  */
 public function parse(array $files)
 {
     $output = array();
     foreach ($files as $file) {
         $fileSystem = new Filesystem();
         if (!$fileSystem->exists($file)) {
             throw new FileNotFoundException(null, 0, null, $file);
         }
         $fileDocumentations = Yaml::parse($file);
         if (is_array($fileDocumentations)) {
             foreach ($fileDocumentations as $documentation) {
                 $output[] = $this->apiDocFactory->create($documentation);
             }
         }
     }
     return $output;
 }