|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DoctrineModuleTest; |
|
6
|
|
|
|
|
7
|
|
|
use DoctrineModule\Module; |
|
8
|
|
|
use Laminas\Mvc\Application; |
|
9
|
|
|
use Laminas\Mvc\MvcEvent; |
|
10
|
|
|
use Laminas\ServiceManager\ServiceManager; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use function serialize; |
|
15
|
|
|
use function unserialize; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @covers \DoctrineModule\Module |
|
19
|
|
|
*/ |
|
20
|
|
|
class ModuleTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|Application */ |
|
23
|
|
|
private $application; |
|
24
|
|
|
|
|
25
|
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|MvcEvent */ |
|
26
|
|
|
private $event; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|ServiceManager */ |
|
30
|
|
|
private $serviceManager; |
|
31
|
|
|
|
|
32
|
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Console\Application */ |
|
33
|
|
|
private $cli; |
|
34
|
|
|
|
|
35
|
|
|
protected function setUp() : void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->application = $this->getMockBuilder('Laminas\Mvc\Application') |
|
|
|
|
|
|
38
|
|
|
->disableOriginalConstructor() |
|
39
|
|
|
->getMock(); |
|
40
|
|
|
$this->event = $this->createMock('Laminas\Mvc\MvcEvent'); |
|
|
|
|
|
|
41
|
|
|
$this->serviceManager = $this->createMock('Laminas\ServiceManager\ServiceManager'); |
|
|
|
|
|
|
42
|
|
|
$this->cli = $this->createPartialMock('Symfony\Component\Console\Application', ['run']); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$this |
|
45
|
|
|
->serviceManager |
|
46
|
|
|
->expects($this->any()) |
|
47
|
|
|
->method('get') |
|
48
|
|
|
->with('doctrine.cli') |
|
49
|
|
|
->will($this->returnValue($this->cli)); |
|
50
|
|
|
|
|
51
|
|
|
$this |
|
52
|
|
|
->application |
|
53
|
|
|
->expects($this->any()) |
|
54
|
|
|
->method('getServiceManager') |
|
55
|
|
|
->will($this->returnValue($this->serviceManager)); |
|
56
|
|
|
|
|
57
|
|
|
$this |
|
58
|
|
|
->event |
|
59
|
|
|
->expects($this->any()) |
|
60
|
|
|
->method('getTarget') |
|
61
|
|
|
->will($this->returnValue($this->application)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @covers \DoctrineModule\Module::getConfig |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testGetConfig() : void |
|
68
|
|
|
{ |
|
69
|
|
|
$module = new Module(); |
|
70
|
|
|
|
|
71
|
|
|
$config = $module->getConfig(); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertIsArray($config); |
|
74
|
|
|
$this->assertArrayHasKey('doctrine', $config); |
|
|
|
|
|
|
75
|
|
|
$this->assertArrayHasKey('doctrine_factories', $config); |
|
|
|
|
|
|
76
|
|
|
$this->assertArrayHasKey('service_manager', $config); |
|
|
|
|
|
|
77
|
|
|
$this->assertArrayHasKey('controllers', $config); |
|
|
|
|
|
|
78
|
|
|
$this->assertArrayHasKey('route_manager', $config); |
|
|
|
|
|
|
79
|
|
|
$this->assertArrayHasKey('console', $config); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
$this->assertSame($config, unserialize(serialize($config))); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Should display the help message in plain message |
|
86
|
|
|
* |
|
87
|
|
|
* @covers \DoctrineModule\Module::getConsoleUsage |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testGetConsoleUsage() : void |
|
90
|
|
|
{ |
|
91
|
|
|
$this |
|
|
|
|
|
|
92
|
|
|
->cli |
|
93
|
|
|
->expects($this->once()) |
|
94
|
|
|
->method('run') |
|
95
|
|
|
->with( |
|
96
|
|
|
$this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), |
|
97
|
|
|
$this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface') |
|
98
|
|
|
) |
|
99
|
|
|
->will($this->returnCallback(static function (InputInterface $input, OutputInterface $output) : void { |
|
100
|
|
|
$output->write($input->getFirstArgument() . ' - TEST'); |
|
101
|
|
|
$output->write(' - More output'); |
|
102
|
|
|
})); |
|
103
|
|
|
|
|
104
|
|
|
$module = new Module(); |
|
105
|
|
|
|
|
106
|
|
|
$module->onBootstrap($this->event); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertSame( |
|
109
|
|
|
'list - TEST - More output', |
|
110
|
|
|
$module->getConsoleUsage($this->createMock('Laminas\Console\Adapter\AdapterInterface')) |
|
|
|
|
|
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..