This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Ibonly\NaijaEmoji\Test; |
||
4 | |||
5 | use Dotenv\Dotenv; |
||
6 | use GuzzleHttp\Client; |
||
7 | use Ibonly\NaijaEmoji\Emoji; |
||
8 | use PHPUnit_Framework_TestCase; |
||
9 | use Ibonly\NaijaEmoji\AuthController; |
||
10 | use GuzzleHttp\Exception\ClientException; |
||
11 | |||
12 | class RoutesTest extends PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | protected $url; |
||
15 | protected $token; |
||
16 | protected $client; |
||
17 | |||
18 | public function __construct () |
||
19 | { |
||
20 | $this->emoji = new Emoji(); |
||
0 ignored issues
–
show
|
|||
21 | $auth = new AuthController(); |
||
22 | |||
23 | $this->token = $auth->getTestToken(); |
||
24 | $this->url = $auth->getAuthUrl(); |
||
25 | } |
||
26 | |||
27 | public function setUp () |
||
28 | { |
||
29 | $this->client = new Client(); |
||
30 | } |
||
31 | |||
32 | public function getTestId () |
||
33 | { |
||
34 | return $this->emoji->where(['name' => 'TestName'])->getData('id'); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * testInvalidEndpoint |
||
39 | */ |
||
40 | public function testInvalidEndpoint() |
||
41 | { |
||
42 | $this->setExpectedException("GuzzleHttp\Exception\ClientException"); |
||
43 | |||
44 | $request = $this->client->request('GET', $this->url.'/emogis'); |
||
0 ignored issues
–
show
$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 ![]() |
|||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Test if the ouput of getAll is an object |
||
49 | */ |
||
50 | View Code Duplication | public function testGetAllEmoji () |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
51 | { |
||
52 | $request = $this->client->request('GET', $this->url.'/emojis'); |
||
53 | |||
54 | $this->assertInternalType("object", $request->getBody()); |
||
55 | $this->assertEquals(200, $request->getStatusCode()); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Test get a single emoji endpoint |
||
60 | */ |
||
61 | View Code Duplication | public function testGetSingleEmoji () |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
62 | { |
||
63 | $request = $this->client->request('GET', $this->url.'/emojis/3'); |
||
64 | |||
65 | $this->assertInternalType("object", $request->getBody()); |
||
66 | $this->assertEquals(200, $request->getStatusCode()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Test Post endpoint |
||
71 | */ |
||
72 | public function testPOSTEmoji() |
||
73 | { |
||
74 | $data = array( |
||
75 | 'name' => 'TestEmojiName', |
||
76 | 'char' => '🎃', |
||
77 | 'keywords' => "apple, friut, mac", |
||
78 | 'category' => 'fruit' |
||
79 | ); |
||
80 | $request = $this->client->request('POST', $this->url.'/emojis',[ 'headers' => ['Authorization'=> $this->token],'form_params' => $data ]); |
||
81 | |||
82 | $this->assertInternalType('object' , $request); |
||
83 | $this->assertEquals('200', $request->getStatusCode()); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Test if Authorization Header is set |
||
88 | */ |
||
89 | public function testPostIfAuthorizationNotSet () |
||
90 | { |
||
91 | $data = array( |
||
92 | 'name' => 'TestEmojiName', |
||
93 | 'char' => '🎃', |
||
94 | 'keywords' => "apple, friut, mac", |
||
95 | 'category' => 'fruit' |
||
96 | ); |
||
97 | |||
98 | $this->setExpectedException("GuzzleHttp\Exception\ClientException"); |
||
99 | |||
100 | $request = $this->client->request('POST', $this->url.'/emojis', ['form_params' => $data]); |
||
0 ignored issues
–
show
$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 ![]() |
|||
101 | |||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Test PUT/PATCH emoji |
||
106 | */ |
||
107 | public function testPutPatchEmoji () |
||
108 | { |
||
109 | $data = array( |
||
110 | 'name' => 'TestName' |
||
111 | ); |
||
112 | $request = $this->client->request('PUT', $this->url.'/emojis/'.$this->getTestId(),[ 'headers' => ['Authorization'=> $this->token],'form_params' => $data ]); |
||
113 | |||
114 | $this->assertInternalType('object' , $request); |
||
115 | $this->assertEquals('200', $request->getStatusCode()); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Test DELETE an emoji |
||
120 | */ |
||
121 | public function testDeleteEmoji() |
||
122 | { |
||
123 | |||
124 | $this->assertInternalType('integer', $this->getTestId()); |
||
125 | // $data = array( |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% 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. ![]() |
|||
126 | // 'id' => '1' |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% 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. ![]() |
|||
127 | // ); |
||
128 | // $this->request = $this->client->get('/emojis'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
57% 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. ![]() |
|||
129 | // $request = $this->client->delete('/emojis/2', $this->request->getUrl(), json_encode($data)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% 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. ![]() |
|||
130 | // $response = $request->send(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
55% 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. ![]() |
|||
131 | // $this->assertEquals(406, $response->getStatusCode()); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
74% 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. ![]() |
|||
132 | } |
||
133 | } |
||
134 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: