|
16 | 16 |
|
17 | 17 | use MageDownload\Command\DownloadCommand; |
18 | 18 | use MageDownload\Command\PHPUnit\TestCase; |
| 19 | +use Symfony\Component\Console\Helper\DialogHelper; |
| 20 | +use Symfony\Component\Console\Helper\HelperSet; |
19 | 21 | use Symfony\Component\Console\Tester\CommandTester; |
| 22 | +use Symfony\Component\Console\Input\ArgvInput; |
20 | 23 |
|
21 | 24 | /** |
22 | 25 | * Test the file command |
@@ -162,4 +165,37 @@ public function testCommandFolderDestination() |
162 | 165 | $this->assertContains('Complete', $commandTester->getDisplay()); |
163 | 166 | $this->assertFileExists('/tmp/PATCH_SUPEE-6788_CE_1.9.2.1_v1.sh'); |
164 | 167 | } |
| 168 | + |
| 169 | + /** |
| 170 | + * Test downloading using prompts |
| 171 | + * |
| 172 | + * @return void |
| 173 | + */ |
| 174 | + public function testCommandWithPrompts() |
| 175 | + { |
| 176 | + $command = $this->getApplication()->find(DownloadCommand::NAME); |
| 177 | + $command->setHelperSet(new HelperSet([new DialogHelper])); |
| 178 | + $commandTester = new CommandTester($command); |
| 179 | + $command->getHelper('dialog')->setInputStream($this->getInputStream("1\n0\n0\n")); |
| 180 | + $result = $commandTester->execute(array( |
| 181 | + 'command' => DownloadCommand::NAME, |
| 182 | + ), array('interactive' => new ArgvInput)); |
| 183 | + $this->assertEquals(0, $result); |
| 184 | + $this->assertContains('Complete', $commandTester->getDisplay()); |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Send prompts to PHP |
| 189 | + * |
| 190 | + * @param sring $input |
| 191 | + * |
| 192 | + * @return resource |
| 193 | + */ |
| 194 | + protected function getInputStream($input) |
| 195 | + { |
| 196 | + $stream = fopen('php://memory', 'r+', false); |
| 197 | + fputs($stream, $input); |
| 198 | + rewind($stream); |
| 199 | + return $stream; |
| 200 | + } |
165 | 201 | } |
0 commit comments