-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfe7134
commit 68dfb45
Showing
1 changed file
with
35 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} |