Failed Conditions
Push — master ( b9670c...4ba57f )
by Zac
16:20 queued 37s
created

ApiControllerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 59.68 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 37
loc 62
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetResults() 12 12 1
A testGetResultsInsufficentPerms() 0 7 1
A testGetRecentGroupResults() 0 10 1
A testGetRecentGroupResultsInsufficentPerms() 7 7 1
A testGetResultsForTest() 11 11 1
A testGetResultsForTestInsufficentPerms() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Overwatch\ResultBundle\Tests\Controller;
4
5
use Overwatch\ResultBundle\DataFixtures\ORM\TestResultFixtures;
6
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures;
7
use Overwatch\TestBundle\DataFixtures\ORM\TestGroupFixtures;
8
use Overwatch\UserBundle\Tests\Base\DatabaseAwareTestCase;
9
10
/**
11
 * ApiControllerTest
12
 * Functional test of API methods provided by the APIController
13
 */
14
class ApiControllerTest extends DatabaseAwareTestCase
15
{
16 View Code Duplication
    public function testGetResults()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
17
    {
18
        $this->logIn('ROLE_SUPER_ADMIN');
19
        $this->client->request('GET', '/api/results');
20
21
        $this->assertJsonResponse($this->client->getResponse());
22
        $this->assertCount(4, $this->getResponseContent());
23
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-1'], $this->getResponseContent());
24
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-2'], $this->getResponseContent());
25
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $this->getResponseContent());
26
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-4'], $this->getResponseContent());
27
    }
28
29
    public function testGetResultsInsufficentPerms()
30
    {
31
        $this->logIn('ROLE_ADMIN');
32
        $this->client->request('GET', '/api/results');
33
34
        $this->assertForbidden($this->client->getResponse());
35
    }
36
37
    public function testGetRecentGroupResults()
38
    {
39
        $this->logIn('ROLE_SUPER_ADMIN');
40
        $this->client->request('GET', '/api/results/group/' . TestGroupFixtures::$groups['group-1']->getId());
41
42
        $this->assertJsonResponse($this->client->getResponse());
43
        $this->assertCount(2, $this->getResponseContent());
44
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $this->getResponseContent());
45
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-4'], $this->getResponseContent());
46
    }
47
48 View Code Duplication
    public function testGetRecentGroupResultsInsufficentPerms()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
49
    {
50
        $this->logIn('ROLE_ADMIN');
51
        $this->client->request('GET', '/api/results/group/' . TestGroupFixtures::$groups['group-1']->getId());
52
53
        $this->assertForbidden($this->client->getResponse());
54
    }
55
56 View Code Duplication
    public function testGetResultsForTest()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
57
    {
58
        $this->logIn('ROLE_SUPER_ADMIN');
59
        $this->client->request('GET', '/api/results/test/' . TestFixtures::$tests['test-1']->getId());
60
61
        $this->assertJsonResponse($this->client->getResponse());
62
        $this->assertCount(3, $this->getResponseContent());
63
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-1'], $this->getResponseContent());
64
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-2'], $this->getResponseContent());
65
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $this->getResponseContent());
66
    }
67
68 View Code Duplication
    public function testGetResultsForTestInsufficentPerms()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
69
    {
70
        $this->logIn('ROLE_ADMIN');
71
        $this->client->request('GET', '/api/results/test/' . TestFixtures::$tests['test-1']->getId());
72
73
        $this->assertForbidden($this->client->getResponse());
74
    }
75
}
76