Skip to content

Commit

Permalink
Merge pull request #1 from josegonzalez/patch-1
Browse files Browse the repository at this point in the history
Mock underlying fileystem writes
  • Loading branch information
jorisvaesen committed Mar 15, 2016
2 parents 8da2d61 + 8b27ef5 commit e476219
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions tests/TestCase/File/Writer/DefaultWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public function setup()
}
]
];
$this->writer = new DefaultWriter($this->table, $this->entity, $this->data, $this->field, $this->settings);
$this->writer = new DefaultWriter(
$this->table,
$this->entity,
$this->data,
$this->field,
$this->settings
);

$this->vfs = new Vfs;
mkdir($this->vfs->path('/tmp'));
Expand All @@ -59,16 +65,19 @@ public function testInvoke()

public function testDelete()
{
$writer = $this->getMock('Josegonzalez\Upload\File\Writer\DefaultWriter', ['delete'], [$this->table, $this->entity, $this->data, $this->field, $this->settings]);
$writer->expects($this->any())->method('delete')->will($this->returnValue([true]));
$filesystem = $this->getMock('League\Flysystem\FilesystemInterface');
$filesystem->expects($this->at(0))->method('delete')->will($this->returnValue(true));
$filesystem->expects($this->at(1))->method('delete')->will($this->returnValue(false));
$writer = $this->getMock('Josegonzalez\Upload\File\Writer\DefaultWriter', ['getFilesystem'], [$this->table, $this->entity, $this->data, $this->field, $this->settings]);
$writer->expects($this->any())->method('getFilesystem')->will($this->returnValue($filesystem));

$this->assertEquals([], $writer->delete([]));
$this->assertEquals([true], $writer->delete([
$this->vfs->path('existing-file.txt')
$this->vfs->path('/tmp/tempfile')
]));

$writer = $this->getMock('Josegonzalez\Upload\File\Writer\DefaultWriter', ['delete'], [$this->table, $this->entity, $this->data, $this->field, $this->settings]);
$writer->expects($this->any())->method('delete')->will($this->returnValue([false]));
$this->assertEquals([false], $writer->delete([
$this->vfs->path('unexisting-file.txt')
$this->vfs->path('/tmp/invalid.txt')
]));
}

Expand Down

0 comments on commit e476219

Please sign in to comment.