ReplaceOpTest.php in Drupal 10
File
core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ReplaceOpTest.php
View source
<?php
namespace Drupal\Tests\Composer\Plugin\Scaffold\Integration;
use Drupal\Composer\Plugin\Scaffold\Operations\ReplaceOp;
use Drupal\Composer\Plugin\Scaffold\ScaffoldOptions;
use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures;
use Drupal\Tests\Traits\PhpUnitWarnings;
use PHPUnit\Framework\TestCase;
class ReplaceOpTest extends TestCase {
use PhpUnitWarnings;
public function testProcess() {
$fixtures = new Fixtures();
$destination = $fixtures
->destinationPath('[web-root]/robots.txt');
$source = $fixtures
->sourcePath('drupal-assets-fixture', 'robots.txt');
$options = ScaffoldOptions::create([]);
$sut = new ReplaceOp($source, TRUE);
$this
->assertFileDoesNotExist($destination
->fullPath());
$sut
->process($destination, $fixtures
->io(), $options);
$this
->assertFileExists($destination
->fullPath());
$contents = trim(file_get_contents($destination
->fullPath()));
$this
->assertEquals('# Test version of robots.txt from drupal/core.', $contents);
$output = $fixtures
->getOutput();
$this
->assertStringContainsString('Copy [web-root]/robots.txt from assets/robots.txt', $output);
}
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);
$this
->assertFileDoesNotExist($destination
->fullPath());
$sut
->process($destination, $fixtures
->io(), $options);
$this
->assertFileExists($destination
->fullPath());
$this
->assertSame('', file_get_contents($destination
->fullPath()));
$output = $fixtures
->getOutput();
$this
->assertStringContainsString('Copy [web-root]/empty_file.txt from assets/empty_file.txt', $output);
}
}