Skip to content

Commit

Permalink
optimize ScanExecutorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Jun 3, 2017
1 parent bfe7134 commit 68dfb45
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions tests/Service/Storage/ScanExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,69 @@
use Symfony\Component\Filesystem\Filesystem;
use AnimeDb\Bundle\CatalogBundle\Entity\Storage;

/**
* Test storage scanner.
*
* @author Peter Gribanov <[email protected]>
*/
class ScanExecutorTest extends \PHPUnit_Framework_TestCase
{
/**
* Test export.
* @var \PHPUnit_Framework_MockObject_MockObject|CommandExecutor
*/
public function testExport()
private $command;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|Filesystem
*/
private $fs;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|Storage
*/
private $storage;

protected function setUp()
{
$storage_id = 5;
/* @var $command \PHPUnit_Framework_MockObject_MockObject|CommandExecutor */
$command = $this
$this->command = $this
->getMockBuilder('\AnimeDb\Bundle\AppBundle\Service\CommandExecutor')
->disableOriginalConstructor()
->getMock();
/* @var $fs \PHPUnit_Framework_MockObject_MockObject|Filesystem */
$fs = $this->getMock('\Symfony\Component\Filesystem\Filesystem');
/* @var $storage \PHPUnit_Framework_MockObject_MockObject|Storage */
$storage = $this->getMock('\AnimeDb\Bundle\CatalogBundle\Entity\Storage');
->getMock()
;
$this->fs = $this->getMock('\Symfony\Component\Filesystem\Filesystem');
$this->storage = $this->getMock('\AnimeDb\Bundle\CatalogBundle\Entity\Storage');
}

public function testExport()
{
$storage_id = 5;
$output = '/output/%s.log';
$progress = '/progress/%s.log';
$pattern = 'php app/console animedb:scan-storage --no-ansi --force --export=%s %s >%s 2>&1';

$storage
$this->storage
->expects($this->atLeastOnce())
->method('getId')
->will($this->returnValue($storage_id));
$fs

$this->fs
->expects($this->once())
->method('mkdir')
->with([dirname($output), dirname($progress)], 0755);
$fs
$this->fs
->expects($this->once())
->method('remove')
->with([
sprintf($output, $storage_id),
sprintf($progress, $storage_id),
]);
$command

$this->command
->expects($this->once())
->method('send')
->with(sprintf(
$pattern,
sprintf($progress, $storage->getId()),
$storage->getId(),
sprintf($output, $storage->getId())
sprintf($progress, $storage_id),
$storage_id,
sprintf($output, $storage_id)
));

$scanner = new ScanExecutor($command, $fs, $output, $progress);
$scanner->export($storage);
$scanner = new ScanExecutor($this->command, $this->fs, $output, $progress);
$scanner->export($this->storage);
}
}

0 comments on commit 68dfb45

Please sign in to comment.