You are here

public function ConfigFormTest::testCopyFileFailedWrite in Flysystem 8

Same name and namespace in other branches
  1. 3.x tests/src/Unit/Form/ConfigFormTest.php \Drupal\Tests\flysystem\Unit\Form\ConfigFormTest::testCopyFileFailedWrite()
  2. 2.0.x tests/src/Unit/Form/ConfigFormTest.php \Drupal\Tests\flysystem\Unit\Form\ConfigFormTest::testCopyFileFailedWrite()
  3. 3.0.x tests/src/Unit/Form/ConfigFormTest.php \Drupal\Tests\flysystem\Unit\Form\ConfigFormTest::testCopyFileFailedWrite()

@covers ::copyFile

File

tests/src/Unit/Form/ConfigFormTest.php, line 194

Class

ConfigFormTest
@coversDefaultClass \Drupal\flysystem\Form\ConfigForm @group flysystem

Namespace

Drupal\Tests\flysystem\Unit\Form

Code

public function testCopyFileFailedWrite() {
  $context = [];
  $from = new Filesystem(new MemoryAdapter());
  $from
    ->write('test.txt', 'abcdefg');
  $this->factory
    ->getFilesystem('from_files')
    ->willReturn($from);
  $failed_write = $this
    ->prophesize(FilesystemInterface::class);
  $failed_write
    ->putStream(Argument::cetera())
    ->willReturn(FALSE);
  $this->factory
    ->getFilesystem('to_fail')
    ->willReturn($failed_write);
  ConfigForm::copyFile('from_files', 'to_fail', 'test.txt', $context);
  $this
    ->assertSame(1, count($context['results']['errors']));
  $this
    ->assertTrue(strpos($context['results']['errors'][0][0], 'could not be saved') !== FALSE);
}