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

PhpmdDiffFilterTest::testNoValidLines()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 3
nop 0
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace exussum12\CoverageChecker\tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Exception;
6
7
class PhpmdDiffFilterTest extends TestCase
8
{
9
10 View Code Duplication
    public function testValid()
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
testValid 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...
11
    {
12
        $GLOBALS['argv'] = [
13
            'phpunitDiffFilter',
14
            __DIR__ . '/fixtures/change.txt',
15
            __DIR__ . '/fixtures/phpmd.xml'
16
        ];
17
        ob_start();
18
        require(__DIR__ . "/../src/runners/phpmdDiffFilter.php");
19
        $output = ob_get_clean();
20
        $this->assertContains('100.00%', $output);
21
    }
22
23 View Code Duplication
    public function testNoValidLines()
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
testNoValidLines 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...
24
    {
25
        $GLOBALS['argv'] = [
26
            'phpunitDiffFilter',
27
            __DIR__ . '/fixtures/change.txt',
28
            __DIR__ . '/fixtures/phpmd-change.xml',
29
        ];
30
        try {
31
            ob_start();
32
            require(__DIR__ . "/../src/runners/phpmdDiffFilter.php");
33
        } catch (Exception $e) {
34
            $output = ob_get_clean();
35
            $this->assertEquals(2, $e->getCode());
36
            $this->assertContains('0.00%', $output);
37
            return;
38
        }
39
        $this->fail("no exception thrown");
40
41
    }
42
43 View Code Duplication
    public function testNoValidLinesStrict()
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
testNoValidLinesStrict 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...
44
    {
45
        $GLOBALS['argv'] = [
46
            'phpunitDiffFilter',
47
            __DIR__ . '/fixtures/change.txt',
48
            __DIR__ . '/fixtures/phpmd-change.xml',
49
            '--strict',
50
        ];
51
        try {
52
            ob_start();
53
            require(__DIR__ . "/../src/runners/phpmdDiffFilter.php");
54
        } catch (Exception $e) {
55
            $output = ob_get_clean();
56
            $this->assertEquals(2, $e->getCode());
57
            $this->assertContains('0%', $output);
58
            return;
59
        }
60
61
        $this->fail("no exception thrown");
62
    }
63
}
64