|
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\Helper\DialogHelper; |
|
|
19 |
use Symfony\Component\DependencyInjection\Container; |
|
|
20 |
|
|
|
21 |
abstract class GenerateCommandTest extends \PHPUnit_Framework_TestCase |
|
|
22 |
{ |
|
|
23 |
protected function getHelperSet($input) |
|
|
24 |
{ |
|
|
25 |
$dialog = new DialogHelper(); |
|
|
26 |
$dialog->setInputStream($this->getInputStream($input)); |
|
|
27 |
|
|
|
28 |
return new HelperSet(array(new FormatterHelper(), $dialog)); |
|
|
29 |
} |
|
|
30 |
|
|
|
31 |
protected function getBundle() |
|
|
32 |
{ |
|
|
33 |
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); |
|
|
34 |
$bundle |
|
|
35 |
->expects($this->any()) |
|
|
36 |
->method('getPath') |
|
|
37 |
->will($this->returnValue(sys_get_temp_dir())) |
|
|
38 |
; |
|
|
39 |
|
|
|
40 |
return $bundle; |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
protected function getInputStream($input) |
|
|
44 |
{ |
|
|
45 |
$stream = fopen('php://memory', 'r+', false); |
|
|
46 |
fputs($stream, $input.str_repeat("\n", 10)); |
|
|
47 |
rewind($stream); |
|
|
48 |
|
|
|
49 |
return $stream; |
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
protected function getContainer() |
|
|
53 |
{ |
|
|
54 |
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); |
|
|
55 |
$kernel |
|
|
56 |
->expects($this->any()) |
|
|
57 |
->method('getBundle') |
|
|
58 |
->will($this->returnValue($this->getBundle())) |
|
|
59 |
; |
|
|
60 |
|
|
|
61 |
$filesystem = $this->getMock('Symfony\Component\HttpKernel\Util\Filesystem'); |
|
|
62 |
$filesystem |
|
|
63 |
->expects($this->any()) |
|
|
64 |
->method('isAbsolutePath') |
|
|
65 |
->will($this->returnValue(true)) |
|
|
66 |
; |
|
|
67 |
|
|
|
68 |
$container = new Container(); |
|
|
69 |
$container->set('kernel', $kernel); |
|
|
70 |
$container->set('filesystem', $filesystem); |
|
|
71 |
|
|
|
72 |
$container->setParameter('kernel.root_dir', sys_get_temp_dir()); |
|
|
73 |
|
|
|
74 |
return $container; |
|
|
75 |
} |
|
|
76 |
} |