|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Sensio\Bundle\GeneratorBundle\Tests\Command; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Console\Helper\HelperSet; |
|
|
15 |
use Symfony\Component\Console\Helper\FormatterHelper; |
|
|
16 |
use Symfony\Component\Console\Output\StreamOutput; |
|
|
17 |
use Symfony\Component\Console\Tester\CommandTester; |
|
|
18 |
use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineEntityCommand; |
|
|
19 |
use Sensio\Bundle\GeneratorBundle\Command\Helper\DialogHelper; |
|
|
20 |
use Symfony\Component\DependencyInjection\Container; |
|
|
21 |
|
|
|
22 |
class GenerateDoctrineEntityCommandTest extends GenerateCommandTest |
|
|
23 |
{ |
|
|
24 |
/** |
|
|
25 |
* @dataProvider getInteractiveCommandData |
|
|
26 |
*/ |
|
|
27 |
public function testInteractiveCommand($options, $input, $expected) |
|
|
28 |
{ |
|
|
29 |
list($entity, $format, $fields) = $expected; |
|
|
30 |
|
|
|
31 |
$generator = $this->getGenerator(); |
|
|
32 |
$generator |
|
|
33 |
->expects($this->once()) |
|
|
34 |
->method('generate') |
|
|
35 |
->with($this->getBundle(), $entity, $format, $fields) |
|
|
36 |
; |
|
|
37 |
|
|
|
38 |
$tester = new CommandTester($this->getCommand($generator, $input)); |
|
|
39 |
$tester->execute($options); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
public function getInteractiveCommandData() |
|
|
43 |
{ |
|
|
44 |
return array( |
|
|
45 |
array(array(), "AcmeBlogBundle:Blog/Post\n", array('Blog\\Post', 'annotation', array())), |
|
|
46 |
array(array('--entity' => 'AcmeBlogBundle:Blog/Post'), '', array('Blog\\Post', 'annotation', array())), |
|
|
47 |
array(array(), "AcmeBlogBundle:Blog/Post\nyml\n\n", array('Blog\\Post', 'yml', array())), |
|
|
48 |
array(array(), "AcmeBlogBundle:Blog/Post\nyml\ntitle\n\n255\ndescription\ntext\n\n", array('Blog\\Post', 'yml', array( |
|
|
49 |
array('fieldName' => 'title', 'type' => 'string', 'length' => 255), |
|
|
50 |
array('fieldName' => 'description', 'type' => 'text'), |
|
|
51 |
))), |
|
|
52 |
); |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
/** |
|
|
56 |
* @dataProvider getNonInteractiveCommandData |
|
|
57 |
*/ |
|
|
58 |
public function testNonInteractiveCommand($options, $expected) |
|
|
59 |
{ |
|
|
60 |
list($entity, $format, $fields) = $expected; |
|
|
61 |
|
|
|
62 |
$generator = $this->getGenerator(); |
|
|
63 |
$generator |
|
|
64 |
->expects($this->once()) |
|
|
65 |
->method('generate') |
|
|
66 |
->with($this->getBundle(), $entity, $format, $fields) |
|
|
67 |
; |
|
|
68 |
|
|
|
69 |
$tester = new CommandTester($this->getCommand($generator, '')); |
|
|
70 |
$tester->execute($options, array('interactive' => false)); |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
public function getNonInteractiveCommandData() |
|
|
74 |
{ |
|
|
75 |
return array( |
|
|
76 |
array(array('--entity' => 'AcmeBlogBundle:Blog/Post'), array('Blog\\Post', 'annotation', array())), |
|
|
77 |
array(array('--entity' => 'AcmeBlogBundle:Blog/Post', '--format' => 'yml', '--fields' => 'title:string(255) description:text'), array('Blog\\Post', 'yml', array( |
|
|
78 |
array('fieldName' => 'title', 'type' => 'string', 'length' => 255), |
|
|
79 |
array('fieldName' => 'description', 'type' => 'text', 'length' => ''), |
|
|
80 |
))), |
|
|
81 |
); |
|
|
82 |
} |
|
|
83 |
|
|
|
84 |
protected function getCommand($generator, $input) |
|
|
85 |
{ |
|
|
86 |
$command = new GenerateDoctrineEntityCommand(); |
|
|
87 |
$command->setContainer($this->getContainer()); |
|
|
88 |
$command->setHelperSet($this->getHelperSet($input)); |
|
|
89 |
$command->setGenerator($generator); |
|
|
90 |
|
|
|
91 |
return $command; |
|
|
92 |
} |
|
|
93 |
|
|
|
94 |
protected function getGenerator() |
|
|
95 |
{ |
|
|
96 |
// get a noop generator |
|
|
97 |
return $this |
|
|
98 |
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Generator\DoctrineEntityGenerator') |
|
|
99 |
->disableOriginalConstructor() |
|
|
100 |
->setMethods(array('generate')) |
|
|
101 |
->getMock() |
|
|
102 |
; |
|
|
103 |
} |
|
|
104 |
} |