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.

GetResourceControllerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 86
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testGet() 0 24 1
A testGetNotFound() 0 19 1
A testGetError() 0 23 1
1
<?php
2
3
namespace JDesrosiers\Resourceful\Controller\Test;
4
5
use JDesrosiers\Resourceful\Controller\GetResourceController;
6
use JDesrosiers\Resourceful\Resourceful;
7
use PHPUnit_Framework_TestCase;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\Client;
10
11
class GetResourceControllerTest extends PHPUnit_Framework_TestCase
12
{
13
    private $app;
14
    private $service;
15
    private $client;
16
17
    public function setUp()
18
    {
19
        $this->app = new Resourceful();
20
        $this->app["debug"] = true;
21
22
        $this->service = $this->getMockBuilder("Doctrine\Common\Cache\Cache")->getMock();
23
        $this->app->get("/foo/{id}", new GetResourceController($this->service));
24
25
        $this->client = new Client($this->app);
26
    }
27
28
    public function testGet()
29
    {
30
        $foo = new \stdClass();
31
        $foo->id = "4ee8e29d45851";
32
33
        $this->service->method("contains")
34
            ->with("/foo/4ee8e29d45851")
35
            ->willReturn(true);
36
37
        $this->service->method("fetch")
38
            ->with("/foo/4ee8e29d45851")
39
            ->willReturn($foo);
40
41
        $headers = [
42
            "HTTP_ACCEPT" => "application/json",
43
        ];
44
        $this->client->request("GET", "/foo/4ee8e29d45851", [], [], $headers);
45
        $response = $this->client->getResponse();
46
47
        $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
48
        $this->assertEquals("application/json", $response->headers->get("Content-Type"));
49
        $this->assertEquals("GET", $response->headers->get("Allow"));
50
        $this->assertJsonStringEqualsJsonString('{"id":"4ee8e29d45851"}', $response->getContent());
51
    }
52
53
    public function testGetNotFound()
54
    {
55
        $this->service->method("contains")
56
            ->with("/foo/4ee8e29d45851")
57
            ->willReturn(false);
58
59
        $this->app->error(function (\Exception $e, $code) {
0 ignored issues
show
Unused Code introduced by
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
            $this->assertEquals("Not Found", $e->getMessage());
61
        });
62
63
        $headers = [
64
            "HTTP_ACCEPT" => "application/json",
65
        ];
66
        $this->client->request("GET", "/foo/4ee8e29d45851", [], [], $headers);
67
        $response = $this->client->getResponse();
68
69
        $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
70
        $this->assertFalse($response->headers->has("Allow"));
71
    }
72
73
    public function testGetError()
74
    {
75
        $this->service->method("contains")
76
            ->with("/foo/4ee8e29d45851")
77
            ->willReturn(true);
78
79
        $this->service->method("fetch")
80
            ->with("/foo/4ee8e29d45851")
81
            ->willReturn(false);
82
83
        $this->app->error(function (\Exception $e, $code) {
0 ignored issues
show
Unused Code introduced by
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
            $this->assertEquals("Failed to retrieve resource", $e->getMessage());
85
        });
86
87
        $headers = [
88
            "HTTP_ACCEPT" => "application/json",
89
        ];
90
        $this->client->request("GET", "/foo/4ee8e29d45851", [], [], $headers);
91
        $response = $this->client->getResponse();
92
93
        $this->assertEquals(Response::HTTP_SERVICE_UNAVAILABLE, $response->getStatusCode());
94
        $this->assertFalse($response->headers->has("Allow"));
95
    }
96
}
97