Verified Commit fc14cbc6 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3283498 by Mile23, alexpott: Scaffold ReplaceOp::copyScaffold() throws...

Issue #3283498 by Mile23, alexpott: Scaffold ReplaceOp::copyScaffold() throws an error for empty files
parent 1c5c378e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -92,8 +92,7 @@ public function process(ScaffoldFilePath $destination, IOInterface $io, Scaffold
  protected function copyScaffold(ScaffoldFilePath $destination, IOInterface $io) {
    $interpolator = $destination->getInterpolator();
    $this->source->addInterpolationData($interpolator);
    $success = file_put_contents($destination->fullPath(), $this->contents());
    if (!$success) {
    if (file_put_contents($destination->fullPath(), $this->contents()) === FALSE) {
      throw new \RuntimeException($interpolator->interpolate("Could not copy source file <info>[src-rel-path]</info> to <info>[dest-rel-path]</info>!"));
    }
    $io->write($interpolator->interpolate("  - Copy <info>[dest-rel-path]</info> from <info>[src-rel-path]</info>"));
+22 −0
Original line number Diff line number Diff line
@@ -39,4 +39,26 @@ public function testProcess() {
    $this->assertStringContainsString('Copy [web-root]/robots.txt from assets/robots.txt', $output);
  }

  /**
   * @covers ::process
   */
  public function testEmptyFile() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/empty_file.txt');
    $source = $fixtures->sourcePath('empty-file', 'empty_file.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new ReplaceOp($source, TRUE);
    // Assert that there is no target file before we run our test.
    $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.
    $sut->process($destination, $fixtures->io(), $options);
    // Assert that the target file was created.
    $this->assertFileExists($destination->fullPath());
    // Assert the target contained the contents from the correct scaffold file.
    $this->assertSame('', file_get_contents($destination->fullPath()));
    // Confirm that expected output was written to our io fixture.
    $output = $fixtures->getOutput();
    $this->assertStringContainsString('Copy [web-root]/empty_file.txt from assets/empty_file.txt', $output);
  }

}
+10 −0
Original line number Diff line number Diff line
{
  "name": "fixtures/empty-file",
  "extra": {
    "drupal-scaffold": {
      "file-mapping": {
        "[web-root]/empty_file.txt": "assets/empty_file.txt"
      }
    }
  }
}