Passed
Branch master (cd2b9b)
by Scott
03:31
created

PhpunitDiffFilterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 78.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 59
loc 75
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testWrongArgs() 0 5 1
A testWorkingCorrectly() 12 12 1
A testFailingBuild() 20 20 2
A testPassingLowPercentage() 14 14 1
A testNoCoveredLines() 13 13 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
namespace exussum12\CoverageChecker\tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Exception;
6
7
class PhpunitDiffFilterTest extends TestCase
8
{
9
    /**
10
     * @expectedException Exception
11
     * @expectedExceptionCode 1
12
     */
13
    public function testWrongArgs()
0 ignored issues
show
Coding Style introduced by
testWrongArgs uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
14
    {
15
        $GLOBALS['argv'] = [];
16
        require(__DIR__ . "/../src/runners/phpunitDiffFilter.php");
17
    }
18
19 View Code Duplication
    public function testWorkingCorrectly()
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...
Coding Style introduced by
testWorkingCorrectly uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
20
    {
21
        $GLOBALS['argv'] = [
22
            'phpunitDiffFilter',
23
            __DIR__ . '/fixtures/change.txt',
24
            __DIR__ . '/fixtures/coverage.xml'
25
        ];
26
        ob_start();
27
        require(__DIR__ . "/../src/runners/phpunitDiffFilter.php");
28
        $output = ob_get_clean();
29
        $this->assertContains('100.00%', $output);
30
    }
31
32 View Code Duplication
    public function testFailingBuild()
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...
Coding Style introduced by
testFailingBuild uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
33
    {
34
        $GLOBALS['argv'] = [
35
            'phpunitDiffFilter',
36
            __DIR__ . '/fixtures/newFile.txt',
37
            __DIR__ . '/fixtures/coverage-change.xml',
38
            70
39
        ];
40
        try {
41
            ob_start();
42
            require(__DIR__ . "/../src/runners/phpunitDiffFilter.php");
43
        } catch (Exception $e) {
44
            $output = ob_get_clean();
45
            $this->assertEquals(2, $e->getCode());
46
            $this->assertContains('66.67%', $output);
47
            return;
48
        }
49
50
        $this->fail("no exception thrown");
51
    }
52
53 View Code Duplication
    public function testPassingLowPercentage()
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...
Coding Style introduced by
testPassingLowPercentage uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
54
    {
55
        $GLOBALS['argv'] = [
56
            'phpunitDiffFilter',
57
            __DIR__ . '/fixtures/newFile.txt',
58
            __DIR__ . '/fixtures/coverage-change.xml',
59
            60
60
        ];
61
62
        ob_start();
63
        require(__DIR__ . "/../src/runners/phpunitDiffFilter.php");
64
        $output = ob_get_clean();
65
        $this->assertContains('66.67%', $output);
66
    }
67
68 View Code Duplication
    public function testNoCoveredLines()
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...
Coding Style introduced by
testNoCoveredLines uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
69
    {
70
        $GLOBALS['argv'] = [
71
            'phpunitDiffFilter',
72
            __DIR__ . '/fixtures/removeFile.txt',
73
            __DIR__ . '/fixtures/coverage-change.xml',
74
        ];
75
76
        ob_start();
77
        require(__DIR__ . "/../src/runners/phpunitDiffFilter.php");
78
        $output = ob_get_clean();
79
        $this->assertContains('No lines found', $output);
80
    }
81
}
82