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\LinuxPlatform; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @coversDefaultClass \ComponentManager\Platform\LinuxPlatform |
17
|
|
|
* @group platform |
18
|
|
|
* @group platform-linux |
19
|
|
|
*/ |
20
|
|
|
class PlatformLinuxPlatformTest extends TestCase { |
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $oldPath; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \ComponentManager\Platform\LinuxPlatform |
28
|
|
|
*/ |
29
|
|
|
protected $platform; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @override \PHPUnit_Framework_TestCase |
33
|
|
|
*/ |
34
|
|
|
public function setUp() { |
35
|
|
|
$this->oldPath = getenv('PATH'); |
36
|
|
|
putenv("PATH=/bin:{$this->oldPath}"); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$filesystem = $this->createMock(Filesystem::class); |
39
|
|
|
$this->platform = new LinuxPlatform($filesystem); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @override \PHPUnit_Framework_TestCase |
44
|
|
|
*/ |
45
|
|
|
public function tearDown() { |
46
|
|
|
putenv("PATH={$this->oldPath}"); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers ::expandPath |
51
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::__construct |
52
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
53
|
|
|
* @covers \ComponentManager\Platform\LinuxPlatform::getHomeDirectory |
54
|
|
|
*/ |
55
|
|
|
public function testExpandPath() { |
56
|
|
|
$expected = getenv('HOME') . '/test'; |
57
|
|
|
$actual = $this->platform->expandPath('~/test'); |
58
|
|
|
|
59
|
|
|
$this->assertEquals($expected, $actual); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers ::getExecutablePath |
64
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::__construct |
65
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
66
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
67
|
|
|
*/ |
68
|
|
|
public function testGetExecutablePath() { |
69
|
|
|
$this->assertEquals( |
70
|
|
|
'/bin/sh', $this->platform->getExecutablePath('sh')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers ::getExecutablePath |
75
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::__construct |
76
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
77
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
78
|
|
|
* @expectedException \ComponentManager\Exception\PlatformException |
79
|
|
|
* @expectedExceptionCode 2 |
80
|
|
|
*/ |
81
|
|
|
public function testGetExecutablePathThrows() { |
82
|
|
|
$this->platform->getExecutablePath('likelynotathing'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @covers ::getHomeDirectory |
87
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::__construct |
88
|
|
|
*/ |
89
|
|
|
public function testGetHomeDirectory() { |
90
|
|
|
$this->assertFileExists($this->platform->getHomeDirectory()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @covers ::getHomeDirectory |
95
|
|
|
* @covers ::getLocalSharedDirectory |
96
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::__construct |
97
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
|
|
|
|
98
|
|
|
* @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
99
|
|
|
*/ |
100
|
|
|
public function testGetLocalSharedDirectory() { |
101
|
|
|
$this->assertFileExists($this->platform->getLocalSharedDirectory()); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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.