|
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 SetUserEmailTest. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class SetUserEmailTest 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
|
|
|
$this->assertResponseContainKeyValue(['message' => 'User Email Saved Successfully.'], $response); |
|
48
|
|
|
|
|
49
|
|
|
$this->seeInDatabase('users', ['email' => $data['email']]); |
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|