]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\Command; | |
4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | |
6 | use Wallabag\CoreBundle\Command\InstallCommand; | |
7 | use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock; | |
8 | use Symfony\Bundle\FrameworkBundle\Console\Application; | |
9 | use Symfony\Component\Console\Tester\CommandTester; | |
10 | use Symfony\Component\Console\Input\ArrayInput; | |
11 | use Symfony\Component\Console\Output\NullOutput; | |
12 | use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; | |
13 | use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; | |
14 | ||
15 | class InstallCommandTest extends WallabagCoreTestCase | |
16 | { | |
17 | public static function tearDownAfterClass() | |
18 | { | |
19 | $application = new Application(static::$kernel); | |
20 | $application->setAutoExit(false); | |
21 | ||
22 | $code = $application->run(new ArrayInput(array( | |
23 | 'command' => 'doctrine:fixtures:load', | |
24 | '--no-interaction' => true, | |
25 | '--env' => 'test', | |
26 | )), new NullOutput()); | |
27 | } | |
28 | ||
29 | public function testRunInstallCommand() | |
30 | { | |
31 | $this->container = static::$kernel->getContainer(); | |
32 | ||
33 | $application = new Application(static::$kernel); | |
34 | $application->add(new InstallCommandMock()); | |
35 | ||
36 | $command = $application->find('wallabag:install'); | |
37 | ||
38 | // We mock the QuestionHelper | |
39 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | |
40 | ->disableOriginalConstructor() | |
41 | ->getMock(); | |
42 | $question->expects($this->any()) | |
43 | ->method('ask') | |
44 | ->will($this->returnValue('yes_'.uniqid('', true))); | |
45 | ||
46 | // We override the standard helper with our mock | |
47 | $command->getHelperSet()->set($question, 'question'); | |
48 | ||
49 | $tester = new CommandTester($command); | |
50 | $tester->execute(array( | |
51 | 'command' => $command->getName(), | |
52 | )); | |
53 | ||
54 | $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); | |
55 | $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay()); | |
56 | $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); | |
57 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | |
58 | } | |
59 | ||
60 | public function testRunInstallCommandWithReset() | |
61 | { | |
62 | $this->container = static::$kernel->getContainer(); | |
63 | ||
64 | $application = new Application(static::$kernel); | |
65 | $application->add(new InstallCommandMock()); | |
66 | ||
67 | $command = $application->find('wallabag:install'); | |
68 | ||
69 | // We mock the QuestionHelper | |
70 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | |
71 | ->disableOriginalConstructor() | |
72 | ->getMock(); | |
73 | $question->expects($this->any()) | |
74 | ->method('ask') | |
75 | ->will($this->returnValue('yes_'.uniqid('', true))); | |
76 | ||
77 | // We override the standard helper with our mock | |
78 | $command->getHelperSet()->set($question, 'question'); | |
79 | ||
80 | $tester = new CommandTester($command); | |
81 | $tester->execute(array( | |
82 | 'command' => $command->getName(), | |
83 | '--reset' => true, | |
84 | )); | |
85 | ||
86 | $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); | |
87 | $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay()); | |
88 | $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); | |
89 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | |
90 | ||
91 | // we force to reset everything | |
92 | $this->assertContains('Droping database, creating database and schema', $tester->getDisplay()); | |
93 | } | |
94 | ||
95 | /** | |
96 | * @group command-doctrine | |
97 | */ | |
98 | public function testRunInstallCommandWithDatabaseRemoved() | |
99 | { | |
100 | $this->container = static::$kernel->getContainer(); | |
101 | ||
102 | $application = new Application(static::$kernel); | |
103 | $application->add(new InstallCommand()); | |
104 | $application->add(new DropDatabaseDoctrineCommand()); | |
105 | ||
106 | // drop database first, so the install command won't ask to reset things | |
107 | $command = new DropDatabaseDoctrineCommand(); | |
108 | $command->setApplication($application); | |
109 | $command->run(new ArrayInput(array( | |
110 | 'command' => 'doctrine:database:drop', | |
111 | '--force' => true, | |
112 | )), new NullOutput()); | |
113 | ||
114 | $command = $application->find('wallabag:install'); | |
115 | ||
116 | // We mock the QuestionHelper | |
117 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | |
118 | ->disableOriginalConstructor() | |
119 | ->getMock(); | |
120 | $question->expects($this->any()) | |
121 | ->method('ask') | |
122 | ->will($this->returnValue('yes_'.uniqid('', true))); | |
123 | ||
124 | // We override the standard helper with our mock | |
125 | $command->getHelperSet()->set($question, 'question'); | |
126 | ||
127 | $tester = new CommandTester($command); | |
128 | $tester->execute(array( | |
129 | 'command' => $command->getName(), | |
130 | )); | |
131 | ||
132 | $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); | |
133 | $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay()); | |
134 | $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); | |
135 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | |
136 | ||
137 | // the current database doesn't already exist | |
138 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); | |
139 | } | |
140 | ||
141 | public function testRunInstallCommandChooseResetSchema() | |
142 | { | |
143 | $this->container = static::$kernel->getContainer(); | |
144 | ||
145 | $application = new Application(static::$kernel); | |
146 | $application->add(new InstallCommandMock()); | |
147 | ||
148 | $command = $application->find('wallabag:install'); | |
149 | ||
150 | // We mock the QuestionHelper | |
151 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | |
152 | ->disableOriginalConstructor() | |
153 | ->getMock(); | |
154 | ||
155 | $question->expects($this->exactly(3)) | |
156 | ->method('ask') | |
157 | ->will($this->onConsecutiveCalls( | |
158 | false, // don't want to reset the entire database | |
159 | true, // do want to reset the schema | |
160 | false // don't want to create a new user | |
161 | )); | |
162 | ||
163 | // We override the standard helper with our mock | |
164 | $command->getHelperSet()->set($question, 'question'); | |
165 | ||
166 | $tester = new CommandTester($command); | |
167 | $tester->execute(array( | |
168 | 'command' => $command->getName(), | |
169 | )); | |
170 | ||
171 | $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); | |
172 | $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay()); | |
173 | $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); | |
174 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | |
175 | ||
176 | $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); | |
177 | } | |
178 | ||
179 | /** | |
180 | * @group command-doctrine | |
181 | */ | |
182 | public function testRunInstallCommandChooseNothing() | |
183 | { | |
184 | $this->container = static::$kernel->getContainer(); | |
185 | ||
186 | $application = new Application(static::$kernel); | |
187 | $application->add(new InstallCommand()); | |
188 | $application->add(new DropDatabaseDoctrineCommand()); | |
189 | $application->add(new CreateDatabaseDoctrineCommand()); | |
190 | ||
191 | // drop database first, so the install command won't ask to reset things | |
192 | $command = new DropDatabaseDoctrineCommand(); | |
193 | $command->setApplication($application); | |
194 | $command->run(new ArrayInput(array( | |
195 | 'command' => 'doctrine:database:drop', | |
196 | '--force' => true, | |
197 | )), new NullOutput()); | |
198 | ||
199 | $this->container->get('doctrine')->getManager()->getConnection()->close(); | |
200 | ||
201 | $command = new CreateDatabaseDoctrineCommand(); | |
202 | $command->setApplication($application); | |
203 | $command->run(new ArrayInput(array( | |
204 | 'command' => 'doctrine:database:create', | |
205 | '--env' => 'test', | |
206 | )), new NullOutput()); | |
207 | ||
208 | $command = $application->find('wallabag:install'); | |
209 | ||
210 | // We mock the QuestionHelper | |
211 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | |
212 | ->disableOriginalConstructor() | |
213 | ->getMock(); | |
214 | ||
215 | $question->expects($this->exactly(2)) | |
216 | ->method('ask') | |
217 | ->will($this->onConsecutiveCalls( | |
218 | false, // don't want to reset the entire database | |
219 | false // don't want to create a new user | |
220 | )); | |
221 | ||
222 | // We override the standard helper with our mock | |
223 | $command->getHelperSet()->set($question, 'question'); | |
224 | ||
225 | $tester = new CommandTester($command); | |
226 | $tester->execute(array( | |
227 | 'command' => $command->getName(), | |
228 | )); | |
229 | ||
230 | $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); | |
231 | $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay()); | |
232 | $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); | |
233 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | |
234 | ||
235 | $this->assertContains('Creating schema', $tester->getDisplay()); | |
236 | } | |
237 | ||
238 | public function testRunInstallCommandNoInteraction() | |
239 | { | |
240 | $this->container = static::$kernel->getContainer(); | |
241 | ||
242 | $application = new Application(static::$kernel); | |
243 | $application->add(new InstallCommandMock()); | |
244 | ||
245 | $command = $application->find('wallabag:install'); | |
246 | ||
247 | // We mock the QuestionHelper | |
248 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | |
249 | ->disableOriginalConstructor() | |
250 | ->getMock(); | |
251 | $question->expects($this->any()) | |
252 | ->method('ask') | |
253 | ->will($this->returnValue('yes_'.uniqid('', true))); | |
254 | ||
255 | // We override the standard helper with our mock | |
256 | $command->getHelperSet()->set($question, 'question'); | |
257 | ||
258 | $tester = new CommandTester($command); | |
259 | $tester->execute(array( | |
260 | 'command' => $command->getName(), | |
261 | '--no-interaction' => true, | |
262 | )); | |
263 | ||
264 | $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay()); | |
265 | $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay()); | |
266 | $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); | |
267 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | |
268 | } | |
269 | } |