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 LinuxPlatform |
30
|
|
|
*/ |
31
|
|
|
protected $platform; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc TestCase |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
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
|
|
|
* @inheritdoc 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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.