TestCaseUserController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testListUsers() 7 7 1
A testUserById() 7 7 1
A testCreateUserView() 7 7 1
A testStoreUser() 0 10 1
A testPatchUserById() 0 11 1
A testDeleteUserById() 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 Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Preetender\Routing\Testing\HttpInteraction;
7
8
/**
9
 * Class TestCaseUserController
10
 * @package Tests
11
 */
12
class TestCaseUserController extends TestCase
13
{
14
    use HttpInteraction;
15
16
    /**
17
     * @inheritdoc
18
     */
19 View Code Duplication
    public function testListUsers()
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...
20
    {
21
        $http = $this->http->get('users');
22
        $output = $http->getBody()->getContents();
23
        $this->assertEquals(200, $http->getStatusCode());
24
        $this->assertEquals('list all users', $output);
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 View Code Duplication
    public function testUserById()
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...
31
    {
32
        $http = $this->http->get('users/1');
33
        $output = $http->getBody()->getContents();
34
        $this->assertEquals(200, $http->getStatusCode());
35
        $this->assertEquals('show user by id 1', $output);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 View Code Duplication
    public function testCreateUserView()
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...
42
    {
43
       $http = $this->http->get('users/create');
44
       $output = $http->getBody()->getContents();
45
       $this->assertEquals(200, $http->getStatusCode());
46
       $this->assertEquals('view create user', $output);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function testStoreUser()
53
    {
54
        $http = $this->http->post('users', [
55
            'form_params' => [
56
                'name' => 'test',
57
                'email' => '[email protected]'
58
            ]
59
        ]);
60
        $this->assertEquals(201, $http->getStatusCode());
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function testPatchUserById()
67
    {
68
        $http = $this->http->patch('users/edit/1', [
69
            'form_params' => [
70
                'name' => 'test'
71
            ]
72
        ]);
73
        $output = $http->getBody()->getContents();
74
        $this->assertEquals(200, $http->getStatusCode());
75
        $this->assertEquals('{"body":"update part of user 1","data":{"name":"test"}}', $output);
76
    }
77
78
    /**
79
     * @inheritdoc
80
     */
81 View Code Duplication
    public function testDeleteUserById()
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...
82
    {
83
        $http = $this->http->delete('users/1');
84
        $output = $http->getBody()->getContents();
85
        $this->assertEquals(200, $http->getStatusCode());
86
        $this->assertEquals('delete user by id 1', $output);
87
    }
88
}