BaseTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 4
dl 0
loc 47
ccs 29
cts 29
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAppLoadsSecondaryRoute() 0 14 1
A testAppResolvesDatabaseService() 0 12 1
A testAppWorks() 0 16 1
1
<?php
2
3
namespace App\Tests;
4
5
use Fyuze\Kernel\Application\Web;
6
use PHPUnit\Framework\TestCase;
7
8
class BaseTest extends TestCase
9
{
10 1
    public function testAppWorks()
11
    {
12
        // Will eventually be
13
        // $request = $this->createRequest('/');
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
        // $this->assertResponse(200);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
15
        //
16 1
        $path = realpath(__DIR__ . '/../../../');
17 1
        $app = new Web($path);
18 1
        $response = $app->boot();
19
20 1
        $app->getContainer()->dump();
21
22 1
        $this->assertInstanceOf('Fyuze\Http\Response', $response);
23 1
        $this->assertEquals(200, $response->getStatusCode());
24 1
        $this->assertEquals('<body>Welcome to Fyuze!</body>', (string)$response->getBody());
25 1
    }
26
27 1
    public function testAppLoadsSecondaryRoute()
0 ignored issues
show
Coding Style introduced by
testAppLoadsSecondaryRoute 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...
28
    {
29 1
        $path = realpath(__DIR__ . '/../../../');
30 1
        $app = new Web($path);
31 1
        $_SERVER['REQUEST_URI'] = '/hello/Matthew';
32 1
        $response = $app->boot();
33 1
        unset($_SERVER['REQUEST_URI']);
34
35 1
        $app->getContainer()->dump();
36
37 1
        $this->assertInstanceOf('Fyuze\Http\Response', $response);
38 1
        $this->assertEquals(200, $response->getStatusCode());
39 1
        $this->assertEquals('<body>Hello, Matthew!</body>', (string)$response->getBody());
40 1
    }
41
42 1
    public function testAppResolvesDatabaseService()
0 ignored issues
show
Coding Style introduced by
testAppResolvesDatabaseService 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...
43
    {
44 1
        $path = realpath(__DIR__ . '/../../../');
45 1
        $app = new Web($path);
46 1
        $_SERVER['REQUEST_URI'] = '/database';
47 1
        $response = $app->boot();
48 1
        unset($_SERVER['REQUEST_URI']);
49
50 1
        $this->assertInstanceOf('Fyuze\Http\Response', $response);
51
        //$this->assertEquals(200, $response->getStatusCode());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52 1
        $this->assertEquals('{"name":"matthew"}', (string)$response->getBody());
53 1
    }
54
}
55