コード例 #1
0
ファイル: ReFormatTest.php プロジェクト: graze/data-file
 public function testModifyWithFormatOption()
 {
     $file = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class);
     $target = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class);
     $file->shouldReceive('getPath')->andReturn('/tmp/file.txt');
     $file->shouldReceive('exists')->andReturn(true);
     $file->shouldReceive('getClone')->andReturn($target);
     $target->shouldReceive('setPath')->with('/tmp/file-format.txt')->andReturn($target);
     $format = m::mock(FormatInterface::class);
     $target->shouldReceive('setFormat')->with($format)->andReturn($target);
     $reader = m::mock(FileReader::class);
     $this->builder->shouldReceive('build')->with(FileReader::class, $file, null, $this->parserFactory)->andReturn($reader);
     $writer = m::mock(FileWriter::class);
     $this->builder->shouldReceive('build')->with(FileWriter::Class, $target, $format, $this->formatterFactory)->andReturn($writer);
     $iterator = new ArrayIterator(['first', 'second']);
     $reader->shouldReceive('fetch')->andReturn($iterator);
     $writer->shouldReceive('insertAll')->with($iterator)->once();
     static::assertSame($target, $this->reFormatter->modify($file, ['format' => $format]));
 }