|
@@ 135-176 (lines=42) @@
|
| 132 |
|
static::assertSame($target, $this->reFormatter->reFormat($file, $format)); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
public function testCanReFormatALocalInputFile() |
| 136 |
|
{ |
| 137 |
|
$file = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class); |
| 138 |
|
$target = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class); |
| 139 |
|
|
| 140 |
|
$file->shouldReceive('getPath') |
| 141 |
|
->andReturn('/tmp/file.txt'); |
| 142 |
|
$file->shouldReceive('exists') |
| 143 |
|
->andReturn(true); |
| 144 |
|
|
| 145 |
|
$file->shouldReceive('getClone') |
| 146 |
|
->andReturn($target); |
| 147 |
|
$target->shouldReceive('setPath') |
| 148 |
|
->with('/tmp/file-format.txt') |
| 149 |
|
->andReturn($target); |
| 150 |
|
|
| 151 |
|
$format = m::mock(FormatInterface::class); |
| 152 |
|
|
| 153 |
|
$target->shouldReceive('setFormat') |
| 154 |
|
->with($format) |
| 155 |
|
->andReturn($target); |
| 156 |
|
|
| 157 |
|
$reader = m::mock(FileReader::class); |
| 158 |
|
$this->builder->shouldReceive('build') |
| 159 |
|
->with(FileReader::class, $file, null, $this->parserFactory) |
| 160 |
|
->andReturn($reader); |
| 161 |
|
$writer = m::mock(FileWriter::class); |
| 162 |
|
$this->builder->shouldReceive('build') |
| 163 |
|
->with(FileWriter::Class, $target, $format, $this->formatterFactory) |
| 164 |
|
->andReturn($writer); |
| 165 |
|
|
| 166 |
|
$iterator = new ArrayIterator(['first', 'second']); |
| 167 |
|
|
| 168 |
|
$reader->shouldReceive('fetch') |
| 169 |
|
->andReturn($iterator); |
| 170 |
|
|
| 171 |
|
$writer->shouldReceive('insertAll') |
| 172 |
|
->with($iterator) |
| 173 |
|
->once(); |
| 174 |
|
|
| 175 |
|
static::assertSame($target, $this->reFormatter->reFormat($file, $format)); |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
public function testCanReformatWithIntputAndOutputFiles() |
| 179 |
|
{ |
|
@@ 276-317 (lines=42) @@
|
| 273 |
|
static::assertSame($target, $this->reFormatter->modify($file, ['output' => $target])); |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
public function testModifyWithFormatOption() |
| 277 |
|
{ |
| 278 |
|
$file = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class); |
| 279 |
|
$target = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class); |
| 280 |
|
|
| 281 |
|
$file->shouldReceive('getPath') |
| 282 |
|
->andReturn('/tmp/file.txt'); |
| 283 |
|
$file->shouldReceive('exists') |
| 284 |
|
->andReturn(true); |
| 285 |
|
|
| 286 |
|
$file->shouldReceive('getClone') |
| 287 |
|
->andReturn($target); |
| 288 |
|
$target->shouldReceive('setPath') |
| 289 |
|
->with('/tmp/file-format.txt') |
| 290 |
|
->andReturn($target); |
| 291 |
|
|
| 292 |
|
$format = m::mock(FormatInterface::class); |
| 293 |
|
|
| 294 |
|
$target->shouldReceive('setFormat') |
| 295 |
|
->with($format) |
| 296 |
|
->andReturn($target); |
| 297 |
|
|
| 298 |
|
$reader = m::mock(FileReader::class); |
| 299 |
|
$this->builder->shouldReceive('build') |
| 300 |
|
->with(FileReader::class, $file, null, $this->parserFactory) |
| 301 |
|
->andReturn($reader); |
| 302 |
|
$writer = m::mock(FileWriter::class); |
| 303 |
|
$this->builder->shouldReceive('build') |
| 304 |
|
->with(FileWriter::Class, $target, $format, $this->formatterFactory) |
| 305 |
|
->andReturn($writer); |
| 306 |
|
|
| 307 |
|
$iterator = new ArrayIterator(['first', 'second']); |
| 308 |
|
|
| 309 |
|
$reader->shouldReceive('fetch') |
| 310 |
|
->andReturn($iterator); |
| 311 |
|
|
| 312 |
|
$writer->shouldReceive('insertAll') |
| 313 |
|
->with($iterator) |
| 314 |
|
->once(); |
| 315 |
|
|
| 316 |
|
static::assertSame($target, $this->reFormatter->modify($file, ['format' => $format])); |
| 317 |
|
} |
| 318 |
|
|
| 319 |
|
public function testReFormatWithDeleteOldFile() |
| 320 |
|
{ |