Passed
Push — master ( 95d224...68f44f )
by Luke
02:40
created

PlatformLinuxPlatformTest::testExpandPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
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 {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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}");
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...
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}");
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...
47
    }
48
49
    /**
50
     * @covers ::expandPath
51
     * @covers \ComponentManager\Platform\AbstractPlatform::__construct
52
     * @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...
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
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...
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
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...
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
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...
98
     * @covers \ComponentManager\Platform\AbstractPlatform::joinPaths
99
     */
100
    public function testGetLocalSharedDirectory() {
101
        $this->assertFileExists($this->platform->getLocalSharedDirectory());
102
    }
103
}
104