|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @mixin PHPUnit_Framework_TestCase |
|
5
|
|
|
*/ |
|
6
|
|
|
class RatingApiControllerTest extends FunctionalTest |
|
7
|
|
|
{ |
|
8
|
|
|
protected static $fixture_file = 'RatingApiControllerTest.yml'; |
|
9
|
|
|
|
|
10
|
|
View Code Duplication |
public function testErrorWhenMissingParams() |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
$response = $this->get('api/rating'); |
|
13
|
|
|
|
|
14
|
|
|
$this->assertJson($response->getBody()); |
|
15
|
|
|
|
|
16
|
|
|
$result = json_decode($response->getBody()); |
|
17
|
|
|
$this->assertFalse($result->success); |
|
18
|
|
|
$this->assertContains('Missing', $result->message); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
View Code Duplication |
public function testErrorWhenModuleNotFound() |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$response = $this->get('api/rating/bar/baz'); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertJson($response->getBody()); |
|
26
|
|
|
|
|
27
|
|
|
$result = json_decode($response->getBody()); |
|
28
|
|
|
$this->assertFalse($result->success); |
|
29
|
|
|
$this->assertContains('not be found', $result->message); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
public function testResponseIncludesRating() |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$response = $this->get('api/rating/foo/bar'); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertJson($response->getBody()); |
|
37
|
|
|
|
|
38
|
|
|
$result = json_decode($response->getBody()); |
|
39
|
|
|
$this->assertTrue($result->success); |
|
40
|
|
|
$this->assertSame(53, $result->rating); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
View Code Duplication |
public function testDetailedResponse() |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$response = $this->get('api/rating/foo/bar?detailed'); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertJson($response->getBody()); |
|
48
|
|
|
|
|
49
|
|
|
$result = json_decode($response->getBody()); |
|
50
|
|
|
$this->assertTrue($result->success); |
|
51
|
|
|
$this->assertSame(3, $result->metrics->coverage); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
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.