<commit_before><?php

namespace IsmaAmbrosi\Bundle\GeneratorBundle\Tests\Generator;

use IsmaAmbrosi\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator;

/**
 * Class DoctrineDocumentGeneratorTest
 *
 * @author <NAME><<EMAIL>>
 */
class DoctrineCrudGeneratorTest extends GeneratorTestCase
{

    public function testAnnotation()
    {
        $prefix = 'test/admin/'.strtolower($this->getName());
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'annotation', $prefix, false);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$this->documentName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertFalse(method_exists($controller, 'newAction'), '"new" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'createAction'), '"create" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'deleteAction'), '"delete" action for controller does exists');

        $content = file_get_contents($file);
        $this->assertTrue(false !== strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');
    }

    public function testAnnotationWithWriteActions()
    {
        $prefix = 'test/admin/'.strtolower($this->getName());
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'annotation', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$this->documentName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'newAction'), '"new" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'createAction'), '"create" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'deleteAction'), '"delete" action for controller does not exists');

        $content = file_get_contents($file);
        $this->assertTrue(false !== strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');
    }

    public function testYaml()
    {
        $prefix = 'test/admin/'.strtolower($this->getName());
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'yaml', $prefix, false);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$this->documentName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertFalse(method_exists($controller, 'newAction'), '"new" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'createAction'), '"create" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'deleteAction'), '"delete" action for controller does exists');

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.yml', 'Routing file does not exists');
    }

    public function testYamlWithWriteActions()
    {
        $prefix = 'test/admin/'.strtolower($this->getName());
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'yaml', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$this->documentName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'newAction'), '"new" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'createAction'), '"create" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'deleteAction'), '"delete" action for controller does not exists');

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.yml', 'Routing file does not exists');
    }

    public function testXml()
    {
        $prefix = 'test/admin/'.strtolower($this->getName());
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'xml', $prefix, false);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$this->documentName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertFalse(method_exists($controller, 'newAction'), '"new" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'createAction'), '"create" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'deleteAction'), '"delete" action for controller does exists');

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.xml', 'Routing file does not exists');
    }

    public function testXmllWithWriteActions()
    {
        $prefix = 'test/admin/'.strtolower($this->getName());
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'xml', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$this->documentName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'newAction'), '"new" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'createAction'), '"create" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'deleteAction'), '"delete" action for controller does not exists');

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.xml', 'Routing file does not exists');
    }
}<commit_msg>Test case for deeper controllers<commit_after><?php

namespace IsmaAmbrosi\Bundle\GeneratorBundle\Tests\Generator;

use IsmaAmbrosi\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator;

/**
 * Class DoctrineDocumentGeneratorTest
 *
 * @author <NAME><<EMAIL>>
 */
class DoctrineCrudGeneratorTest extends GeneratorTestCase
{

    public function testAnnotation()
    {
        $prefix = $this->getPathPrefix();
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'annotation', $prefix, false);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithoutWriteActions($namespace, $this->documentName);

        $content = file_get_contents($file);
        $this->assertTrue(false !== strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');
    }

    public function testAnnotationWithWriteActions()
    {
        $prefix = $this->getPathPrefix();
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'annotation', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithWriteActions($namespace, $this->documentName);

        $content = file_get_contents($file);
        $this->assertTrue(false !== strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');
    }

    public function testYaml()
    {
        $prefix = $this->getPathPrefix();
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'yaml', $prefix, false);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithoutWriteActions($namespace, $this->documentName);

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.yml', 'Routing file does not exists');
    }

    public function testYamlWithWriteActions()
    {
        $prefix = $this->getPathPrefix();
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'yaml', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithWriteActions($namespace, $this->documentName);

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.yml', 'Routing file does not exists');
    }

    public function testXml()
    {
        $prefix = $this->getPathPrefix();
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'xml', $prefix, false);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithoutWriteActions($namespace, $this->documentName);

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.xml', 'Routing file does not exists');
    }

    public function testXmlWithWriteActions()
    {
        $prefix = $this->getPathPrefix();
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $this->documentName, $this->metadata, 'xml', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$this->documentName.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithWriteActions($namespace, $this->documentName);

        $content = file_get_contents($file);
        $this->assertTrue(false === strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/config/routing/'.strtolower($this->documentName).'.xml', 'Routing file does not exists');
    }

    public function testGeneratorWithDeeperPath()
    {
        $prefix = $this->getPathPrefix();

        $controllerName = 'Admin\\Canned\\Message\\'.$this->documentName;
        $controllerPath = str_replace('\\', DIRECTORY_SEPARATOR, $controllerName);
        $generator = new DoctrineCrudGenerator($this->getFilesystem(), __DIR__.'/../../Resources/skeleton/crud');
        $generator->generate($this->getTestBundle(), $this->documentName, $controllerName, $this->metadata, 'annotation', $prefix, true);

        $file = $this->getTestBundle()->getPath().'/Controller/'.$controllerPath.'Controller.php';
        $this->assertFileExists($file, 'Controller class file does not exists');
        require_once $file;

        $namespace = $this->getTestBundle()->getNamespace();
        $this->assertControllerWithWriteActions($namespace, $controllerName);

        $content = file_get_contents($file);
        $this->assertTrue(false !== strpos($content, '@Route("/'.$prefix.'")'), 'Route annotation not found in class');

    }

    protected function assertControllerWithWriteActions($namespace, $controllerName)
    {
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$controllerName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'newAction'), '"new" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'createAction'), '"create" action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'deleteAction'), '"delete" action for controller does not exists');

        $controllerPath = str_replace('\\', '/', $controllerName);
        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/index.html.twig');
        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/show.html.twig');
        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/new.html.twig');
        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/edit.html.twig');
    }

    protected function assertControllerWithoutWriteActions($namespace, $controllerName)
    {
        $this->assertTrue(class_exists($controller = $namespace.'\\Controller\\'.$controllerName.'Controller'), 'Controller class does not exists');
        $this->assertTrue(method_exists($controller, 'indexAction'), 'Index action for controller does not exists');
        $this->assertTrue(method_exists($controller, 'showAction'), 'Show action for controller does not exists');
        $this->assertFalse(method_exists($controller, 'newAction'), '"new" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'createAction'), '"create" action for controller does exists');
        $this->assertFalse(method_exists($controller, 'deleteAction'), '"delete" action for controller does exists');

        $controllerPath = str_replace('\\', '/', $controllerName);
        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/index.html.twig');
        $this->assertFileExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/show.html.twig');
        $this->assertFileNotExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/new.html.twig');
        $this->assertFileNotExists($this->getTestBundle()->getPath().'/Resources/views/'.$controllerPath.'/edit.html.twig');
    }

    private function getPathPrefix()
    {
        return 'test/admin/'.strtolower($this->getName());
    }
}
{'fraction_non_alphanumeric': 0.17474539757148452, 'fraction_numerical': 0.0, 'mean_word_length': 4.370759926373915, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 314, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4220143', 'n_tokens_mistral': 5336, 'n_tokens_neox': 5324, 'n_words': 1049}