Пример #1
0
 public function testCanCallMakeDirectoryWithAnExistingFolder()
 {
     $file = new LocalFile(static::$dir . 'no_dir_file');
     static::assertTrue(file_exists($file->getDirectory()));
     $retFile = $this->maker->makeDirectory($file);
     static::assertSame($retFile, $file);
 }
Пример #2
0
 /**
  * @param string      $path
  * @param string|null $contents
  *
  * @return LocalFile
  */
 protected function makeFile($path, $contents = null)
 {
     $file = new LocalFile(static::$dir . $path);
     if (!is_null($contents)) {
         $file->write($contents);
     }
     return $file;
 }
Пример #3
0
 public function testMoveDeletesTheOldFile()
 {
     $fromFile = new LocalFile(static::$dir . 'delete_from.text');
     $fromFile->put('Some Text In Here');
     $toFile = new LocalFile(static::$dir . 'delete_to.text');
     $this->transfer->moveTo($fromFile, $toFile);
     static::assertEquals('Some Text In Here', $toFile->read());
     static::assertFalse($fromFile->exists());
 }
Пример #4
0
    public function testReFormatFromCsvToJson()
    {
        $file = new LocalFile(static::$dir . 'reFormatInput.csv');
        $file->setFormat(new CsvFormat(['headerRow' => 1]));
        $input = <<<CSV
"first","second","third"
"1","cake","monkies"
"2","banana","fish"
CSV;
        $file->write($input);
        $output = new LocalFile(static::$dir . 'reFormatOutput.json');
        $output->setFormat(new JsonFormat(['fileType' => JsonFormat::JSON_FILE_TYPE_EACH_LINE]));
        $reFormat = new ReFormat();
        $reFormat->reFormat($file, null, $output);
        $expected = <<<JSON
{"first":"1","second":"cake","third":"monkies"}
{"first":"2","second":"banana","third":"fish"}
JSON;
        static::assertEquals($expected, $output->read());
    }
Пример #5
0
 public function testConversionWillFailWhenSpecifyingAnInvalidEncoding()
 {
     $asciiFile = new LocalFile(static::$dir . 'ascii_fail.test');
     $asciiFile->put(mb_convert_encoding('Some random Text', 'ASCII'));
     $this->expectException(ProcessFailedException::class);
     $this->converter->toEncoding($asciiFile, 'NotARealEncoding');
 }
Пример #6
0
 public function testPassingFalseToKeepOldFileOptionWillKeepTheFile()
 {
     $file = new LocalFile(static::$dir . 'delete_file_zip.test');
     $file->put('random stuff and things!');
     $compressedFile = $this->zip->compress($file, ['keepOldFile' => false]);
     static::assertFalse($file->exists());
     static::assertTrue($compressedFile->exists());
     $uncompresssedFile = $this->zip->decompress($compressedFile, ['keepOldFile' => false]);
     static::assertFalse($compressedFile->exists());
     static::assertTrue($uncompresssedFile->exists());
 }
Пример #7
0
 public function testGetStream()
 {
     $file = new LocalFile(static::$dir . 'file_get_stream.test');
     $stream = $file->getStream();
     static::assertInternalType('resource', $stream);
     fwrite($stream, 'some text');
     fclose($stream);
     static::assertEquals('some text', $file->read());
 }
Пример #8
0
 public function testModifyWillSetTheEncoding()
 {
     $utf8file = new LocalFile(static::$dir . 'utf8_file.test');
     $utf8file->put(mb_convert_encoding('Some random Text €±§', 'UTF-8'));
     $utf8file = $this->findEncoding->modify($utf8file);
     static::assertEquals('utf-8', $utf8file->getEncoding());
 }
Пример #9
0
 public function testWhenTheProcessFailsAnExceptionIsThrownOnFindEncoding()
 {
     $process = m::mock(Process::class)->makePartial();
     $process->shouldReceive('isSuccessful')->andReturn(false);
     $this->builder->shouldReceive('build')->andReturn($process);
     $file = new LocalFile(static::$dir . 'failed_tail.test');
     $file->put('nothing interesting here');
     $this->expectException(ProcessFailedException::class);
     $this->head->head($file, 3);
 }
Пример #10
0
 public function testWhenTheProcessFailsAnExceptionIsThrownOnFindEncoding()
 {
     $process = m::mock(Process::class)->makePartial();
     $process->shouldReceive('isSuccessful')->andReturn(false);
     $this->builder->shouldReceive('build')->andReturn($process);
     $file = new LocalFile(static::$dir . 'failed_replace_text.test');
     $file->put('some text that text should be replaced');
     $this->expectException(ProcessFailedException::class);
     $this->replacer->replaceText($file, 'text', 'pants');
 }
Пример #11
0
 public function testModifyWillSetTheCompression()
 {
     $file = new LocalFile(static::$dir . 'tobegzipped_file.test');
     $file->put('some random text');
     $gzip = new Gzip();
     $gzipFile = $gzip->compress($file);
     $gzipFile->setCompression(CompressionFactory::TYPE_NONE);
     $gzipFile = $this->findCompression->modify($gzipFile);
     static::assertEquals(Gzip::NAME, $gzipFile->getCompression());
 }