|
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\GenerateBundleCommand; |
|
|
19 |
use Sensio\Bundle\GeneratorBundle\Command\Helper\DialogHelper; |
|
|
20 |
use Symfony\Component\DependencyInjection\Container; |
|
|
21 |
|
|
|
22 |
class GenerateBundleCommandTest extends GenerateCommandTest |
|
|
23 |
{ |
|
|
24 |
/** |
|
|
25 |
* @dataProvider getInteractiveCommandData |
|
|
26 |
*/ |
|
|
27 |
public function testInteractiveCommand($options, $input, $expected) |
|
|
28 |
{ |
|
|
29 |
list($namespace, $bundle, $dir, $format, $structure) = $expected; |
|
|
30 |
|
|
|
31 |
$generator = $this->getGenerator(); |
|
|
32 |
$generator |
|
|
33 |
->expects($this->once()) |
|
|
34 |
->method('generate') |
|
|
35 |
->with($namespace, $bundle, $dir, $format, $structure) |
|
|
36 |
; |
|
|
37 |
|
|
|
38 |
$tester = new CommandTester($this->getCommand($generator, $input)); |
|
|
39 |
$tester->execute($options); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
public function getInteractiveCommandData() |
|
|
43 |
{ |
|
|
44 |
$tmp = sys_get_temp_dir(); |
|
|
45 |
return array( |
|
|
46 |
array(array('--dir' => $tmp), "Foo/BarBundle\n", array('Foo\BarBundle', 'FooBarBundle', $tmp.'/', 'annotation', false)), |
|
|
47 |
array(array('--dir' => $tmp), "Foo/BarBundle\nBarBundle\nfoo\nyml\nn", array('Foo\BarBundle', 'BarBundle', 'foo/', 'yml', false)), |
|
|
48 |
array(array('--dir' => $tmp, '--format' => 'yml', '--bundle-name' => 'BarBundle', '--structure' => true), "Foo/BarBundle\n", array('Foo\BarBundle', 'BarBundle', $tmp.'/', 'yml', true)), |
|
|
49 |
); |
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
/** |
|
|
53 |
* @dataProvider getNonInteractiveCommandData |
|
|
54 |
*/ |
|
|
55 |
public function testNonInteractiveCommand($options, $expected) |
|
|
56 |
{ |
|
|
57 |
list($namespace, $bundle, $dir, $format, $structure) = $expected; |
|
|
58 |
|
|
|
59 |
$generator = $this->getGenerator(); |
|
|
60 |
$generator |
|
|
61 |
->expects($this->once()) |
|
|
62 |
->method('generate') |
|
|
63 |
->with($namespace, $bundle, $dir, $format, $structure) |
|
|
64 |
; |
|
|
65 |
|
|
|
66 |
$tester = new CommandTester($this->getCommand($generator, '')); |
|
|
67 |
$tester->execute($options, array('interactive' => false)); |
|
|
68 |
} |
|
|
69 |
|
|
|
70 |
public function getNonInteractiveCommandData() |
|
|
71 |
{ |
|
|
72 |
$tmp = sys_get_temp_dir(); |
|
|
73 |
return array( |
|
|
74 |
array(array('--dir' => $tmp, '--namespace' => 'Foo/BarBundle'), array('Foo\BarBundle', 'FooBarBundle', $tmp.'/', 'annotation', false)), |
|
|
75 |
array(array('--dir' => $tmp, '--namespace' => 'Foo/BarBundle', '--format' => 'yml', '--bundle-name' => 'BarBundle', '--structure' => true), array('Foo\BarBundle', 'BarBundle', $tmp.'/', 'yml', true)), |
|
|
76 |
); |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
protected function getCommand($generator, $input) |
|
|
80 |
{ |
|
|
81 |
$command = $this |
|
|
82 |
->getMockBuilder('Sensio\Bundle\GeneratorBundle\Command\GenerateBundleCommand') |
|
|
83 |
->setMethods(array('checkAutoloader', 'updateKernel', 'updateRouting')) |
|
|
84 |
->getMock() |
|
|
85 |
; |
|
|
86 |
|
|
|
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\BundleGenerator') |
|
|
99 |
->disableOriginalConstructor() |
|
|
100 |
->setMethods(array('generate')) |
|
|
101 |
->getMock() |
|
|
102 |
; |
|
|
103 |
} |
|
|
104 |
} |