|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information please see |
|
17
|
|
|
* <http://phing.info>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Phing\Io; |
|
21
|
|
|
|
|
22
|
|
|
use Phing\Phing; |
|
23
|
|
|
use ReflectionClass; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Unit test for FileSystem |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
class FileSystemTest extends \PHPUnit\Framework\TestCase |
|
30
|
|
|
{ |
|
31
|
|
|
private $oldFsType = ""; |
|
32
|
|
|
|
|
33
|
|
|
public function setUp(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->oldFsType = Phing::getProperty('host.fstype'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function tearDown(): void |
|
39
|
|
|
{ |
|
40
|
|
|
Phing::setProperty('host.fstype', $this->oldFsType); |
|
41
|
|
|
$this->_resetFileSystem(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function _resetFileSystem() |
|
45
|
|
|
{ |
|
46
|
|
|
$refClass = new ReflectionClass(FileSystem::class); |
|
47
|
|
|
$refProperty = $refClass->getProperty('fs'); |
|
48
|
|
|
$refProperty->setAccessible(true); |
|
49
|
|
|
$refProperty->setValue(null); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testGetFileSystemWithUnknownTypeKeyThrowsException() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->_resetFileSystem(); |
|
55
|
|
|
|
|
56
|
|
|
$this->expectException(IOException::class); |
|
57
|
|
|
|
|
58
|
|
|
Phing::setProperty('host.fstype', 'UNRECOGNISED'); |
|
59
|
|
|
|
|
60
|
|
|
FileSystem::getFileSystem(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @dataProvider fileSystemMappingsDataProvider |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testGetFileSystemReturnsCorrect($expectedFileSystemClass, $fsTypeKey) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->_resetFileSystem(); |
|
69
|
|
|
|
|
70
|
|
|
Phing::setProperty('host.fstype', $fsTypeKey); |
|
71
|
|
|
|
|
72
|
|
|
$system = FileSystem::getFileSystem(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertInstanceOf($expectedFileSystemClass, $system); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function fileSystemMappingsDataProvider() |
|
78
|
|
|
{ |
|
79
|
|
|
return [ |
|
80
|
|
|
[UnixFileSystem::class, 'UNIX'], |
|
81
|
|
|
[WindowsFileSystem::class, 'WINDOWS'], |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testWhichFailsNonStringExecutable() |
|
86
|
|
|
{ |
|
87
|
|
|
$fs = FileSystem::getFileSystem(); |
|
88
|
|
|
$path = $fs->which(42); |
|
89
|
|
|
$this->assertEquals($path, false); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testWhichFailsDueToUnusualExecutableName() |
|
93
|
|
|
{ |
|
94
|
|
|
$fs = FileSystem::getFileSystem(); |
|
95
|
|
|
$path = $fs->which('tasword.bin'); |
|
96
|
|
|
$this->assertEquals($path, false); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testWhichHinkyExecutableNameWithSeparator() |
|
100
|
|
|
{ |
|
101
|
|
|
$fs = FileSystem::getFileSystem(); |
|
102
|
|
|
$path = $fs->which('zx:\tasword.bin'); |
|
103
|
|
|
$this->assertEquals($path, false); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testListContentsWithNumericName() |
|
107
|
|
|
{ |
|
108
|
|
|
$fs = FileSystem::getFileSystem(); |
|
109
|
|
|
|
|
110
|
|
|
$parentDir = new File(__DIR__ . '/../../etc/system/io/testdir'); |
|
111
|
|
|
$contents = $fs->listContents($parentDir); |
|
112
|
|
|
|
|
113
|
|
|
foreach ($contents as $filename) { |
|
114
|
|
|
self::assertIsString($filename); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|