Completed
Push — master ( 4c5f95...615c30 )
by Mahmoud
04:04
created

testUpdateExistingUserWithEmptyValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 19
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\User\UI\API\Tests\Functional;
4
5
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
6
7
/**
8
 * Class UpdateUserTest.
9
 *
10
 * @author Mahmoud Zalt <[email protected]>
11
 */
12
class UpdateUserTest extends TestCase
13
{
14
15
    private $endpoint = '/users';
16
17
    public function testUpdateExistingUser_()
18
    {
19
        $user = $this->getLoggedInTestingUser();
20
21
        $data = [
22
            'name'     => 'Updated Name',
23
            'password' => 'updated#Password',
24
        ];
25
26
        $endpoint = $this->endpoint . '/' . $user->id;
27
28
        // send the HTTP request
29
        $response = $this->apiCall($endpoint, 'put', $data);
30
31
        // assert response status is correct
32
        $this->assertEquals($response->getStatusCode(), '200');
33
34
        // assert returned user is the updated one
35
        $this->assertResponseContainKeyValue([
36
            'email' => $user->email,
37
            'name'  => $data['name'],
38
        ], $response);
39
40
        // assert data was updated in the database
41
        $this->seeInDatabase('users', ['name' => $data['name']]);
42
    }
43
44 View Code Duplication
    public function testUpdateExistingUserWithEmptyValues()
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...
45
    {
46
        $user = $this->getLoggedInTestingUser();
47
48
        $data = []; // empty data
49
50
        $endpoint = $this->endpoint . '/' . $user->id;
51
52
        // send the HTTP request
53
        $response = $this->apiCall($endpoint, 'put', $data);
54
55
        // assert response status is correct
56
        $this->assertEquals($response->getStatusCode(), '417');
57
58
        // assert message is correct
59
        $this->assertResponseContainKeyValue([
60
            'message' => 'All inputs are empty.',
61
        ], $response);
62
    }
63
64
    // TODO: after upgrading to Laravel 5.2 this function started returning 500 instead of 403
65
    // it could be due to something in `app/Port/Exception/Handler/ExceptionsHandler.php` and the don't report thingy
66
    // same problem as testDeleteDifferentUser
67
68
//    public function testUpdateDifferentUser_()
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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.

Loading history...
69
//    {
70
//        $data = [
71
//            'name'     => 'Updated Name',
72
//            'password' => 'updated#Password',
73
//        ];
74
//
75
//        $endpoint = $this->endpoint . '/' . 100; // amy ID
76
//
77
//        // send the HTTP request
78
//        $response = $this->apiCall($endpoint, 'put', $data);
79
//
80
//        // assert response status is correct
81
//        $this->assertEquals($response->getStatusCode(), '403');
82
//
83
//        // assert the message means (not allowed to proceed with the request)
84
//        $this->assertEquals($response->getContent(), 'Forbidden');
85
//    }
86
87
}
88