1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* this file is part of magerun |
4
|
|
|
* |
5
|
|
|
* @author Tom Klingenberg <https://github.com/ktomk> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace N98\Util; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class OperatingSystemTest |
12
|
|
|
* |
13
|
|
|
* @package N98\Util |
14
|
|
|
* @covers N98\Util\OperatingSystem |
15
|
|
|
*/ |
16
|
|
|
class OperatingSystemTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
*/ |
21
|
|
|
public function osDetection() |
22
|
|
|
{ |
23
|
|
|
$matrix = array( |
24
|
|
|
OperatingSystem::isLinux(), |
25
|
|
|
OperatingSystem::isWindows(), |
26
|
|
|
OperatingSystem::isMacOs(), |
27
|
|
|
OperatingSystem::isNetware(), |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$this->assertCount(4, $matrix, 'Number of OSes to check for'); |
31
|
|
|
$this->assertCount(1, array_filter($matrix), 'One OS must be detected'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @requires OS Linux |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function testIsLinux() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->assertTrue(OperatingSystem::isLinux()); |
40
|
|
|
$this->assertFalse(OperatingSystem::isWindows()); |
41
|
|
|
$this->assertFalse(OperatingSystem::isMacOs()); |
42
|
|
|
$this->assertFalse(OperatingSystem::isNetware()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @requires OS ^Win |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function testIsWindows() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$this->assertTrue(OperatingSystem::isWindows()); |
51
|
|
|
$this->assertFalse(OperatingSystem::isLinux()); |
52
|
|
|
$this->assertFalse(OperatingSystem::isMacOs()); |
53
|
|
|
$this->assertFalse(OperatingSystem::isNetware()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @requires OS Darwin|Mac |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function testIsMacOs() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$this->assertTrue(OperatingSystem::isMacOs()); |
62
|
|
|
$this->assertFalse(OperatingSystem::isLinux()); |
63
|
|
|
$this->assertFalse(OperatingSystem::isWindows()); |
64
|
|
|
$this->assertFalse(OperatingSystem::isNetware()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @requires OS netware |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testIsNetware() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$this->assertTrue(OperatingSystem::isNetware()); |
73
|
|
|
$this->assertFalse(OperatingSystem::isLinux()); |
74
|
|
|
$this->assertFalse(OperatingSystem::isWindows()); |
75
|
|
|
$this->assertFalse(OperatingSystem::isMacOs()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @test |
80
|
|
|
*/ |
81
|
|
|
public function getCwd() |
82
|
|
|
{ |
83
|
|
|
$expected = getcwd(); |
84
|
|
|
$this->assertEquals($expected, OperatingSystem::getCwd()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @test |
89
|
|
|
* @requires PHP 5.4 |
90
|
|
|
*/ |
91
|
|
|
public function phpBinary() |
92
|
|
|
{ |
93
|
|
|
$this->assertEquals(PHP_BINARY, OperatingSystem::getPhpBinary()); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.