/**
  * @dataProvider dataTestApiDeclaration
  */
 public function testApiDeclaration($resource, $expected)
 {
     set_error_handler(array($this, 'handleDeprecation'));
     $data = $this->extractor->all();
     restore_error_handler();
     $actual = $this->formatter->format($data, $resource);
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if (!$request->query->has($this->parameter)) {
         return;
     }
     $controller = $request->attributes->get('_controller');
     $route = $request->attributes->get('_route');
     if (null !== ($annotation = $this->extractor->get($controller, $route))) {
         $result = $this->formatter->formatOne($annotation);
         $event->setResponse(new Response($result, 200, array('Content-Type' => 'text/html')));
     }
 }
 /**
  * @param string $view View name
  * @return array|mixed
  */
 public function all($view = ApiDoc::DEFAULT_VIEW)
 {
     $cache = $this->getViewCache($view);
     if ($cache->isFresh() === false) {
         $resources = array();
         foreach ($this->getRoutes() as $route) {
             if (null !== ($method = $this->getReflectionMethod($route->getDefault('_controller'))) && null !== ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS))) {
                 $file = $method->getDeclaringClass()->getFileName();
                 $resources[] = new FileResource($file);
             }
         }
         $resources = array_merge($resources, $this->router->getRouteCollection()->getResources());
         $data = parent::all($view);
         $cache->write(serialize($data), $resources);
         return $data;
     }
     return unserialize(file_get_contents($cache));
 }