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

SetEmailTest::testSetUserEmail_()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\Email\UI\API\Tests\Functional;
4
5
use App\Containers\Email\Mails\ConfirmEmail;
6
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
7
8
/**
9
 * Class SetEmailTest.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class SetEmailTest extends TestCase
14
{
15
16
    private $endpoint = '/users/{id}/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
        $user = $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('setEmail')->once()->withAnyArgs();
37
        $confirmEmail->shouldReceive('setName')->once()->withAnyArgs();
38
39
        $this->endpoint = str_replace("{id}", $user->id, $this->endpoint);
40
41
        // send the HTTP request
42
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
43
44
        // assert response status is correct
45
        $this->assertEquals($response->getStatusCode(), '202');
46
47
    }
48
49
}
50