aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJeremy <jeremy.benoist@gmail.com>2015-02-22 23:29:48 +0100
committerJeremy <jeremy.benoist@gmail.com>2015-02-22 23:29:48 +0100
commitc641baad0ec52198d77f2018c7bf8acdfe5957ce (patch)
tree7026acde83f5d38a9ad94d92f926d880aa233dbe /src/Wallabag
parent732c2ad8971f427ec196acfac53dad034cefdef4 (diff)
downloadwallabag-c641baad0ec52198d77f2018c7bf8acdfe5957ce.tar.gz
wallabag-c641baad0ec52198d77f2018c7bf8acdfe5957ce.tar.zst
wallabag-c641baad0ec52198d77f2018c7bf8acdfe5957ce.zip
More tests on the install command
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php219
1 files changed, 216 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
index a091d66f..64f6c329 100644
--- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
@@ -8,13 +8,13 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
8use Symfony\Component\Console\Tester\CommandTester; 8use Symfony\Component\Console\Tester\CommandTester;
9use Symfony\Component\Console\Input\ArrayInput; 9use Symfony\Component\Console\Input\ArrayInput;
10use Symfony\Component\Console\Output\NullOutput; 10use Symfony\Component\Console\Output\NullOutput;
11use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
12use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
11 13
12class InstallCommandTest extends WallabagTestCase 14class InstallCommandTest extends WallabagTestCase
13{ 15{
14 public function tearDown() 16 public static function tearDownAfterClass()
15 { 17 {
16 parent::tearDown();
17
18 $application = new Application(static::$kernel); 18 $application = new Application(static::$kernel);
19 $application->setAutoExit(false); 19 $application->setAutoExit(false);
20 20
@@ -58,4 +58,217 @@ class InstallCommandTest extends WallabagTestCase
58 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay()); 58 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
59 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); 59 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
60 } 60 }
61
62 public function testRunInstallCommandWithReset()
63 {
64 $this->container = static::$kernel->getContainer();
65
66 $application = new Application(static::$kernel);
67 $application->add(new InstallCommand());
68
69 $command = $application->find('wallabag:install');
70
71 // We mock the DialogHelper
72 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
73 ->disableOriginalConstructor()
74 ->getMock();
75 $dialog->expects($this->any())
76 ->method('ask')
77 ->will($this->returnValue('test'));
78 $dialog->expects($this->any())
79 ->method('askConfirmation')
80 ->will($this->returnValue(true));
81
82 // We override the standard helper with our mock
83 $command->getHelperSet()->set($dialog, 'dialog');
84
85 $tester = new CommandTester($command);
86 $tester->execute(array(
87 'command' => $command->getName(),
88 '--reset' => true,
89 ));
90
91 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
92 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
93 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
94 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
95
96 // we force to reset everything
97 $this->assertContains('Droping database, creating database and schema', $tester->getDisplay());
98 }
99
100 public function testRunInstallCommandWithDatabaseRemoved()
101 {
102 $this->container = static::$kernel->getContainer();
103
104 $application = new Application(static::$kernel);
105 $application->add(new InstallCommand());
106 $application->add(new DropDatabaseDoctrineCommand());
107
108 // drop database first, so the install command won't ask to reset things
109 $command = new DropDatabaseDoctrineCommand();
110 $command->setApplication($application);
111 $command->run(new ArrayInput(array(
112 'command' => 'doctrine:database:drop',
113 '--force' => true,
114 )), new NullOutput());
115
116 $command = $application->find('wallabag:install');
117
118 // We mock the DialogHelper
119 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
120 ->disableOriginalConstructor()
121 ->getMock();
122 $dialog->expects($this->any())
123 ->method('ask')
124 ->will($this->returnValue('test'));
125 $dialog->expects($this->any())
126 ->method('askConfirmation')
127 ->will($this->returnValue(true));
128
129 // We override the standard helper with our mock
130 $command->getHelperSet()->set($dialog, 'dialog');
131
132 $tester = new CommandTester($command);
133 $tester->execute(array(
134 'command' => $command->getName(),
135 ));
136
137 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
138 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
139 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
140 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
141
142 // the current database doesn't already exist
143 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
144 }
145
146 public function testRunInstallCommandChooseResetSchema()
147 {
148 $this->container = static::$kernel->getContainer();
149
150 $application = new Application(static::$kernel);
151 $application->add(new InstallCommand());
152
153 $command = $application->find('wallabag:install');
154
155 // We mock the DialogHelper
156 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
157 ->disableOriginalConstructor()
158 ->getMock();
159
160 $dialog->expects($this->exactly(3))
161 ->method('askConfirmation')
162 ->will($this->onConsecutiveCalls(
163 false, // don't want to reset the entire database
164 true, // do want to reset the schema
165 false // don't want to create a new user
166 ));
167
168 // We override the standard helper with our mock
169 $command->getHelperSet()->set($dialog, 'dialog');
170
171 $tester = new CommandTester($command);
172 $tester->execute(array(
173 'command' => $command->getName(),
174 ));
175
176 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
177 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
178 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
179 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
180
181 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
182 }
183
184 public function testRunInstallCommandChooseNothing()
185 {
186 $this->container = static::$kernel->getContainer();
187
188 $application = new Application(static::$kernel);
189 $application->add(new InstallCommand());
190 $application->add(new DropDatabaseDoctrineCommand());
191 $application->add(new CreateDatabaseDoctrineCommand());
192
193 // drop database first, so the install command won't ask to reset things
194 $command = new DropDatabaseDoctrineCommand();
195 $command->setApplication($application);
196 $command->run(new ArrayInput(array(
197 'command' => 'doctrine:database:drop',
198 '--force' => true,
199 )), new NullOutput());
200
201 $this->container->get('doctrine')->getManager()->getConnection()->close();
202
203 $command = new CreateDatabaseDoctrineCommand();
204 $command->setApplication($application);
205 $command->run(new ArrayInput(array(
206 'command' => 'doctrine:database:create',
207 '--env' => 'test',
208 )), new NullOutput());
209
210 $command = $application->find('wallabag:install');
211
212 // We mock the DialogHelper
213 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
214 ->disableOriginalConstructor()
215 ->getMock();
216
217 $dialog->expects($this->exactly(2))
218 ->method('askConfirmation')
219 ->will($this->onConsecutiveCalls(
220 false, // don't want to reset the entire database
221 false // don't want to create a new user
222 ));
223
224 // We override the standard helper with our mock
225 $command->getHelperSet()->set($dialog, 'dialog');
226
227 $tester = new CommandTester($command);
228 $tester->execute(array(
229 'command' => $command->getName(),
230 ));
231
232 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
233 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
234 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
235 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
236
237 $this->assertContains('Creating schema', $tester->getDisplay());
238 }
239
240 public function testRunInstallCommandNoInteraction()
241 {
242 $this->container = static::$kernel->getContainer();
243
244 $application = new Application(static::$kernel);
245 $application->add(new InstallCommand());
246
247 $command = $application->find('wallabag:install');
248
249 // We mock the DialogHelper
250 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
251 ->disableOriginalConstructor()
252 ->getMock();
253 $dialog->expects($this->any())
254 ->method('ask')
255 ->will($this->returnValue('test'));
256 $dialog->expects($this->any())
257 ->method('askConfirmation')
258 ->will($this->returnValue(true));
259
260 // We override the standard helper with our mock
261 $command->getHelperSet()->set($dialog, 'dialog');
262
263 $tester = new CommandTester($command);
264 $tester->execute(array(
265 'command' => $command->getName(),
266 '--no-interaction' => true,
267 ));
268
269 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
270 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
271 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
272 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
273 }
61} 274}