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