1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Moodle component manager. |
5
|
|
|
* |
6
|
|
|
* @author Luke Carrier <[email protected]> |
7
|
|
|
* @copyright 2016 Luke Carrier |
8
|
|
|
* @license GPL-3.0+ |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use ComponentManager\Platform\WindowsPlatform; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @coversDefaultClass \ComponentManager\Platform\WindowsPlatform |
16
|
|
|
* @group platform |
17
|
|
|
* @group platform-windows |
18
|
|
|
*/ |
19
|
|
|
class PlatformWindowsPlatformTest extends TestCase { |
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $oldPath; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $oldWorkingDirectory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \ComponentManager\Platform\WindowsPlatform |
32
|
|
|
*/ |
33
|
|
|
protected $platform; |
34
|
|
|
|
35
|
|
|
public function setUp() { |
36
|
|
|
$this->oldPath = getenv('PATH'); |
37
|
|
|
putenv("PATH=C:\\windows\\system32;{$this->oldPath}"); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$this->oldWorkingDirectory = getcwd(); |
40
|
|
|
|
41
|
|
|
$this->platform = new WindowsPlatform(); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function tearDown() { |
45
|
|
|
putenv("PATH={$this->oldPath}"); |
|
|
|
|
46
|
|
|
|
47
|
|
|
chdir($this->oldWorkingDirectory); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::createTempDirectory |
52
|
|
|
*/ |
53
|
|
|
public function testCreateTempDirectory() { |
54
|
|
|
$temp = $this->platform->createTempDirectory(); |
55
|
|
|
|
56
|
|
|
$this->assertFileExists($temp); |
57
|
|
|
|
58
|
|
|
rmdir($temp); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @covers ::expandPath |
63
|
|
|
*/ |
64
|
|
|
public function testExpandPath() { |
65
|
|
|
$this->assertEquals('~\blah', $this->platform->expandPath('~\blah')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
70
|
|
|
*/ |
71
|
|
|
public function testGetDirectorySeparator() { |
72
|
|
|
$this->assertEquals('\\', $this->platform->getDirectorySeparator()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @covers ::getExecutablePath |
77
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
78
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
79
|
|
|
*/ |
80
|
|
|
public function testGetExecutablePath() { |
81
|
|
|
$this->assertEquals( |
82
|
|
|
'c:\\windows\\system32\\cmd.exe', |
83
|
|
|
strtolower($this->platform->getExecutablePath('cmd'))); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @covers ::getExecutablePath |
88
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
89
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
90
|
|
|
* |
91
|
|
|
* @expectedException \ComponentManager\Exception\PlatformException |
92
|
|
|
* @expectedExceptionCode 2 |
93
|
|
|
*/ |
94
|
|
|
public function testGetExecutablePathThrows() { |
95
|
|
|
$this->platform->getExecutablePath('likelynotathing'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @covers ::getHomeDirectory |
100
|
|
|
*/ |
101
|
|
|
public function testGetHomeDirectory() { |
102
|
|
|
$home = $this->platform->getHomeDirectory(); |
103
|
|
|
$user = getenv('USERNAME'); |
104
|
|
|
|
105
|
|
|
$this->assertStringEndsWith($user, $home); |
106
|
|
|
$this->assertFileExists($home); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @covers ::getLocalSharedDirectory |
111
|
|
|
*/ |
112
|
|
|
public function testGetLocalSharedDirectory() { |
113
|
|
|
$this->assertFileExists($this->platform->getLocalSharedDirectory()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getPhpExecutable |
118
|
|
|
*/ |
119
|
|
|
public function testGetPhpExecutable() { |
120
|
|
|
$this->assertFileExists($this->platform->getPhpExecutable()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getPhpScript |
125
|
|
|
*/ |
126
|
|
|
public function testGetPhpScript() { |
127
|
|
|
$this->assertFileExists($this->platform->getPhpScript()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getWorkingDirectory |
132
|
|
|
*/ |
133
|
|
|
public function testGetWorkingDirectory() { |
134
|
|
|
$target = 'c:\windows'; |
135
|
|
|
|
136
|
|
|
$this->assertEquals(getcwd(), $this->platform->getWorkingDirectory()); |
137
|
|
|
|
138
|
|
|
chdir($target); |
139
|
|
|
$this->assertEquals($target, $this->platform->getWorkingDirectory()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
144
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
public function testJoinPaths() { |
147
|
|
|
$this->assertEquals( |
148
|
|
|
'c:\\windows', $this->platform->joinPaths(['c:', 'windows'])); |
149
|
|
|
|
150
|
|
|
$this->assertEquals( |
151
|
|
|
'c:\\windows\\system32', |
152
|
|
|
$this->platform->joinPaths(['c:', 'windows\\system32'])); |
153
|
|
|
|
154
|
|
|
$this->assertEquals( |
155
|
|
|
'c:\\windows\\system32', |
156
|
|
|
$this->platform->joinPaths(['c:\\windows', 'system32'])); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.