Updated to Symfony 2.1 BETA3
This commit is contained in:
3
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/.gitignore
vendored
Normal file
3
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
phpunit.xml
|
||||
vendor
|
||||
composer.lock
|
@@ -55,7 +55,7 @@ conventions):
|
||||
|
||||
<info>php app/console generate:bundle --namespace=Acme/BlogBundle</info>
|
||||
|
||||
Note that you can use <comment>/</comment> instead of <comment>\\</comment> for the namespace delimiter to avoid any
|
||||
Note that you can use <comment>/</comment> instead of <comment>\\ </comment>for the namespace delimiter to avoid any
|
||||
problem.
|
||||
|
||||
If you want to disable any user interaction, use <comment>--no-interaction</comment> but don't forget to pass all needed options:
|
||||
|
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Sensio\Bundle\GeneratorBundle\Command\GenerateBundleCommand;
|
||||
|
||||
class GenerateBundleCommandTest extends GenerateCommandTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider getInteractiveCommandData
|
||||
*/
|
||||
public function testInteractiveCommand($options, $input, $expected)
|
||||
{
|
||||
list($namespace, $bundle, $dir, $format, $structure) = $expected;
|
||||
|
||||
$generator = $this->getGenerator();
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($namespace, $bundle, $dir, $format, $structure)
|
||||
;
|
||||
|
||||
$tester = new CommandTester($this->getCommand($generator, $input));
|
||||
$tester->execute($options);
|
||||
}
|
||||
|
||||
public function getInteractiveCommandData()
|
||||
{
|
||||
$tmp = sys_get_temp_dir();
|
||||
|
||||
return array(
|
||||
array(array('--dir' => $tmp), "Foo/BarBundle\n", array('Foo\BarBundle', 'FooBarBundle', $tmp.'/', 'annotation', false)),
|
||||
array(array('--dir' => $tmp), "Foo/BarBundle\nBarBundle\nfoo\nyml\nn", array('Foo\BarBundle', 'BarBundle', 'foo/', 'yml', false)),
|
||||
array(array('--dir' => $tmp, '--format' => 'yml', '--bundle-name' => 'BarBundle', '--structure' => true), "Foo/BarBundle\n", array('Foo\BarBundle', 'BarBundle', $tmp.'/', 'yml', true)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNonInteractiveCommandData
|
||||
*/
|
||||
public function testNonInteractiveCommand($options, $expected)
|
||||
{
|
||||
list($namespace, $bundle, $dir, $format, $structure) = $expected;
|
||||
|
||||
$generator = $this->getGenerator();
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($namespace, $bundle, $dir, $format, $structure)
|
||||
;
|
||||
|
||||
$tester = new CommandTester($this->getCommand($generator, ''));
|
||||
$tester->execute($options, array('interactive' => false));
|
||||
}
|
||||
|
||||
public function getNonInteractiveCommandData()
|
||||
{
|
||||
$tmp = sys_get_temp_dir();
|
||||
|
||||
return array(
|
||||
array(array('--dir' => $tmp, '--namespace' => 'Foo/BarBundle'), array('Foo\BarBundle', 'FooBarBundle', $tmp.'/', 'annotation', false)),
|
||||
array(array('--dir' => $tmp, '--namespace' => 'Foo/BarBundle', '--format' => 'yml', '--bundle-name' => 'BarBundle', '--structure' => true), array('Foo\BarBundle', 'BarBundle', $tmp.'/', 'yml', true)),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCommand($generator, $input)
|
||||
{
|
||||
$command = $this
|
||||
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Command\GenerateBundleCommand')
|
||||
->setMethods(array('checkAutoloader', 'updateKernel', 'updateRouting'))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$command->setContainer($this->getContainer());
|
||||
$command->setHelperSet($this->getHelperSet($input));
|
||||
$command->setGenerator($generator);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
protected function getGenerator()
|
||||
{
|
||||
// get a noop generator
|
||||
return $this
|
||||
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Generator\BundleGenerator')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('generate'))
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Sensio\Bundle\GeneratorBundle\Command\Helper\DialogHelper;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
|
||||
abstract class GenerateCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function getHelperSet($input)
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
$dialog->setInputStream($this->getInputStream($input));
|
||||
|
||||
return new HelperSet(array(new FormatterHelper(), $dialog));
|
||||
}
|
||||
|
||||
protected function getBundle()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle
|
||||
->expects($this->any())
|
||||
->method('getPath')
|
||||
->will($this->returnValue(sys_get_temp_dir()))
|
||||
;
|
||||
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
protected function getInputStream($input)
|
||||
{
|
||||
$stream = fopen('php://memory', 'r+', false);
|
||||
fputs($stream, $input.str_repeat("\n", 10));
|
||||
rewind($stream);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
$kernel
|
||||
->expects($this->any())
|
||||
->method('getBundle')
|
||||
->will($this->returnValue($this->getBundle()))
|
||||
;
|
||||
|
||||
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
|
||||
$filesystem
|
||||
->expects($this->any())
|
||||
->method('isAbsolutePath')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$container = new Container();
|
||||
$container->set('kernel', $kernel);
|
||||
$container->set('filesystem', $filesystem);
|
||||
|
||||
$container->setParameter('kernel.root_dir', sys_get_temp_dir());
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand;
|
||||
|
||||
class GenerateDoctrineCrudCommandTest extends GenerateCommandTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider getInteractiveCommandData
|
||||
*/
|
||||
public function testInteractiveCommand($options, $input, $expected)
|
||||
{
|
||||
list($entity, $format, $prefix, $withWrite) = $expected;
|
||||
|
||||
$generator = $this->getGenerator();
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($this->getBundle(), $entity, $this->getDoctrineMetadata(), $format, $prefix, $withWrite)
|
||||
;
|
||||
|
||||
$tester = new CommandTester($this->getCommand($generator, $input));
|
||||
$tester->execute($options);
|
||||
}
|
||||
|
||||
public function getInteractiveCommandData()
|
||||
{
|
||||
return array(
|
||||
array(array(), "AcmeBlogBundle:Blog/Post\n", array('Blog\\Post', 'annotation', 'blog_post', false)),
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post'), '', array('Blog\\Post', 'annotation', 'blog_post', false)),
|
||||
array(array(), "AcmeBlogBundle:Blog/Post\ny\nyml\nfoobar\n", array('Blog\\Post', 'yml', 'foobar', true)),
|
||||
array(array(), "AcmeBlogBundle:Blog/Post\ny\nyml\n/foobar\n", array('Blog\\Post', 'yml', 'foobar', true)),
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post', '--format' => 'yml', '--route-prefix' => 'foo', '--with-write' => true), '', array('Blog\\Post', 'yml', 'foo', true)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNonInteractiveCommandData
|
||||
*/
|
||||
public function testNonInteractiveCommand($options, $expected)
|
||||
{
|
||||
list($entity, $format, $prefix, $withWrite) = $expected;
|
||||
|
||||
$generator = $this->getGenerator();
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($this->getBundle(), $entity, $this->getDoctrineMetadata(), $format, $prefix, $withWrite)
|
||||
;
|
||||
|
||||
$tester = new CommandTester($this->getCommand($generator, ''));
|
||||
$tester->execute($options, array('interactive' => false));
|
||||
}
|
||||
|
||||
public function getNonInteractiveCommandData()
|
||||
{
|
||||
return array(
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post'), array('Blog\\Post', 'annotation', 'blog_post', false)),
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post', '--format' => 'yml', '--route-prefix' => 'foo', '--with-write' => true), array('Blog\\Post', 'yml', 'foo', true)),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCommand($generator, $input)
|
||||
{
|
||||
$command = $this
|
||||
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand')
|
||||
->setMethods(array('getEntityMetadata'))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$command
|
||||
->expects($this->any())
|
||||
->method('getEntityMetadata')
|
||||
->will($this->returnValue(array($this->getDoctrineMetadata())))
|
||||
;
|
||||
|
||||
$command->setContainer($this->getContainer());
|
||||
$command->setHelperSet($this->getHelperSet($input));
|
||||
$command->setGenerator($generator);
|
||||
$command->setFormGenerator($this->getFormGenerator());
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
protected function getDoctrineMetadata()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
protected function getGenerator()
|
||||
{
|
||||
// get a noop generator
|
||||
return $this
|
||||
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('generate'))
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
protected function getFormGenerator()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Generator\DoctrineFormGenerator')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('generate'))
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
$container = parent::getContainer();
|
||||
|
||||
$registry = $this->getMock('Symfony\Bridge\Doctrine\RegistryInterface');
|
||||
$registry
|
||||
->expects($this->any())
|
||||
->method('getEntityNamespace')
|
||||
->will($this->returnValue('Foo\\FooBundle\\Entity'))
|
||||
;
|
||||
|
||||
$container->set('doctrine', $registry);
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineEntityCommand;
|
||||
|
||||
class GenerateDoctrineEntityCommandTest extends GenerateCommandTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider getInteractiveCommandData
|
||||
*/
|
||||
public function testInteractiveCommand($options, $input, $expected)
|
||||
{
|
||||
list($entity, $format, $fields) = $expected;
|
||||
|
||||
$generator = $this->getGenerator();
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($this->getBundle(), $entity, $format, $fields)
|
||||
;
|
||||
|
||||
$tester = new CommandTester($this->getCommand($generator, $input));
|
||||
$tester->execute($options);
|
||||
}
|
||||
|
||||
public function getInteractiveCommandData()
|
||||
{
|
||||
return array(
|
||||
array(array(), "AcmeBlogBundle:Blog/Post\n", array('Blog\\Post', 'annotation', array())),
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post'), '', array('Blog\\Post', 'annotation', array())),
|
||||
array(array(), "AcmeBlogBundle:Blog/Post\nyml\n\n", array('Blog\\Post', 'yml', array())),
|
||||
array(array(), "AcmeBlogBundle:Blog/Post\nyml\ntitle\n\n255\ndescription\ntext\n\n", array('Blog\\Post', 'yml', array(
|
||||
array('fieldName' => 'title', 'type' => 'string', 'length' => 255),
|
||||
array('fieldName' => 'description', 'type' => 'text'),
|
||||
))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNonInteractiveCommandData
|
||||
*/
|
||||
public function testNonInteractiveCommand($options, $expected)
|
||||
{
|
||||
list($entity, $format, $fields) = $expected;
|
||||
|
||||
$generator = $this->getGenerator();
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($this->getBundle(), $entity, $format, $fields)
|
||||
;
|
||||
$generator
|
||||
->expects($this->any())
|
||||
->method('isReservedKeyword')
|
||||
->will($this->returnValue(false))
|
||||
;
|
||||
|
||||
$tester = new CommandTester($this->getCommand($generator, ''));
|
||||
$tester->execute($options, array('interactive' => false));
|
||||
}
|
||||
|
||||
public function getNonInteractiveCommandData()
|
||||
{
|
||||
return array(
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post'), array('Blog\\Post', 'annotation', array())),
|
||||
array(array('--entity' => 'AcmeBlogBundle:Blog/Post', '--format' => 'yml', '--fields' => 'title:string(255) description:text'), array('Blog\\Post', 'yml', array(
|
||||
array('fieldName' => 'title', 'type' => 'string', 'length' => 255),
|
||||
array('fieldName' => 'description', 'type' => 'text', 'length' => ''),
|
||||
))),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCommand($generator, $input)
|
||||
{
|
||||
$command = new GenerateDoctrineEntityCommand();
|
||||
$command->setContainer($this->getContainer());
|
||||
$command->setHelperSet($this->getHelperSet($input));
|
||||
$command->setGenerator($generator);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
protected function getGenerator()
|
||||
{
|
||||
// get a noop generator
|
||||
return $this
|
||||
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Generator\DoctrineEntityGenerator')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('generate', 'isReservedKeyword'))
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Generator;
|
||||
|
||||
use Sensio\Bundle\GeneratorBundle\Generator\BundleGenerator;
|
||||
|
||||
class BundleGeneratorTest extends GeneratorTest
|
||||
{
|
||||
public function testGenerateYaml()
|
||||
{
|
||||
$generator = new BundleGenerator($this->filesystem, __DIR__.'/../../Resources/skeleton/bundle');
|
||||
$generator->generate('Foo\BarBundle', 'FooBarBundle', $this->tmpDir, 'yml', false);
|
||||
|
||||
$files = array(
|
||||
'FooBarBundle.php',
|
||||
'Controller/DefaultController.php',
|
||||
'Resources/views/Default/index.html.twig',
|
||||
'Resources/config/routing.yml',
|
||||
'Tests/Controller/DefaultControllerTest.php',
|
||||
'Resources/config/services.yml',
|
||||
'DependencyInjection/Configuration.php',
|
||||
'DependencyInjection/FooBarExtension.php',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertTrue(file_exists($this->tmpDir.'/Foo/BarBundle/'.$file), sprintf('%s has been generated', $file));
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Foo/BarBundle/FooBarBundle.php');
|
||||
$this->assertContains('namespace Foo\\BarBundle', $content);
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Foo/BarBundle/Controller/DefaultController.php');
|
||||
$this->assertContains('public function indexAction', $content);
|
||||
$this->assertNotContains('@Route("/hello/{name}"', $content);
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Foo/BarBundle/Resources/views/Default/index.html.twig');
|
||||
$this->assertContains('Hello {{ name }}!', $content);
|
||||
}
|
||||
|
||||
public function testGenerateAnnotation()
|
||||
{
|
||||
$generator = new BundleGenerator($this->filesystem, __DIR__.'/../../Resources/skeleton/bundle');
|
||||
$generator->generate('Foo\BarBundle', 'FooBarBundle', $this->tmpDir, 'annotation', false);
|
||||
|
||||
$this->assertFalse(file_exists($this->tmpDir.'/Foo/BarBundle/Resources/config/routing.yml'));
|
||||
$this->assertFalse(file_exists($this->tmpDir.'/Foo/BarBundle/Resources/config/routing.xml'));
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Foo/BarBundle/Controller/DefaultController.php');
|
||||
$this->assertContains('@Route("/hello/{name}"', $content);
|
||||
}
|
||||
}
|
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Generator;
|
||||
|
||||
use Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator;
|
||||
|
||||
class DoctrineCrudGeneratorTest extends GeneratorTest
|
||||
{
|
||||
public function testGenerateYamlFull()
|
||||
{
|
||||
$this->getGenerator()->generate($this->getBundle(), 'Post', $this->getMetadata(), 'yml', '/post', true);
|
||||
|
||||
$files = array(
|
||||
'Controller/PostController.php',
|
||||
'Tests/Controller/PostControllerTest.php',
|
||||
'Resources/config/routing/post.yml',
|
||||
'Resources/views/Post/index.html.twig',
|
||||
'Resources/views/Post/show.html.twig',
|
||||
'Resources/views/Post/new.html.twig',
|
||||
'Resources/views/Post/edit.html.twig',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertTrue(file_exists($this->tmpDir.'/'.$file), sprintf('%s has been generated', $file));
|
||||
}
|
||||
|
||||
$files = array(
|
||||
'Resources/config/routing/post.xml',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertFalse(file_exists($this->tmpDir.'/'.$file), sprintf('%s has not been generated', $file));
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Controller/PostController.php');
|
||||
$strings = array(
|
||||
'namespace Foo\BarBundle\Controller;',
|
||||
'public function indexAction',
|
||||
'public function showAction',
|
||||
'public function newAction',
|
||||
'public function editAction',
|
||||
);
|
||||
foreach ($strings as $string) {
|
||||
$this->assertContains($string, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGenerateXml()
|
||||
{
|
||||
$this->getGenerator()->generate($this->getBundle(), 'Post', $this->getMetadata(), 'xml', '/post', false);
|
||||
|
||||
$files = array(
|
||||
'Controller/PostController.php',
|
||||
'Tests/Controller/PostControllerTest.php',
|
||||
'Resources/config/routing/post.xml',
|
||||
'Resources/views/Post/index.html.twig',
|
||||
'Resources/views/Post/show.html.twig',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertTrue(file_exists($this->tmpDir.'/'.$file), sprintf('%s has been generated', $file));
|
||||
}
|
||||
|
||||
$files = array(
|
||||
'Resources/config/routing/post.yml',
|
||||
'Resources/views/Post/new.html.twig',
|
||||
'Resources/views/Post/edit.html.twig',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertFalse(file_exists($this->tmpDir.'/'.$file), sprintf('%s has not been generated', $file));
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Controller/PostController.php');
|
||||
$strings = array(
|
||||
'namespace Foo\BarBundle\Controller;',
|
||||
'public function indexAction',
|
||||
'public function showAction',
|
||||
);
|
||||
foreach ($strings as $string) {
|
||||
$this->assertContains($string, $content);
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Controller/PostController.php');
|
||||
$strings = array(
|
||||
'public function newAction',
|
||||
'public function editAction',
|
||||
'@Route',
|
||||
);
|
||||
foreach ($strings as $string) {
|
||||
$this->assertNotContains($string, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGenerateAnnotationWrite()
|
||||
{
|
||||
$this->getGenerator()->generate($this->getBundle(), 'Post', $this->getMetadata(), 'annotation', '/post', true);
|
||||
|
||||
$files = array(
|
||||
'Controller/PostController.php',
|
||||
'Tests/Controller/PostControllerTest.php',
|
||||
'Resources/views/Post/index.html.twig',
|
||||
'Resources/views/Post/show.html.twig',
|
||||
'Resources/views/Post/new.html.twig',
|
||||
'Resources/views/Post/edit.html.twig',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertTrue(file_exists($this->tmpDir.'/'.$file), sprintf('%s has been generated', $file));
|
||||
}
|
||||
|
||||
$files = array(
|
||||
'Resources/config/routing/post.yml',
|
||||
'Resources/config/routing/post.xml',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertFalse(file_exists($this->tmpDir.'/'.$file), sprintf('%s has not been generated', $file));
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Controller/PostController.php');
|
||||
$strings = array(
|
||||
'namespace Foo\BarBundle\Controller;',
|
||||
'public function indexAction',
|
||||
'public function showAction',
|
||||
'public function newAction',
|
||||
'public function editAction',
|
||||
'@Route',
|
||||
);
|
||||
foreach ($strings as $string) {
|
||||
$this->assertContains($string, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGenerateAnnotation()
|
||||
{
|
||||
$this->getGenerator()->generate($this->getBundle(), 'Post', $this->getMetadata(), 'annotation', '/post', false);
|
||||
|
||||
$files = array(
|
||||
'Controller/PostController.php',
|
||||
'Tests/Controller/PostControllerTest.php',
|
||||
'Resources/views/Post/index.html.twig',
|
||||
'Resources/views/Post/show.html.twig',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertTrue(file_exists($this->tmpDir.'/'.$file), sprintf('%s has been generated', $file));
|
||||
}
|
||||
|
||||
$files = array(
|
||||
'Resources/config/routing/post.yml',
|
||||
'Resources/config/routing/post.xml',
|
||||
'Resources/views/Post/new.html.twig',
|
||||
'Resources/views/Post/edit.html.twig',
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$this->assertFalse(file_exists($this->tmpDir.'/'.$file), sprintf('%s has not been generated', $file));
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Controller/PostController.php');
|
||||
$strings = array(
|
||||
'namespace Foo\BarBundle\Controller;',
|
||||
'public function indexAction',
|
||||
'public function showAction',
|
||||
'@Route',
|
||||
);
|
||||
foreach ($strings as $string) {
|
||||
$this->assertContains($string, $content);
|
||||
}
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Controller/PostController.php');
|
||||
$strings = array(
|
||||
'public function newAction',
|
||||
'public function editAction',
|
||||
);
|
||||
foreach ($strings as $string) {
|
||||
$this->assertNotContains($string, $content);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getGenerator()
|
||||
{
|
||||
return new DoctrineCrudGenerator($this->filesystem, __DIR__.'/../../Resources/skeleton/crud');
|
||||
}
|
||||
|
||||
protected function getBundle()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
|
||||
$bundle->expects($this->any())->method('getName')->will($this->returnValue('FooBarBundle'));
|
||||
$bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\BarBundle'));
|
||||
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
public function getMetadata()
|
||||
{
|
||||
$metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
|
||||
$metadata->identifier = array('id');
|
||||
$metadata->fieldMappings = array('title' => array('type' => 'string'));
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Generator;
|
||||
|
||||
use Sensio\Bundle\GeneratorBundle\Generator\DoctrineFormGenerator;
|
||||
|
||||
class DoctrineFormGeneratorTest extends GeneratorTest
|
||||
{
|
||||
public function testGenerate()
|
||||
{
|
||||
$generator = new DoctrineFormGenerator($this->filesystem, __DIR__.'/../../Resources/skeleton/form');
|
||||
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
|
||||
$bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\BarBundle'));
|
||||
|
||||
$metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
|
||||
$metadata->identifier = array('id');
|
||||
$metadata->associationMappings = array('title' => array('type' => 'string'));
|
||||
|
||||
$generator->generate($bundle, 'Post', $metadata);
|
||||
|
||||
$this->assertTrue(file_exists($this->tmpDir.'/Form/PostType.php'));
|
||||
|
||||
$content = file_get_contents($this->tmpDir.'/Form/PostType.php');
|
||||
$this->assertContains('->add(\'title\')', $content);
|
||||
$this->assertContains('class PostType extends AbstractType', $content);
|
||||
$this->assertContains("'data_class' => 'Foo\BarBundle\Entity\Post'", $content);
|
||||
$this->assertContains("'foo_barbundle_posttype'", $content);
|
||||
}
|
||||
}
|
32
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Tests/Generator/GeneratorTest.php
vendored
Normal file
32
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Tests/Generator/GeneratorTest.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sensio\Bundle\GeneratorBundle\Tests\Generator;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
abstract class GeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $filesystem;
|
||||
protected $tmpDir;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->tmpDir = sys_get_temp_dir().'/sf2';
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->filesystem->remove($this->tmpDir);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->filesystem->remove($this->tmpDir);
|
||||
}
|
||||
}
|
20
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/phpunit.xml.dist
vendored
Normal file
20
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit bootstrap="./vendor/autoload.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="SensioGeneratorBundle">
|
||||
<directory suffix="Test.php">./Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
Reference in New Issue
Block a user