|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mongrate\MongrateBundle\Tests\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Mongrate\MongrateBundle\MongrateBundle; |
|
6
|
|
|
use Mongrate\MongrateBundle\Tests\TestKernel; |
|
7
|
|
|
use Symfony\Component\Console\Application; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkApplication; |
|
9
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
10
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
14
|
|
|
|
|
15
|
|
|
abstract class AbstractCommandTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
protected $application; |
|
18
|
|
|
|
|
19
|
|
|
protected $config; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->application = new Application(); |
|
24
|
|
|
|
|
25
|
|
|
$this->config = [ |
|
26
|
|
|
'migrations_directory' => '/', |
|
27
|
|
|
'mongodb_server' => 'localhost', |
|
28
|
|
|
'mongodb_db' => 'test' |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function assertCommandIsFound($name, $class) |
|
33
|
|
|
{ |
|
34
|
|
|
$command = $this->application->find($name); |
|
35
|
|
|
$this->assertEquals($name, $command->getName()); |
|
36
|
|
|
$this->assertNotEmpty($command->getDescription()); |
|
37
|
|
|
$this->assertInstanceOf($class, $command); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertCommandIsRegisteredInBundle($name, $class); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function assertCommandIsRegisteredInBundle($name, $class) |
|
43
|
|
|
{ |
|
44
|
|
|
$mockContainer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container') |
|
45
|
|
|
->setMethods(['getParameter']) |
|
46
|
|
|
->getMock(); |
|
47
|
|
|
$mockContainer->expects($this->any()) |
|
48
|
|
|
->method('getParameter') |
|
49
|
|
|
->with('mongrate_bundle') |
|
50
|
|
|
->will($this->returnValue($this->config)); |
|
51
|
|
|
|
|
52
|
|
|
$kernel = new TestKernel($mockContainer); |
|
53
|
|
|
|
|
54
|
|
|
$frameworkApplication = new FrameworkApplication($kernel); |
|
55
|
|
|
|
|
56
|
|
|
$bundle = new MongrateBundle(); |
|
57
|
|
|
$bundle->registerCommands($frameworkApplication); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertInstanceOf($class, $frameworkApplication->find($name)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function assertIsContainerAware($name, $class) |
|
63
|
|
|
{ |
|
64
|
|
|
self::assertInstanceOf( |
|
65
|
|
|
ContainerAwareInterface::class, |
|
66
|
|
|
new $class($this->config), |
|
67
|
|
|
sprintf('The %s command is not instance of ContainerAwareInterface', $name) |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function assertContainerWasInjectedToService($name, $class) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->application->add(new $class($this->config)); |
|
74
|
|
|
|
|
75
|
|
|
$command = $this->application->get($name); |
|
76
|
|
|
|
|
77
|
|
|
$command->setContainer(new Container()); |
|
78
|
|
|
$command->initialize(New ArrayInput([]), new NullOutput()); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
self::assertAttributeInstanceOf( |
|
81
|
|
|
ContainerInterface::class, |
|
82
|
|
|
'container', |
|
83
|
|
|
\PHPUnit_Framework_Assert::getObjectAttribute($command, 'service'), |
|
84
|
|
|
sprintf('Container wasn\'t injected to the MigrationService by %s command', $name) |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.