/**
  * @param ApiResource $apiResource
  * @param ContainerBuilder $container
  */
 protected function setupEntity(ApiResource $apiResource, ContainerBuilder $container)
 {
     $apiResourceServiceName = $apiResource->getResourceServiceName();
     $formHandlerServiceName = $apiResource->getFormHandlerServiceName();
     $entityHandlerServiceName = $apiResource->getEntityHandlerServiceName();
     $controllerServiceName = $apiResource->getControllerServiceName();
     $filterServiceName = $apiResource->getFilterServiceName();
     $filter = $apiResource->getFilterClass();
     // Filter
     if ($container->hasDefinition($filter)) {
         $filterDefinition = $container->getDefinition($filter);
         $container->setDefinition($filterServiceName, $filterDefinition);
     } elseif (class_exists($filter)) {
         $filterDefinition = new Definition($filter);
         $container->setDefinition($filterServiceName, $filterDefinition);
     }
     // Form Handler
     $formHandler = new Definition(FormHandler::class);
     $formHandler->addArgument(new Reference('doctrine.orm.entity_manager'));
     $formHandler->addArgument(new Reference('form.factory'));
     $formHandler->addArgument($this->getFormType($apiResource));
     $container->setDefinition($formHandlerServiceName, $formHandler);
     // Handler
     $entityHandler = new Definition(BaseHandler::class);
     $entityHandler->addArgument(new Reference('doctrine.orm.entity_manager'));
     $entityHandler->addArgument(new Reference($apiResourceServiceName));
     $entityHandler->addArgument(new Reference($formHandlerServiceName));
     if ($filter) {
         $entityHandler->addArgument(new Reference($filterServiceName));
     }
     $container->setDefinition($entityHandlerServiceName, $entityHandler);
     // Controller
     $controller = new Definition(RestApiController::class);
     $controller->addMethodCall('setContainer', [new Reference('service_container')]);
     $controller->addMethodCall('setHandler', [new Reference($entityHandlerServiceName)]);
     $container->setDefinition($controllerServiceName, $controller);
 }
 /** @test */
 public function it_returns_the_entity_handler_service_name()
 {
     $this->assertEquals($this->bundlePrefix . '.entity_handler.posts', $this->config->getEntityHandlerServiceName());
 }