You are here

public function FileTest::testFile_saveChunk in One Click Upload 7.2

* @covers ::saveChunk

File

flowphp/test/Unit/FileTest.php, line 239

Class

FileTest
File unit tests

Namespace

Unit

Code

public function testFile_saveChunk() {

  //// Setup test

  // Setup temporary file
  $tmpDir = new vfsStreamDirectory('tmp');
  $tmpFile = vfsStream::newFile('tmpFile');
  $tmpFile
    ->setContent('1234567890');
  $tmpDir
    ->addChild($tmpFile);
  $this->vfs
    ->addChild($tmpDir);
  $this->filesArr['file']['tmp_name'] = $tmpFile
    ->url();

  // Mock File to use rename instead of move_uploaded_file
  $request = new Request($this->requestArr, $this->filesArr['file']);
  $file = $this
    ->getMock('Flow\\File', array(
    '_move_uploaded_file',
  ), array(
    $this->config,
    $request,
  ));
  $file
    ->expects($this
    ->once())
    ->method('_move_uploaded_file')
    ->will($this
    ->returnCallback(function ($filename, $destination) {
    return rename($filename, $destination);
  }));

  // Expected destination file
  $expDstFile = $this->vfs
    ->url() . DIRECTORY_SEPARATOR . sha1($request
    ->getIdentifier()) . '_1';

  //// Accrual test
  $this
    ->assertFalse(file_exists($expDstFile));
  $this
    ->assertTrue(file_exists($tmpFile
    ->url()));

  /** @noinspection PhpUndefinedMethodInspection */
  $this
    ->assertTrue($file
    ->saveChunk());
  $this
    ->assertTrue(file_exists($expDstFile));

  //$this->assertFalse(file_exists($tmpFile->url()));
  $this
    ->assertSame('1234567890', file_get_contents($expDstFile));
}