aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-30 12:47:25 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-05-30 12:47:28 +0200
commit26650fdbf8af8d716e712e9c9c8474b42f90722d (patch)
treebc2a36584477519c5302015a2039ebfe1218dea6 /tests
parent5fe65baee5910c887ba148b1163a1a53654dc324 (diff)
downloadwallabag-26650fdbf8af8d716e712e9c9c8474b42f90722d.tar.gz
wallabag-26650fdbf8af8d716e712e9c9c8474b42f90722d.tar.zst
wallabag-26650fdbf8af8d716e712e9c9c8474b42f90722d.zip
Use a better way to set input for command
Actually use the correct to way handle that http://symfony.com/doc/current/components/console/helpers/questionhelper.html#testing-a-command-that-expects-input
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php106
1 files changed, 30 insertions, 76 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 122a87d4..71c2ffc6 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -67,18 +67,14 @@ class InstallCommandTest extends WallabagCoreTestCase
67 67
68 $command = $application->find('wallabag:install'); 68 $command = $application->find('wallabag:install');
69 69
70 // We mock the QuestionHelper
71 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
72 ->disableOriginalConstructor()
73 ->getMock();
74 $question->expects($this->any())
75 ->method('ask')
76 ->will($this->returnValue('yes_'.uniqid('', true)));
77
78 // We override the standard helper with our mock
79 $command->getHelperSet()->set($question, 'question');
80
81 $tester = new CommandTester($command); 70 $tester = new CommandTester($command);
71 $tester->setInputs([
72 'y', // dropping database
73 'y', // create super admin
74 'username_'.uniqid('', true), // username
75 'password_'.uniqid('', true), // password
76 'email_'.uniqid('', true).'@wallabag.it', // email
77 ]);
82 $tester->execute([ 78 $tester->execute([
83 'command' => $command->getName(), 79 'command' => $command->getName(),
84 ]); 80 ]);
@@ -97,18 +93,13 @@ class InstallCommandTest extends WallabagCoreTestCase
97 93
98 $command = $application->find('wallabag:install'); 94 $command = $application->find('wallabag:install');
99 95
100 // We mock the QuestionHelper
101 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
102 ->disableOriginalConstructor()
103 ->getMock();
104 $question->expects($this->any())
105 ->method('ask')
106 ->will($this->returnValue('yes_'.uniqid('', true)));
107
108 // We override the standard helper with our mock
109 $command->getHelperSet()->set($question, 'question');
110
111 $tester = new CommandTester($command); 96 $tester = new CommandTester($command);
97 $tester->setInputs([
98 'y', // create super admin
99 'username_'.uniqid('', true), // username
100 'password_'.uniqid('', true), // password
101 'email_'.uniqid('', true).'@wallabag.it', // email
102 ]);
112 $tester->execute([ 103 $tester->execute([
113 'command' => $command->getName(), 104 'command' => $command->getName(),
114 '--reset' => true, 105 '--reset' => true,
@@ -150,18 +141,13 @@ class InstallCommandTest extends WallabagCoreTestCase
150 141
151 $command = $application->find('wallabag:install'); 142 $command = $application->find('wallabag:install');
152 143
153 // We mock the QuestionHelper
154 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
155 ->disableOriginalConstructor()
156 ->getMock();
157 $question->expects($this->any())
158 ->method('ask')
159 ->will($this->returnValue('yes_'.uniqid('', true)));
160
161 // We override the standard helper with our mock
162 $command->getHelperSet()->set($question, 'question');
163
164 $tester = new CommandTester($command); 144 $tester = new CommandTester($command);
145 $tester->setInputs([
146 'y', // create super admin
147 'username_'.uniqid('', true), // username
148 'password_'.uniqid('', true), // password
149 'email_'.uniqid('', true).'@wallabag.it', // email
150 ]);
165 $tester->execute([ 151 $tester->execute([
166 'command' => $command->getName(), 152 'command' => $command->getName(),
167 ]); 153 ]);
@@ -183,23 +169,12 @@ class InstallCommandTest extends WallabagCoreTestCase
183 169
184 $command = $application->find('wallabag:install'); 170 $command = $application->find('wallabag:install');
185 171
186 // We mock the QuestionHelper
187 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
188 ->disableOriginalConstructor()
189 ->getMock();
190
191 $question->expects($this->exactly(3))
192 ->method('ask')
193 ->will($this->onConsecutiveCalls(
194 false, // don't want to reset the entire database
195 true, // do want to reset the schema
196 false // don't want to create a new user
197 ));
198
199 // We override the standard helper with our mock
200 $command->getHelperSet()->set($question, 'question');
201
202 $tester = new CommandTester($command); 172 $tester = new CommandTester($command);
173 $tester->setInputs([
174 'n', // don't want to reset the entire database
175 'y', // do want to reset the schema
176 'n', // don't want to create a new user
177 ]);
203 $tester->execute([ 178 $tester->execute([
204 'command' => $command->getName(), 179 'command' => $command->getName(),
205 ]); 180 ]);
@@ -239,22 +214,11 @@ class InstallCommandTest extends WallabagCoreTestCase
239 214
240 $command = $application->find('wallabag:install'); 215 $command = $application->find('wallabag:install');
241 216
242 // We mock the QuestionHelper
243 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
244 ->disableOriginalConstructor()
245 ->getMock();
246
247 $question->expects($this->exactly(2))
248 ->method('ask')
249 ->will($this->onConsecutiveCalls(
250 false, // don't want to reset the entire database
251 false // don't want to create a new user
252 ));
253
254 // We override the standard helper with our mock
255 $command->getHelperSet()->set($question, 'question');
256
257 $tester = new CommandTester($command); 217 $tester = new CommandTester($command);
218 $tester->setInputs([
219 'n', // don't want to reset the entire database
220 'n', // don't want to create a new user
221 ]);
258 $tester->execute([ 222 $tester->execute([
259 'command' => $command->getName(), 223 'command' => $command->getName(),
260 ]); 224 ]);
@@ -275,21 +239,11 @@ class InstallCommandTest extends WallabagCoreTestCase
275 239
276 $command = $application->find('wallabag:install'); 240 $command = $application->find('wallabag:install');
277 241
278 // We mock the QuestionHelper
279 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
280 ->disableOriginalConstructor()
281 ->getMock();
282 $question->expects($this->any())
283 ->method('ask')
284 ->will($this->returnValue('yes_'.uniqid('', true)));
285
286 // We override the standard helper with our mock
287 $command->getHelperSet()->set($question, 'question');
288
289 $tester = new CommandTester($command); 242 $tester = new CommandTester($command);
290 $tester->execute([ 243 $tester->execute([
291 'command' => $command->getName(), 244 'command' => $command->getName(),
292 '--no-interaction' => true, 245 ], [
246 'interactive' => false,
293 ]); 247 ]);
294 248
295 $this->assertContains('Checking system requirements.', $tester->getDisplay()); 249 $this->assertContains('Checking system requirements.', $tester->getDisplay());