Skip to content

Commit cdb2341

Browse files
Added step to remove files and folders
1 parent fe79370 commit cdb2341

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* Copyright 2021 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
namespace de\codenamephp\installer\steps;
20+
21+
use Symfony\Component\Filesystem\Exception\IOException;
22+
use Symfony\Component\Filesystem\Filesystem;
23+
24+
/**
25+
* Deletes files and folders using symfony filesystem
26+
*/
27+
final class DeleteFilesAndFolders implements iStep {
28+
29+
/**
30+
* @param Filesystem $filesystem
31+
* @param string[] $filesAndFoldersToDelete
32+
*/
33+
public function __construct(public Filesystem $filesystem, public array $filesAndFoldersToDelete) { }
34+
35+
/**
36+
*
37+
* @inheritDoc
38+
* @throws IOException
39+
*/
40+
public function run() : void {
41+
$this->filesystem->remove($this->filesAndFoldersToDelete);
42+
}
43+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* Copyright 2021 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
namespace de\codenamephp\installer\test\steps;
20+
21+
use de\codenamephp\installer\steps\DeleteFilesAndFolders;
22+
use PHPUnit\Framework\TestCase;
23+
use Symfony\Component\Filesystem\Filesystem;
24+
25+
class DeleteFilesAndFoldersTest extends TestCase {
26+
27+
private DeleteFilesAndFolders $sut;
28+
29+
protected function setUp() : void {
30+
$filesystem = $this->createMock(Filesystem::class);
31+
32+
$this->sut = new DeleteFilesAndFolders($filesystem, []);
33+
}
34+
35+
public function testRun() : void {
36+
$this->sut->filesAndFoldersToDelete = ['some', 'files'];
37+
38+
$filesystem = $this->createMock(Filesystem::class);
39+
$filesystem->expects(self::once())->method('remove')->with($this->sut->filesAndFoldersToDelete);
40+
$this->sut->filesystem = $filesystem;
41+
42+
$this->sut->run();
43+
}
44+
}

0 commit comments

Comments
 (0)