/** @test */ public function it_adds_datetime_to_fields() { if (Kernel::MAJOR_VERSION == 2 && Kernel::MINOR_VERSION == 7) { $dateTime = 'datetime'; } else { $dateTime = DateTimeType::class; } $this->form->expects($this->at(3))->method('add')->with('createdAt', $dateTime, ['widget' => 'single_text'])->willReturnSelf(); $this->subscriber->onPreSubmit($this->event); }
/** * @param ApiDoc $annotation * @param array $annotations * @param Route $route * @param \ReflectionMethod $method */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { if (!($resource = $this->getResource($route))) { return; } $context = new RequestContext('', $resource->getActions()->getActionForRoute($route)->getMethods()[0]); $this->router->setContext($context); $routeName = $this->router->match($route->getPath())['_route']; $section = $this->getSection($routeName, $resource); foreach ($annotations as $annot) { if ($annot instanceof GenerateApiDoc) { $annotation->setSection($section); if ($this->returnsEntity($route)) { $this->setOutput($annotation, $resource); } if ($this->expectsInput($route)) { if ($resource->getFormTypeClass() == DynamicFormType::class) { $entityClass = $resource->getEntityClass(); $handler = new DynamicFormSubscriber($this->em, new $entityClass()); foreach ($handler->getFields() as $field) { $annotation->addParameter($field, ['dataType' => 'string', 'required' => false]); } } else { $this->setInput($annotation, $resource); } } if ($roles = $route->getDefault('_roles')) { $annotation->setAuthentication(true); $annotation->setAuthenticationRoles($roles); } $annotation->setDescription($this->getDescription($resource, $route)); $annotation->setDocumentation($this->getDescription($resource, $route)); if ($resource->getActions()->getActionForRoute($route) instanceof Index) { $this->addFilter($annotation, $resource); $this->addPagination($annotation, $resource); } } } }