GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#9)
by Helpful
09:13
created

DebugErrorReporterTest::testReportErrorLive()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 41
rs 8.8571
cc 1
eloc 27
nc 1
nop 0
1
<?php
2
3
namespace Camspiers\LoggerBridge;
4
5
use Camspiers\LoggerBridge\ErrorReporter\DebugErrorReporter;
6
use Config;
7
8
class DebugErrorReporterTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function testReportErrorNotLive()
11
    {
12
        Config::inst()->update('SS_Backtrace', 'ignore_function_args', array());
13
14
        $envMock = $this->getMock(__NAMESPACE__.'\EnvReporter\EnvReporter');
15
16
        $envMock->expects($this->once())
17
            ->method('isLive')
18
            ->will($this->returnValue(false));
19
20
        $debugErrorReporter = new DebugErrorReporter($envMock);
21
22
        ob_start();
23
24
        $debugErrorReporter->reportError(
25
            new \ErrorException(
26
                'Error message',
27
                E_USER_ERROR,
28
                0,
29
                'example-file.php',
30
                10
31
            )
32
        );
33
34
        $contents = ob_get_contents();
35
        ob_end_clean();
36
37
        $this->assertContains(
38
            '[User Error]',
39
            $contents
40
        );
41
42
        $this->assertContains(
43
            'Error message',
44
            $contents
45
        );
46
47
        $this->assertContains(
48
            'Line 10 in example-file.php',
49
            $contents
50
        );
51
    }
52
53
    public function testReportErrorLive()
0 ignored issues
show
Coding Style introduced by
testReportErrorLive uses the super-global variable $_SERVER 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
        Config::inst()->update('Director', 'alternate_base_url', 'http://localhost');
56
        define('BASE_URL', 'http://localhost/');
57
        define('FRAMEWORK_DIR', 'framework');
58
        $_SERVER['REQUEST_METHOD'] = 'GET';
59
        $_SERVER['REQUEST_URI'] = '/';
60
61
        Config::inst()->update('SS_Backtrace', 'ignore_function_args', array());
62
63
        $envMock = $this->getMock(__NAMESPACE__.'\EnvReporter\EnvReporter');
64
65
        $envMock->expects($this->once())
66
            ->method('isLive')
67
            ->will($this->returnValue(true));
68
69
        $debugErrorReporter = new DebugErrorReporter($envMock);
70
71
        ob_start();
72
73
        $debugErrorReporter->reportError(
74
            new \ErrorException(
75
                'Error message',
76
                E_USER_ERROR,
77
                0,
78
                'example-file.php',
79
                10
80
            )
81
        );
82
83
        $contents = ob_get_contents();
84
        ob_end_clean();
85
86
        $this->assertEquals(
87
            <<<HTML
88
<!DOCTYPE html><html><head><title>GET /</title><link rel="stylesheet" type="text/css" href="http://localhost/framework/css/debug.css" /></head><body><div class="info"><h1>Website Error</h1></div></body></html>
89
HTML
90
            ,
91
            $contents
92
        );
93
    }
94
}
95