mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Introduces a new method copy()
.
Some packages, e. g. `tm/tooly-composer-script`, are using the composer classes to e. g. create symlinks or perform other file operations. While there's only a `copyThenRemove()` method this commit introduces a new `copy()` method. `copy()` behaves the same as the copy part of `copyThenRemove()` did with one exception: it returns `true` on success and `false` on failure. Copying a directory may lead to a `false`, while the whole directory or some of its files couldn't been copied. To ensure backwards compatibility `copyThenRemove()` calls `copy()` now. This commit also adds the necessary tests.
This commit is contained in:
parent
d9885d5b3b
commit
39d8104897
2 changed files with 61 additions and 3 deletions
|
@ -311,4 +311,46 @@ class FilesystemTest extends TestCase
|
|||
$this->assertTrue($fs->removeJunction($junction));
|
||||
$this->assertFalse(is_dir($junction));
|
||||
}
|
||||
|
||||
public function testCopy()
|
||||
{
|
||||
@mkdir($this->workingDir . '/foo/bar', 0777, true);
|
||||
@mkdir($this->workingDir . '/foo/baz', 0777, true);
|
||||
file_put_contents($this->workingDir . '/foo/foo.file', 'foo');
|
||||
file_put_contents($this->workingDir . '/foo/bar/foobar.file', 'foobar');
|
||||
file_put_contents($this->workingDir . '/foo/baz/foobaz.file', 'foobaz');
|
||||
file_put_contents($this->testFile, 'testfile');
|
||||
$fs = new Filesystem();
|
||||
$result1 = $fs->copy($this->workingDir . '/foo', $this->workingDir . '/foop');
|
||||
$result2 = $fs->copy($this->testFile, $this->workingDir . '/foop/testfile.file');
|
||||
$this->assertTrue($result1);
|
||||
$this->assertTrue($result2);
|
||||
$this->assertTrue(is_dir($this->workingDir . '/foop'));
|
||||
$this->assertTrue(is_dir($this->workingDir . '/foop/bar'));
|
||||
$this->assertTrue(is_dir($this->workingDir . '/foop/baz'));
|
||||
$this->assertTrue(is_file($this->workingDir . '/foop/foo.file'));
|
||||
$this->assertTrue(is_file($this->workingDir . '/foop/bar/foobar.file'));
|
||||
$this->assertTrue(is_file($this->workingDir . '/foop/baz/foobaz.file'));
|
||||
$this->assertTrue(is_file($this->workingDir . '/foop/testfile.file'));
|
||||
}
|
||||
|
||||
public function testCopyTheRemove()
|
||||
{
|
||||
@mkdir($this->workingDir . '/foo/bar', 0777, true);
|
||||
@mkdir($this->workingDir . '/foo/baz', 0777, true);
|
||||
file_put_contents($this->workingDir . '/foo/foo.file', 'foo');
|
||||
file_put_contents($this->workingDir . '/foo/bar/foobar.file', 'foobar');
|
||||
file_put_contents($this->workingDir . '/foo/baz/foobaz.file', 'foobaz');
|
||||
file_put_contents($this->testFile, 'testfile');
|
||||
$fs = new Filesystem();
|
||||
$fs->copyThenRemove($this->workingDir . '/foo', $this->workingDir . '/foop');
|
||||
$fs->copyThenRemove($this->testFile, $this->workingDir . '/foop/testfile.file');
|
||||
$this->assertFalse(is_file($this->workingDir . '/foop/testfile.file'));
|
||||
$this->assertFalse(is_file($this->workingDir . '/foop/baz/foobaz.file'));
|
||||
$this->assertFalse(is_file($this->workingDir . '/foop/bar/foobar.file'));
|
||||
$this->assertFalse(is_file($this->workingDir . '/foop/foo.file'));
|
||||
$this->assertFalse(is_dir($this->workingDir . '/foop/baz'));
|
||||
$this->assertFalse(is_dir($this->workingDir . '/foop/bar'));
|
||||
$this->assertFalse(is_dir($this->workingDir . '/foop'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue