Completed
Pull Request — master (#912)
by
unknown
07:49
created

OperatingSystemTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 35 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 28
loc 80
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A osDetection() 0 12 1
A testIsLinux() 7 7 1
A testIsWindows() 7 7 1
A testIsMacOs() 7 7 1
A testIsNetware() 7 7 1
A getCwd() 0 5 1
A phpBinary() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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