1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sonata\EasyExtendsBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Application; |
6
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
7
|
|
|
use Symfony\Component\Console\Tests\Command\CommandTest; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
9
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Christian Gripp <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class GenerateCommandTest extends CommandTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ContainerInterface |
18
|
|
|
*/ |
19
|
|
|
private $container; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Application |
23
|
|
|
*/ |
24
|
|
|
private $application; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var GenerateCommand |
28
|
|
|
*/ |
29
|
|
|
private $command; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var CommandTester |
33
|
|
|
*/ |
34
|
|
|
private $tester; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var KernelInterface |
38
|
|
|
*/ |
39
|
|
|
private $kernel; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function setUp() |
45
|
|
|
{ |
46
|
|
|
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
47
|
|
|
|
48
|
|
|
$this->command = new GenerateCommand(); |
49
|
|
|
$this->command->setContainer($this->container); |
50
|
|
|
|
51
|
|
|
$this->application = new Application(); |
52
|
|
|
$this->application->add($this->command); |
53
|
|
|
|
54
|
|
|
$this->tester = new CommandTester($this->application->find('sonata:easy-extends:generate')); |
55
|
|
|
|
56
|
|
|
$this->kernel = $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); |
57
|
|
|
|
58
|
|
|
$this->container->expects($this->any()) |
59
|
|
|
->method('get') |
60
|
|
|
->will($this->returnCallback(function ($id) use ($kernel) { |
61
|
|
|
switch ($id) { |
62
|
|
|
case 'kernel': |
63
|
|
|
return $kernel; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return; |
67
|
|
|
})); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testExecuteWithEmptyOptions() |
71
|
|
|
{ |
72
|
|
|
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); |
73
|
|
|
$bundle->method('getName')->will($this->returnValue('FooBundle')); |
74
|
|
|
|
75
|
|
|
$this->kernel->method('getBundles')->will($this->returnValue(array($bundle))); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$output = $this->tester->execute(array( |
78
|
|
|
'command' => $this->command->getName() |
79
|
|
|
)); |
80
|
|
|
|
81
|
|
|
$this->assertRegExp('@Bundles availables :@', $this->tester->getDisplay()); |
82
|
|
|
$this->assertRegExp('@\- FooBundle@', $this->tester->getDisplay()); |
83
|
|
|
|
84
|
|
|
$this->assertSame(0, $output); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @dataProvider getNamespaceProvider |
89
|
|
|
*/ |
90
|
|
|
public function testExecuteWithInvalidNamespace($namespace) |
91
|
|
|
{ |
92
|
|
|
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); |
93
|
|
|
$bundle->method('getName')->will($this->returnValue('FooBundle')); |
94
|
|
|
|
95
|
|
|
$this->kernel->method('getBundles')->will($this->returnValue(array($bundle))); |
|
|
|
|
96
|
|
|
|
97
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
98
|
|
|
|
99
|
|
|
$this->tester->execute(array( |
100
|
|
|
'command' => $this->command->getName() |
101
|
|
|
), array( |
102
|
|
|
'namespace' => $namespace |
103
|
|
|
)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getNamespaceProvider() |
107
|
|
|
{ |
108
|
|
|
return array( |
109
|
|
|
array(':vendor'), |
110
|
|
|
array('foobar'), |
111
|
|
|
array(' '), |
112
|
|
|
array('\\\\\\\\'), |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.