Skip to content

Commit

Permalink
call ->info() on LocalFileStorage if used for writing (i.e. file does…
Browse files Browse the repository at this point in the history
… not exists)
  • Loading branch information
mathielen committed Aug 5, 2015
1 parent eb22350 commit 1a7aa48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Mathielen/ImportEngine/Storage/LocalFileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ public function getHash()
public function info()
{
if (!isset($this->info)) {
$fileExists = $this->file->isReadable();
$this->info = new StorageInfo(array(
'name' => $this->file->getFilename(),
'hash' => $this->getHash(),
'hash' => $fileExists?$this->getHash():null,
'format' => $this->getFormat(),
'size' => $this->file->getSize(),
'count' => count($this->reader())
'size' => $fileExists?$this->file->getSize():0,
'count' => $fileExists?count($this->reader()):0
));
}

Expand Down
9 changes: 9 additions & 0 deletions tests/functional/Mathielen/ImportEngine/LocalFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Mathielen\ImportEngine\Storage\Format\Format;
use Mathielen\ImportEngine\Storage\Format\XmlFormat;
use Mathielen\ImportEngine\Storage\LocalFileStorage;
use Mathielen\ImportEngine\Storage\StorageInfo;
use Mathielen\ImportEngine\ValueObject\ImportConfiguration;
use Mathielen\ImportEngine\ValueObject\ImportRun;

Expand All @@ -32,6 +33,14 @@ public function testImport($sourceFile, Format $format, Format $targetFormat=nul
$sourceStorage = new LocalFileStorage(new \SplFileInfo($sourceFile), $format);
$targetStorage = new LocalFileStorage(new \SplFileInfo($targetFile), $targetFormat);

$this->assertEquals(new StorageInfo(array(
'name' => basename($targetFile),
'hash' => null,
'format' => $targetFormat,
'size' => 0,
'count' => 0
)), $targetStorage->info());

$importer = Importer::build($targetStorage);

$importConfiguration = new ImportConfiguration();
Expand Down

0 comments on commit 1a7aa48

Please sign in to comment.