Completed
Push — master ( 857394...4794c5 )
by Mahmoud
03:25
created

SetUserEmailTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSetUserEmail_() 0 31 1
1
<?php
2
3
namespace App\Containers\Email\UI\API\Tests\Functional;
4
5
use App\Containers\Email\Mails\ConfirmEmail;
6
use App\Port\Test\PHPUnit\Abstracts\TestCase;
7
8
/**
9
 * Class SetUserEmailTest.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class SetUserEmailTest extends TestCase
14
{
15
16
    private $endpoint = '/users/email';
17
18
    public function testSetUserEmail_()
19
    {
20
        $userDetails = [
21
            'email'    => '[email protected]',
22
            'name'     => 'Hello',
23
            'password' => 'secret',
24
        ];
25
26
        // get the logged in user (create one if no one is logged in)
27
        $this->registerAndLoginTestingUser($userDetails);
28
29
        $data = [
30
            'email' => '[email protected]',
31
        ];
32
33
        // mock sending real emails
34
        $confirmEmail = $this->mock(ConfirmEmail::class);
35
        $confirmEmail->shouldReceive('send')->once()->withAnyArgs()->andReturn(true);
36
        $confirmEmail->shouldReceive('to')->once()->withAnyArgs()->andReturn($confirmEmail);
37
38
        // send the HTTP request
39
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
40
41
        // assert response status is correct
42
        $this->assertEquals($response->getStatusCode(), '202');
43
44
        $this->assertResponseContainKeyValue(['message' => 'User Email Saved Successfully.'], $response);
45
46
        $this->seeInDatabase('users', ['email' => $data['email']]);
47
48
    }
49
50
}
51