Skip to content

Commit 7d47bf3

Browse files
committed
Adding test for download command interaction
1 parent b98ec64 commit 7d47bf3

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

test/MageDownload/Command/DownloadCommandTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
use MageDownload\Command\DownloadCommand;
1818
use MageDownload\Command\PHPUnit\TestCase;
19+
use Symfony\Component\Console\Helper\DialogHelper;
20+
use Symfony\Component\Console\Helper\HelperSet;
1921
use Symfony\Component\Console\Tester\CommandTester;
22+
use Symfony\Component\Console\Input\ArgvInput;
2023

2124
/**
2225
* Test the file command
@@ -162,4 +165,37 @@ public function testCommandFolderDestination()
162165
$this->assertContains('Complete', $commandTester->getDisplay());
163166
$this->assertFileExists('/tmp/PATCH_SUPEE-6788_CE_1.9.2.1_v1.sh');
164167
}
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+
}
165201
}

0 commit comments

Comments
 (0)