Completed
Push — master ( 291cbd...6aab68 )
by Adeniyi
09:08 queued 06:09
created

RoutesTest::testGetAllEmoji()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Ibonly\NaijaEmoji\Test;
4
5
use Guzzle\Http\Client;
6
use PHPUnit_Framework_TestCase;
7
use Guzzle\Http\Exception\ClientErrorResponseException;
8
9
class RoutesTest extends PHPUnit_Framework_TestCase
10
{
11
    public function setUp()
12
    {
13
        $this->client = new Client('https://emojinaija.herokuapp.com');
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->request = $this->client->get('/emojis');
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        $this->response = $this->request->send();
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
    }
17
18
    /**
19
     * Test the URL
20
     */
21
    public function testURL()
22
    {
23
        $this->assertEquals("https://emojinaija.herokuapp.com/emojis", $this->request->getUrl());
24
    }
25
26
    /**
27
     * Test if the ouput of getAll is an object
28
     */
29
    public function testGetAllEmoji()
30
    {
31
        $this->assertInternalType("object", $this->response->getBody());
32
        $this->assertEquals(200, $this->response->getStatusCode());
33
    }
34
35
    /**
36
     * Test get a single emoji endpoint
37
     */
38
    public function testGetSingleEmoji()
39
    {
40
        $endpoint = $this->client->get('emogis/5');
0 ignored issues
show
Unused Code introduced by
$endpoint is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
        $this->assertEquals(200, $this->response->getStatusCode());
42
    }
43
44
    /**
45
     * Test Post endpoint
46
     */
47
   public function testPOSTEmoji()
48
    {
49
        // create our http client (Guzzle)
50
        $data = array(
51
            'name' => 'Run',
52
            'char' => '🏃',
53
            'keywords' => "Run, Ere",
54
            'category' => 'force'
55
        );
56
57
        $this->setExpectedException("Guzzle\Http\Exception\ClientErrorResponseException");
58
        $request = $this->client->post('/emojis', null, json_encode($data));
59
        $response = $request->send();
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
    }
61
62
    /**
63
     * Test if Authorization Header is set
64
     */
65
    public function testHeaderAuthorizationNotSet()
66
    {
67
        $this->assertFalse(in_array('Host', array_keys($this->response->getHeaders()->toArray())
68
));
69
        $this->assertFalse($this->response->hasHeader("Authorization"));
70
    }
71
72
    /**
73
     * Test PUT/PATCH emoji
74
     */
75
    public function testPutPatchEmoji()
76
    {
77
        $data = array(
78
            'name' => 'Run',
79
        );
80
81
        $this->setExpectedException("Guzzle\Http\Exception\ClientErrorResponseException");
82
        $request = $this->client->put('/emojis/2', null, json_encode($data));
0 ignored issues
show
Unused Code introduced by
$request is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
83
        $request = $this->client->patch('/emojis/2', null, json_encode($data));
84
        $response = $request->send();
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
85
    }
86
}