aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php45
-rw-r--r--src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php72
2 files changed, 54 insertions, 63 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 6ebbd93c..808baaf6 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -8,6 +8,9 @@ use Symfony\Component\Console\Input\InputOption;
8use Symfony\Component\Console\Input\ArrayInput; 8use Symfony\Component\Console\Input\ArrayInput;
9use Symfony\Component\Console\Output\OutputInterface; 9use Symfony\Component\Console\Output\OutputInterface;
10use Symfony\Component\Console\Output\NullOutput; 10use Symfony\Component\Console\Output\NullOutput;
11use Symfony\Component\Console\Question\Question;
12use Symfony\Component\Console\Question\ConfirmationQuestion;
13use Symfony\Component\Console\Helper\Table;
11use Wallabag\UserBundle\Entity\User; 14use Wallabag\UserBundle\Entity\User;
12use Wallabag\CoreBundle\Entity\Config; 15use Wallabag\CoreBundle\Entity\Config;
13 16
@@ -85,10 +88,11 @@ class InstallCommand extends ContainerAwareCommand
85 } 88 }
86 $rows[] = array($label, $status, $help); 89 $rows[] = array($label, $status, $help);
87 90
88 $this->getHelper('table') 91 $table = new Table($this->defaultOutput);
92 $table
89 ->setHeaders(array('Checked', 'Status', 'Recommendation')) 93 ->setHeaders(array('Checked', 'Status', 'Recommendation'))
90 ->setRows($rows) 94 ->setRows($rows)
91 ->render($this->defaultOutput); 95 ->render();
92 96
93 if (!$fulfilled) { 97 if (!$fulfilled) {
94 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); 98 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
@@ -130,9 +134,10 @@ class InstallCommand extends ContainerAwareCommand
130 return $this; 134 return $this;
131 } 135 }
132 136
133 $dialog = $this->getHelper('dialog'); 137 $questionHelper = $this->getHelper('question');
138 $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false);
134 139
135 if ($dialog->askConfirmation($this->defaultOutput, '<question>It appears that your database already exists. Would you like to reset it? (y/N)</question> ', false)) { 140 if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) {
136 $this->defaultOutput->writeln('Droping database, creating database and schema'); 141 $this->defaultOutput->writeln('Droping database, creating database and schema');
137 142
138 $this 143 $this
@@ -141,7 +146,8 @@ class InstallCommand extends ContainerAwareCommand
141 ->runCommand('doctrine:schema:create') 146 ->runCommand('doctrine:schema:create')
142 ; 147 ;
143 } elseif ($this->isSchemaPresent()) { 148 } elseif ($this->isSchemaPresent()) {
144 if ($dialog->askConfirmation($this->defaultOutput, '<question>Seems like your database contains schema. Do you want to reset it? (y/N)</question> ', false)) { 149 $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false);
150 if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) {
145 $this->defaultOutput->writeln('Droping schema and creating schema'); 151 $this->defaultOutput->writeln('Droping schema and creating schema');
146 152
147 $this 153 $this
@@ -160,17 +166,6 @@ class InstallCommand extends ContainerAwareCommand
160 $this->defaultOutput->writeln('Clearing the cache'); 166 $this->defaultOutput->writeln('Clearing the cache');
161 $this->runCommand('cache:clear'); 167 $this->runCommand('cache:clear');
162 168
163 /*
164 if ($this->getHelperSet()->get('dialog')->askConfirmation($this->defaultOutput, '<question>Load fixtures (Y/N)?</question>', false)) {
165 $doctrineConfig = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection()->getConfiguration();
166 $logger = $doctrineConfig->getSQLLogger();
167 // speed up fixture load
168 $doctrineConfig->setSQLLogger(null);
169 $this->runCommand('doctrine:fixtures:load');
170 $doctrineConfig->setSQLLogger($logger);
171 }
172 */
173
174 $this->defaultOutput->writeln(''); 169 $this->defaultOutput->writeln('');
175 170
176 return $this; 171 return $this;
@@ -180,9 +175,10 @@ class InstallCommand extends ContainerAwareCommand
180 { 175 {
181 $this->defaultOutput->writeln('<info><comment>Step 3 of 4.</comment> Administration setup.</info>'); 176 $this->defaultOutput->writeln('<info><comment>Step 3 of 4.</comment> Administration setup.</info>');
182 177
183 $dialog = $this->getHelperSet()->get('dialog'); 178 $questionHelper = $this->getHelperSet()->get('question');
179 $question = new ConfirmationQuestion('Would you like to create a new user ? (y/N)', false);
184 180
185 if (false === $dialog->askConfirmation($this->defaultOutput, '<question>Would you like to create a new user ? (y/N)</question>', true)) { 181 if (!$questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) {
186 return $this; 182 return $this;
187 } 183 }
188 184
@@ -190,9 +186,16 @@ class InstallCommand extends ContainerAwareCommand
190 186
191 $userManager = $this->getContainer()->get('fos_user.user_manager'); 187 $userManager = $this->getContainer()->get('fos_user.user_manager');
192 $user = $userManager->createUser(); 188 $user = $userManager->createUser();
193 $user->setUsername($dialog->ask($this->defaultOutput, '<question>Username</question> <comment>(default: wallabag)</comment> :', 'wallabag')); 189
194 $user->setPlainPassword($dialog->ask($this->defaultOutput, '<question>Password</question> <comment>(default: wallabag)</comment> :', 'wallabag')); 190 $question = new Question('Username (default: wallabag) :', 'wallabag');
195 $user->setEmail($dialog->ask($this->defaultOutput, '<question>Email:</question>', '')); 191 $user->setUsername($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
192
193 $question = new Question('Password (default: wallabag) :', 'wallabag');
194 $user->setPlainPassword($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
195
196 $question = new Question('Email:', '');
197 $user->setEmail($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
198
196 $user->setEnabled(true); 199 $user->setEnabled(true);
197 200
198 $em->persist($user); 201 $em->persist($user);
diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
index 24910e60..e98dd202 100644
--- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
@@ -35,19 +35,16 @@ class InstallCommandTest extends WallabagCoreTestCase
35 35
36 $command = $application->find('wallabag:install'); 36 $command = $application->find('wallabag:install');
37 37
38 // We mock the DialogHelper 38 // We mock the QuestionHelper
39 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') 39 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
40 ->disableOriginalConstructor() 40 ->disableOriginalConstructor()
41 ->getMock(); 41 ->getMock();
42 $dialog->expects($this->any()) 42 $question->expects($this->any())
43 ->method('ask') 43 ->method('ask')
44 ->will($this->returnValue('test_'.uniqid('', true))); 44 ->will($this->returnValue('yes_'.uniqid('', true)));
45 $dialog->expects($this->any())
46 ->method('askConfirmation')
47 ->will($this->returnValue(true));
48 45
49 // We override the standard helper with our mock 46 // We override the standard helper with our mock
50 $command->getHelperSet()->set($dialog, 'dialog'); 47 $command->getHelperSet()->set($question, 'question');
51 48
52 $tester = new CommandTester($command); 49 $tester = new CommandTester($command);
53 $tester->execute(array( 50 $tester->execute(array(
@@ -69,19 +66,16 @@ class InstallCommandTest extends WallabagCoreTestCase
69 66
70 $command = $application->find('wallabag:install'); 67 $command = $application->find('wallabag:install');
71 68
72 // We mock the DialogHelper 69 // We mock the QuestionHelper
73 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') 70 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
74 ->disableOriginalConstructor() 71 ->disableOriginalConstructor()
75 ->getMock(); 72 ->getMock();
76 $dialog->expects($this->any()) 73 $question->expects($this->any())
77 ->method('ask') 74 ->method('ask')
78 ->will($this->returnValue('test_'.uniqid('', true))); 75 ->will($this->returnValue('yes_'.uniqid('', true)));
79 $dialog->expects($this->any())
80 ->method('askConfirmation')
81 ->will($this->returnValue(true));
82 76
83 // We override the standard helper with our mock 77 // We override the standard helper with our mock
84 $command->getHelperSet()->set($dialog, 'dialog'); 78 $command->getHelperSet()->set($question, 'question');
85 79
86 $tester = new CommandTester($command); 80 $tester = new CommandTester($command);
87 $tester->execute(array( 81 $tester->execute(array(
@@ -119,19 +113,16 @@ class InstallCommandTest extends WallabagCoreTestCase
119 113
120 $command = $application->find('wallabag:install'); 114 $command = $application->find('wallabag:install');
121 115
122 // We mock the DialogHelper 116 // We mock the QuestionHelper
123 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') 117 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
124 ->disableOriginalConstructor() 118 ->disableOriginalConstructor()
125 ->getMock(); 119 ->getMock();
126 $dialog->expects($this->any()) 120 $question->expects($this->any())
127 ->method('ask') 121 ->method('ask')
128 ->will($this->returnValue('test_'.uniqid('', true))); 122 ->will($this->returnValue('yes_'.uniqid('', true)));
129 $dialog->expects($this->any())
130 ->method('askConfirmation')
131 ->will($this->returnValue(true));
132 123
133 // We override the standard helper with our mock 124 // We override the standard helper with our mock
134 $command->getHelperSet()->set($dialog, 'dialog'); 125 $command->getHelperSet()->set($question, 'question');
135 126
136 $tester = new CommandTester($command); 127 $tester = new CommandTester($command);
137 $tester->execute(array( 128 $tester->execute(array(
@@ -156,13 +147,13 @@ class InstallCommandTest extends WallabagCoreTestCase
156 147
157 $command = $application->find('wallabag:install'); 148 $command = $application->find('wallabag:install');
158 149
159 // We mock the DialogHelper 150 // We mock the QuestionHelper
160 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') 151 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
161 ->disableOriginalConstructor() 152 ->disableOriginalConstructor()
162 ->getMock(); 153 ->getMock();
163 154
164 $dialog->expects($this->exactly(3)) 155 $question->expects($this->exactly(3))
165 ->method('askConfirmation') 156 ->method('ask')
166 ->will($this->onConsecutiveCalls( 157 ->will($this->onConsecutiveCalls(
167 false, // don't want to reset the entire database 158 false, // don't want to reset the entire database
168 true, // do want to reset the schema 159 true, // do want to reset the schema
@@ -170,7 +161,7 @@ class InstallCommandTest extends WallabagCoreTestCase
170 )); 161 ));
171 162
172 // We override the standard helper with our mock 163 // We override the standard helper with our mock
173 $command->getHelperSet()->set($dialog, 'dialog'); 164 $command->getHelperSet()->set($question, 'question');
174 165
175 $tester = new CommandTester($command); 166 $tester = new CommandTester($command);
176 $tester->execute(array( 167 $tester->execute(array(
@@ -216,20 +207,20 @@ class InstallCommandTest extends WallabagCoreTestCase
216 207
217 $command = $application->find('wallabag:install'); 208 $command = $application->find('wallabag:install');
218 209
219 // We mock the DialogHelper 210 // We mock the QuestionHelper
220 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') 211 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
221 ->disableOriginalConstructor() 212 ->disableOriginalConstructor()
222 ->getMock(); 213 ->getMock();
223 214
224 $dialog->expects($this->exactly(2)) 215 $question->expects($this->exactly(2))
225 ->method('askConfirmation') 216 ->method('ask')
226 ->will($this->onConsecutiveCalls( 217 ->will($this->onConsecutiveCalls(
227 false, // don't want to reset the entire database 218 false, // don't want to reset the entire database
228 false // don't want to create a new user 219 false // don't want to create a new user
229 )); 220 ));
230 221
231 // We override the standard helper with our mock 222 // We override the standard helper with our mock
232 $command->getHelperSet()->set($dialog, 'dialog'); 223 $command->getHelperSet()->set($question, 'question');
233 224
234 $tester = new CommandTester($command); 225 $tester = new CommandTester($command);
235 $tester->execute(array( 226 $tester->execute(array(
@@ -253,19 +244,16 @@ class InstallCommandTest extends WallabagCoreTestCase
253 244
254 $command = $application->find('wallabag:install'); 245 $command = $application->find('wallabag:install');
255 246
256 // We mock the DialogHelper 247 // We mock the QuestionHelper
257 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') 248 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
258 ->disableOriginalConstructor() 249 ->disableOriginalConstructor()
259 ->getMock(); 250 ->getMock();
260 $dialog->expects($this->any()) 251 $question->expects($this->any())
261 ->method('ask') 252 ->method('ask')
262 ->will($this->returnValue('test_'.uniqid('', true))); 253 ->will($this->returnValue('yes_'.uniqid('', true)));
263 $dialog->expects($this->any())
264 ->method('askConfirmation')
265 ->will($this->returnValue(true));
266 254
267 // We override the standard helper with our mock 255 // We override the standard helper with our mock
268 $command->getHelperSet()->set($dialog, 'dialog'); 256 $command->getHelperSet()->set($question, 'question');
269 257
270 $tester = new CommandTester($command); 258 $tester = new CommandTester($command);
271 $tester->execute(array( 259 $tester->execute(array(