/**
  * Generates the datatable class if it does not exist.
  *
  * @param BundleInterface $bundle     The bundle in which to create the class
  * @param string          $entity     The entity relative class name
  * @param array           $fields     The datatable fields
  * @param boolean         $clientSide The client side flag
  * @param string          $ajaxUrl    The ajax url
  * @param boolean         $bootstrap3 The bootstrap3 flag
  * @param boolean         $admin      The admin flag
  *
  * @throws RuntimeException
  */
 public function generate(BundleInterface $bundle, $entity, array $fields, $clientSide, $ajaxUrl, $bootstrap3, $admin)
 {
     $parts = explode("\\", $entity);
     $entityClass = array_pop($parts);
     $this->className = $entityClass . 'Datatable';
     $dirPath = $bundle->getPath() . '/Datatables';
     if (true === $admin) {
         $this->className = $entityClass . 'AdminDatatable';
         $dirPath = $bundle->getPath() . '/Datatables/Admin';
     }
     $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Datatable.php';
     if (true === $admin) {
         $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'AdminDatatable.php';
     }
     if (file_exists($this->classPath)) {
         throw new RuntimeException(sprintf('Unable to generate the %s datatable class as it already exists under the %s file', $this->className, $this->classPath));
     }
     $parts = explode('\\', $entity);
     array_pop($parts);
     // set ajaxUrl
     if (false === $clientSide) {
         // server-side
         if (!$ajaxUrl) {
             $this->ajaxUrl = strtolower($entityClass) . '_results';
         } else {
             $this->ajaxUrl = $ajaxUrl;
         }
     }
     $routePref = strtolower($entityClass);
     if (true === $admin) {
         $routePref = DatatablesRoutingLoader::PREF . strtolower($entityClass);
         $bootstrap3 = true;
     }
     $this->renderFile('class.php.twig', $this->classPath, array('namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'entity_class' => $entityClass, 'bundle' => $bundle->getName(), 'datatable_class' => $this->className, 'datatable_name' => $admin ? strtolower($entityClass) . '_admin_datatable' : strtolower($entityClass) . '_datatable', 'fields' => $fields, 'client_side' => (bool) $clientSide, 'ajax_url' => $admin ? DatatablesRoutingLoader::PREF . $this->ajaxUrl : $this->ajaxUrl, 'bootstrap3' => (bool) $bootstrap3, 'admin' => (bool) $admin, 'route_pref' => $routePref));
 }
 /**
  * Generates the entity form class if it does not exist.
  *
  * @param BundleInterface   $bundle   The bundle in which to create the class
  * @param string            $entity   The entity relative class name
  * @param ClassMetadataInfo $metadata The entity metadata class
  */
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
 {
     if (is_null($this->src)) {
         $this->src = $bundle->getPath();
     }
     $this->entity = $entity;
     $dirPath = $this->src . '/Form/Type';
     $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'FormType.php';
     if (count($metadata->identifier) > 1) {
         throw new \RuntimeException('The form generator does not support entity classes with multiple primary keys.');
     }
     $fields = $this->getFieldsFromMetadata($metadata);
     $maxColumnNameSize = 0;
     foreach ($fields as $field) {
         $maxColumnNameSize = max($field['columnNameSize'] + 2, $maxColumnNameSize);
     }
     $options = array('fields' => $fields, 'form_class' => $entity . 'FormType', 'form_label' => $entity, 'max_column_name_size' => $maxColumnNameSize);
     $this->tplOptions = array_merge($this->tplOptions, $options);
     $this->generateForm();
     $this->generateServices();
     if ($this->getContainer()->getParameter('dev_generator_tool.generate_translation')) {
         $g = new TranslationGenerator($this->filesystem, sprintf('%s/Resources/translations', $this->src), $entity, $fields);
         $g->generate();
     }
 }
 /**
  * @covers ::build
  * @dataProvider loadedServicesProvider
  */
 public function testLoadedServices(BundleInterface $bundle, array $expected_service_definitions)
 {
     $container = new ContainerBuilder();
     $bundle->build($container);
     $definitions = $container->getDefinitions();
     foreach ($definitions as $id => $def) {
         /* @var $def \Symfony\Component\DependencyInjection\Definition */
         $class = $def->getClass();
         $expected_service_definitions_count = count($expected_service_definitions);
         for ($i = 0; $i < $expected_service_definitions_count; $i++) {
             if ($id === $expected_service_definitions[$i]) {
                 unset($expected_service_definitions[$i]);
                 break;
             }
         }
         // reset indice
         $expected_service_definitions = array_values($expected_service_definitions);
         // found a resource we didn't expect
         if (count($expected_service_definitions) === $expected_service_definitions_count) {
             $this->fail('Test did not expect service definition to be loaded: ' . $id . ' with class ' . $class);
         }
         // test this later because fixing this failure can lead to the previous
         if (!class_exists($class)) {
             $this->fail(sprintf('Could not load class %s for definition %s', $class, $id));
         }
     }
     $this->assertEmpty($expected_service_definitions, 'Service definition(s) missing: ' . implode(',', $expected_service_definitions));
 }
 /**
  * {@inheritdoc}
  */
 public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask)
 {
     $this->output->writeln(sprintf('Installing assets for <comment>%s</comment>', $bundle->getNamespace(), $targetDir));
     $effectiveSymlinkMask = $this->assetsInstaller->installBundleAssets($bundle, $targetDir, $symlinkMask);
     $this->output->writeln($this->provideResultComment($symlinkMask, $effectiveSymlinkMask));
     return $effectiveSymlinkMask;
 }
 protected function getSkeletonDirs(BundleInterface $bundle = null)
 {
     $skeletonDirs = array();
     if (isset($bundle) && is_dir($dir = $bundle->getPath() . '/Resources/SensioGeneratorBundle/skeleton')) {
         $skeletonDirs[] = $dir;
     }
     if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir() . '/Resources/SensioGeneratorBundle/skeleton')) {
         $skeletonDirs[] = $dir;
     }
     $bundleDirs = $this->getContainer()->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton', null, false);
     $sensioGeneratorSkeletonPath = dirname(__DIR__) . '/Resources/skeleton';
     /*
      * Assert: $bundleDirs is an array that contains $sensioGeneratorSkeletonPath and maybe some more
      * Since $skeletonDirs is a prioritized list we want to exclude $sensioGeneratorSkeletonPath from $bundleDirs
      * now and make sure it is added at the end of the list.
      */
     foreach ($bundleDirs as $dir) {
         if ($dir != $sensioGeneratorSkeletonPath) {
             $skeletonDirs[] = $dir;
         }
     }
     $skeletonDirs[] = $sensioGeneratorSkeletonPath;
     $skeletonDirs[] = __DIR__ . '/../Resources';
     return $skeletonDirs;
 }
 public function generateServiceId(BundleInterface $bundle, $className)
 {
     $namespace = $bundle->getNamespace();
     $alias = $bundle->getAlias();
     $bundleClass = substr($className, strlen($namespace) + 1);
     return sprintf('%s.%s', $alias, $this->makeParentDirAsClassifier($bundleClass));
 }
Example #7
0
 /**
  * Generates the entity form class if it does not exist.
  *
  * @param BundleInterface $bundle The bundle in which to create the class
  * @param string $entity The entity relative class name
  * @param ClassMetadataInfo $metadata The entity metadata class
  */
 public function generate(BundleInterface $bundle, $entity, $fields, $options = null, $search = false)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $this->className = $entityClass . 'Type';
     $dirPath = $bundle->getPath() . '/Form';
     if ($search) {
         $className = $entityClass . 'SearchType';
         $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'SearchType.php';
     } else {
         $className = $entityClass . 'Type';
         $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Type.php';
     }
     if (file_exists($this->classPath)) {
         unlink($this->classPath);
         //throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
     }
     $choice = false;
     foreach ($fields as $field) {
         if ($field['fragment'] == 'choice') {
             $choice = true;
         }
     }
     $parts = explode('\\', $entity);
     array_pop($parts);
     $this->renderFile($this->skeletonDir, 'FormType_tab.php', $this->classPath, array('dir' => $this->skeletonDir, 'fields' => $fields, 'namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'form_class' => $className, 'form_type_name' => strtolower(str_replace('\\', '_', $bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . $this->className), 'entityName' => $entityClass, 'choice' => $choice, 'options' => $options));
 }
Example #8
0
 /**
  * @param string $class
  * @param BundleInterface $bundle
  *
  * @return boolean
  */
 public function isClassInBundle($class, BundleInterface $bundle)
 {
     if (false === $class instanceof \ReflectionClass) {
         $class = $this->reflection->createFromClass($class);
     }
     return true === strpos($class->getNamespaceName(), $bundle->getNamespace());
 }
Example #9
0
 /**
  * <parameters>
  *  <parameter key="app.project.module.class">AppBundle\Module\ProjectModule</parameter>
  * </parameters>
  * <service id="app.project.module" class="%app.project.module.class%">
  *  <tag name="clastic.module" node_module="true" alias="project" />
  *  <tag name="clastic.node_form" build_service="app.project.module.form_build" />
  * </service>.
  *
  * @param BundleInterface $bundle
  * @param array           $data
  */
 private function updateDependencyInjectionXml(BundleInterface $bundle, array $data)
 {
     $file = $bundle->getPath() . '/Resources/config/services.xml';
     $xml = simplexml_load_file($file);
     $parameters = $xml->parameters ? $xml->parameters : $xml->addChild('parameters');
     $services = $xml->services ? $xml->services : $xml->addChild('services');
     $moduleServiceName = sprintf('%s.%s.module', $data['bundle_alias'], $data['identifier']);
     $moduleParameter = $parameters->addChild('parameter', sprintf('%s\\Module\\%sModule', $data['namespace'], $data['module']));
     $moduleParameter->addAttribute('key', sprintf('%s.class', $moduleServiceName));
     $formExtensionParameter = $parameters->addChild('parameter', sprintf('%s\\Form\\Module\\%sFormExtension', $data['namespace'], $data['module']));
     $formExtensionParameter->addAttribute('key', sprintf('%s.form_extension.class', $moduleServiceName));
     $moduleService = $services->addChild('service');
     $moduleService->addAttribute('id', sprintf('%s.%s.module', $data['bundle_alias'], $data['identifier']));
     $moduleService->addAttribute('class', sprintf('%%%s.class%%', $moduleServiceName));
     $moduleTag = $moduleService->addChild('tag');
     $moduleTag->addAttribute('name', 'clastic.module');
     $moduleTag->addAttribute('node_module', 'true');
     $moduleTag->addAttribute('alias', $data['identifier']);
     $formExtensionTag = $moduleService->addChild('tag');
     $formExtensionTag->addAttribute('name', 'clastic.node_form');
     $formExtensionTag->addAttribute('build_service', sprintf('%s.form_extension', $moduleServiceName));
     $formExtensionService = $services->addChild('service');
     $formExtensionService->addAttribute('id', sprintf('%s.form_extension', $moduleServiceName));
     $formExtensionService->addAttribute('class', sprintf('%%%s.form_extension.class%%', $moduleServiceName));
     $xml->saveXML($file);
 }
 /**
  * Export the translations from a given path
  *
  * @param BundleInterface $bundle
  * @param string          $locale
  * @param string          $outputDir
  * @param bool            $excel
  * @return array
  */
 private function exportTranslations(BundleInterface $bundle, $locale, $outputDir, $excel = false)
 {
     // if the bundle does not have a translation dir, continue to the next one
     $translationPath = sprintf('%s%s', $bundle->getPath(), '/Resources/translations');
     if (!is_dir($translationPath)) {
         return array();
     }
     // create a catalogue, and load the messages
     $catalogue = new MessageCatalogue($locale);
     /** @var \Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader $loader */
     $loader = $this->getContainer()->get('translation.loader');
     $loader->loadMessages($translationPath, $catalogue);
     // export in desired format
     if ($excel) {
         // check if the PHPExcel library is installed
         if (!class_exists('PHPExcel')) {
             throw new \RuntimeException('PHPExcel library is not installed. Please do so if you want to export translations as Excel file.');
         }
         $dumper = new ExcelFileDumper();
     } else {
         $dumper = new CsvFileDumper();
     }
     /** @var DumperInterface $dumper */
     return $dumper->dump($catalogue, array('path' => $outputDir, 'bundleName' => $bundle->getName()));
 }
    /**
     * Generates the entity form class if it does not exist.
     *
     * @param BundleInterface $bundle The bundle in which to create the class
     * @param string $entity The entity relative class name
     * @param ClassMetadataInfo $metadata The entity metadata class
     */
    public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
    {
        $parts       = explode('\\', $entity);
        $entityClass = array_pop($parts);

        $this->className = $entityClass.'Type';
        $dirPath         = $bundle->getPath().'/Form';
        $this->classPath = $dirPath.'/'.str_replace('\\', '/', $entity).'Type.php';

        if (file_exists($this->classPath)) {
            throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
        }

        if (count($metadata->identifier) > 1) {
            throw new \RuntimeException('The form generator does not support entity classes with multiple primary keys.');
        }

        $parts = explode('\\', $entity);
        array_pop($parts);

        $this->renderFile($this->skeletonDir, 'FormType.php', $this->classPath, array(
            'dir'              => $this->skeletonDir,
            'fields'           => $this->getFieldsFromMetadata($metadata),
            'namespace'        => $bundle->getNamespace(),
            'entity_namespace' => implode('\\', $parts),
            'form_class'       => $this->className,
        ));
    }
Example #12
0
 /**
  * Gets the prefix of the asset with the given bundle
  *
  * @param BundleInterface $bundle Bundle to fetch in
  *
  * @throws \InvalidArgumentException
  * @return string Prefix
  */
 public function getPrefix(BundleInterface $bundle)
 {
     if (!is_dir($bundle->getPath() . '/Resources/public')) {
         throw new \InvalidArgumentException(sprintf('Bundle %s does not have Resources/public folder', $bundle->getName()));
     }
     return sprintf('/bundles/%s', preg_replace('/bundle$/', '', strtolower($bundle->getName())));
 }
 protected function generateExceptionClass(BundleInterface $bundle, $target)
 {
     if (!is_dir(dirname($target))) {
         mkdir(dirname($target));
     }
     $this->renderFile('form/form_exception.php.twig', $target, ['namespace' => $bundle->getNamespace()]);
 }
Example #14
0
 public function findAdminControllerClasses(BundleInterface $bundle)
 {
     $directory = $bundle->getPath() . '/Controller/Admin';
     $namespace = $bundle->getNamespace() . '\\Controller\\Admin';
     $interface = AdminControllerInterface::class;
     $classes = $this->findClassesImplementingInterface($directory, $namespace, $interface);
     return $classes;
 }
 function it_locates_resource(PathCheckerInterface $pathChecker, KernelInterface $kernel, BundleInterface $bundle)
 {
     $bundle->getName()->willReturn("Bundle");
     $bundle->getPath()->willReturn("/app/bundle");
     $kernel->getBundle("Bundle", false)->willReturn([$bundle]);
     $pathChecker->processPaths(Argument::type('array'), Argument::type('array'), [])->shouldBeCalled()->willReturn("/app/bundle/resource");
     $this->locateResource("@Bundle/Resources/resource", [])->shouldReturn("/app/bundle/resource");
 }
 /**
  * Generate the fixtures class.
  *
  * @param BundleInterface   $bundle     A bundle object
  * @param BundleInterface   $destBundle The destination bundle object
  * @param string            $entity     The entity relative class name
  * @param ClassMetadataInfo $metadata   The entity class metadata
  * @parma integer           $num        The number of fixtures to generate
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, BundleInterface $destBundle, $entity, ClassMetadataInfo $metadata, $num = 1)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $dir = $destBundle->getPath() . '/DataFixtures/ORM/';
     $this->filesystem->mkdir($dir);
     $this->renderFile('fixtures/DataFixtures.php.twig', $dir . $entityClass . 'Data.php', array('namespace' => $destBundle->getNamespace(), 'bundle' => $bundle->getName(), 'entity' => $entity, 'entity_class' => $entityClass, 'fields' => $this->getFieldsFromMetadata($metadata), 'num' => $num));
 }
 /**
  * Generates the entity form class if it does not exist.
  *
  * @param BundleInterface   $bundle   The bundle in which to create the class
  * @param string            $entity   The entity relative class name
  * @param ClassMetadataInfo $metadata The entity metadata class
  * @param ArrayCollection   $options
  */
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, ArrayCollection $options = null)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $this->generatedName = $entityClass;
     $dirPath = $bundle->getPath() . '/Entity';
     $this->filePath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Interface.php';
     $this->renderFile('entity/interface.php.twig', $this->filePath, ['namespace' => $bundle->getNamespace()]);
 }
 /**
  * @param BundleInterface $bundle
  * @param ContainerBuilder $container
  * @param array $configs
  */
 protected function loadExtension(BundleInterface $bundle, ContainerBuilder $container, array $configs)
 {
     $extension = $bundle->getContainerExtension();
     if (!$extension) {
         return;
     }
     $config = array_key_exists($extension->getAlias(), $configs) ? $configs[$extension->getAlias()] : array();
     $extension->load(array($config), $container);
 }
 /**
  * @param string          $file
  * @param BundleInterface $bundle
  *
  * @return string|null
  */
 private function getClassFromFileAndBundle($file, BundleInterface $bundle)
 {
     $root = $bundle->getPath();
     if (0 !== strpos($file, $root)) {
         return;
     }
     $file = substr($file, strlen($root), -4);
     return sprintf('%s%s', $bundle->getNamespace(), str_replace(DIRECTORY_SEPARATOR, '\\', $file));
 }
 /**
  * @param BundleInterface $bundle
  * @param SwaggerDocument $document
  * @param string          $relativeNamespace
  */
 public function generate(BundleInterface $bundle, SwaggerDocument $document, $relativeNamespace = 'Model\\Resources')
 {
     $dir = $bundle->getPath();
     $parameters = ['namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'resource_namespace' => $relativeNamespace];
     foreach ($document->getResourceSchemas() as $typeName => $spec) {
         $resourceFile = "{$dir}/" . str_replace('\\', '/', $relativeNamespace) . "/{$typeName}.php";
         $this->renderFile('resource.php.twig', $resourceFile, array_merge($parameters, $spec, ['resource' => $typeName, 'resource_class' => $typeName]));
     }
 }
 function let(KernelWrapper $kernel, BundleInterface $bundle1, BundleInterface $bundle2, ServiceNameGenerator $generator)
 {
     $kernel->getBundles()->willReturn([$bundle1, $bundle2]);
     $this->beConstructedWith($kernel, $generator);
     $bundle1->getNamespace()->willReturn('Company\\MyBundle');
     $bundle1->getName()->willReturn('bundle1');
     $bundle2->getNamespace()->willReturn('Company\\MyOther\\Bundle');
     $bundle2->getName()->willReturn('Bundle2');
 }
 /**
  * @param BundleInterface $bundle
  * @param string          $controllerClassBasename
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $controllerClassBasename)
 {
     $this->class = sprintf('%s\\Controller\\%s', $bundle->getNamespace(), $controllerClassBasename);
     $this->file = sprintf('%s/Controller/%s.php', $bundle->getPath(), str_replace('\\', '/', $controllerClassBasename));
     $parts = explode('\\', $this->class);
     if (file_exists($this->file)) {
         throw new \RuntimeException(sprintf('Unable to generate the admin controller class "%s". The file "%s" already exists.', $this->class, realpath($this->file)));
     }
     $this->renderFile('AdminController.php.twig', $this->file, array('classBasename' => array_pop($parts), 'namespace' => implode('\\', $parts)));
 }
 private function mergeDefaultSettings(BundleInterface $bundle, array $settings)
 {
     if (empty($settings['contexts'])) {
         $settings['contexts'] = array($bundle->getNamespace() . $this->contextClassSuffix);
     }
     if (empty($settings['paths'])) {
         $settings['paths'] = array($bundle->getPath() . $this->pathSuffix);
     }
     return $settings;
 }
 /**
  * @param  BundleInterface   $bundle
  * @param  string            $adminClassBasename
  * @param  string            $modelClass
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $adminClassBasename, $modelClass)
 {
     $this->class = sprintf('%s\\Admin\\%s', $bundle->getNamespace(), $adminClassBasename);
     $this->file = sprintf('%s/Admin/%s.php', $bundle->getPath(), str_replace('\\', '/', $adminClassBasename));
     $parts = explode('\\', $this->class);
     if (file_exists($this->file)) {
         throw new \RuntimeException(sprintf('Unable to generate the admin class "%s". The file "%s" already exists.', $this->class, realpath($this->file)));
     }
     $this->renderFile('Admin.php.twig', $this->file, array('classBasename' => array_pop($parts), 'namespace' => implode('\\', $parts), 'fields' => $this->modelManager->getExportFields($modelClass)));
 }
Example #25
0
 public static function getNamingArray(BundleInterface $bundle)
 {
     $namingArray = array();
     $namespaceExploded = explode('\\', $bundle->getNamespace());
     $namingArray['Bundle'] = str_replace('Bundle', '', $namespaceExploded[1]);
     $namingArray['bundle'] = strtolower($namingArray['Bundle']);
     $namingArray['Vendor'] = $namespaceExploded[0];
     $namingArray['vendor'] = strtolower($namingArray['Vendor']);
     return $namingArray;
 }
 public function getExtensionNames(BundleInterface $bundle)
 {
     $extensions = $this->getExtensionDirectories($bundle->getPath());
     array_walk($extensions, function (&$path) {
         $path = basename($path);
     });
     if ($bundle instanceof LegacyBundleInterface) {
         $extensions = array_merge($extensions, $bundle->getLegacyExtensionsNames());
     }
     return $extensions;
 }
Example #27
0
 /**
  * Build a form based on the given table.
  * 
  * @param BundleInterface $bundle
  * @param Table           $table
  * @param string          $formTypeNamespace
  *
  * @return string
  */
 public function buildFormType(BundleInterface $bundle, Table $table, $formTypeNamespace)
 {
     $modelName = $table->getPhpName();
     $formTypeContent = file_get_contents(__DIR__ . '/../Resources/skeleton/FormType.php');
     $formTypeContent = str_replace('##NAMESPACE##', $bundle->getNamespace() . str_replace('/', '\\', $formTypeNamespace), $formTypeContent);
     $formTypeContent = str_replace('##CLASS##', $modelName . 'Type', $formTypeContent);
     $formTypeContent = str_replace('##FQCN##', sprintf('%s\\%s', $table->getNamespace(), $modelName), $formTypeContent);
     $formTypeContent = str_replace('##TYPE_NAME##', strtolower($modelName), $formTypeContent);
     $formTypeContent = str_replace('##BUILD_CODE##', $this->buildFormFields($table), $formTypeContent);
     return $formTypeContent;
 }
 /**
  * @param  Admin $admin
  * @param  BundleInterface $bundle
  * @return false | int
  */
 public function generate(Admin $admin, BundleInterface $bundle)
 {
     $admin_name = substr(get_class($admin), strripos(get_class($admin), '\\') + 1);
     $filePath = sprintf('%s/Tests/Admin/%sTest.php', $bundle->getPath(), $admin_name);
     $class = $admin->getClass();
     $mock = new $class();
     $admin->setSubject($mock);
     $namespace = $this->getNamespace($admin);
     $data = $this->generateDatas($admin->getFormFieldDescriptions());
     return $this->renderFile('AdminTests.php.twig', $filePath, array('admin' => $admin, 'formBuilder' => $admin->getFormBuilder(), 'listMapper' => $admin->getList(), 'admin_name' => $admin_name, 'namespace' => $namespace, 'fakeData' => $data));
 }
 function it_throws_an_exception_if_resource_can_not_be_located(Filesystem $filesystem, KernelInterface $kernel, ThemeInterface $theme, BundleInterface $childBundle, BundleInterface $parentBundle)
 {
     $kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]);
     $childBundle->getName()->willReturn('ChildBundle');
     $parentBundle->getName()->willReturn('ParentBundle');
     $theme->getName()->willReturn('theme/name');
     $theme->getPath()->willReturn('/theme/path');
     $filesystem->exists('/theme/path/ChildBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false);
     $filesystem->exists('/theme/path/ParentBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@ParentBundle/Resources/views/index.html.twig', $theme]);
 }
 private function writeFormType(BundleInterface $bundle, \Table $table, \SplFileInfo $file, $force, OutputInterface $output)
 {
     $modelName = $table->getPhpName();
     $formTypeContent = file_get_contents(__DIR__ . '/../Resources/skeleton/FormType.php');
     $formTypeContent = str_replace('##NAMESPACE##', $bundle->getNamespace() . str_replace('/', '\\', self::DEFAULT_FORM_TYPE_DIRECTORY), $formTypeContent);
     $formTypeContent = str_replace('##CLASS##', $modelName . 'Type', $formTypeContent);
     $formTypeContent = str_replace('##FQCN##', sprintf('%s\\%s', $table->getNamespace(), $modelName), $formTypeContent);
     $formTypeContent = str_replace('##TYPE_NAME##', strtolower($modelName), $formTypeContent);
     $formTypeContent = $this->addFields($table, $formTypeContent);
     file_put_contents($file->getPathName(), $formTypeContent);
     $this->writeNewFile($output, $this->getRelativeFileName($file) . ($force ? ' (forced)' : ''));
 }