Passed
Push — master ( 31de2d...8df2bc )
by Scott
33s
created

GenericDiffFilterTest::testMissingHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace exussum12\CoverageChecker\tests;
3
4
use PHPUnit\Framework\TestCase;
5
6
class GenericDiffFilterTest extends TestCase
7
{
8
9
    public function testValid()
0 ignored issues
show
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...
10
    {
11
        $GLOBALS['argv'] = [
12
            'diffFilter',
13
            '--phpcs',
14
            __DIR__ . '/fixtures/change.txt',
15
            __DIR__ . '/fixtures/phpcs.json'
16
        ];
17
        ob_start();
18
        require(__DIR__ . "/../src/Runners/generic.php");
19
        $output = ob_get_clean();
20
        $this->assertContains('100.00%', $output);
21
    }
22
23
    public function testMissingHandler()
0 ignored issues
show
Coding Style introduced by
testMissingHandler 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
        $this->expectException("Exception");
26
27
        $GLOBALS['argv'] = [
28
            'diffFilter',
29
            __DIR__ . '/fixtures/change.txt',
30
            __DIR__ . '/fixtures/phpcs.json'
31
        ];
32
        require(__DIR__ . "/../src/Runners/generic.php");
33
    }
34
}
35