Passed
Push — master ( fc9abb...9945a9 )
by Luke
02:47
created

LinuxPlatformTest::testGetLocalSharedDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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}");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
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}");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
49
    }
50
51
    /**
52
     * @covers ::expandPath
53
     * @covers \ComponentManager\Platform\AbstractPlatform::__construct
54
     * @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 81 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
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
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 81 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
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
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 81 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
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
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 81 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
100
     * @covers \ComponentManager\Platform\AbstractPlatform::joinPaths
101
     */
102
    public function testGetLocalSharedDirectory() {
103
        $this->assertFileExists($this->platform->getLocalSharedDirectory());
104
    }
105
}
106