Completed
Push — master ( 33e787...10dfaa )
by Mahmoud
03:41
created

ContactUsTest::testContactUs()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\Contact\UI\API\Tests\Functional;
4
5
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
6
use Illuminate\Support\Facades\Config;
7
use Mail;
8
9
/**
10
 * Class SampleTest.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class ContactUsTest extends TestCase
15
{
16
17
    private $endpoint = '/contact';
18
19
    public function testContactUs()
20
    {
21
        $visitor = $this->getVisitor();
22
23
        $headers['visitor-id'] = $visitor->visitor_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$headers was never initialized. Although not strictly required by PHP, it is generally a good practice to add $headers = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
24
25
        $data = [
26
            'email'   => '[email protected]',
27
            'message' => 'I just want to tell you this App is awesome.',
28
            'name'    => 'Cool User',
29
            'subject' => 'Thank you RewardFox',
30
        ];
31
32
33
        // TODO NOW:
34
        // 3. RUN ALL TESTS AND FIX EVERYTHING
35
        // 4. MERGE WITH HELLO API
36
        // 5. PUSH HELLO API + MARKETPLACE + REWARD FIX
37
        // 6. MOVE TO ANOTHER TASK...
38
39
        // mock sending emails
40
        Mail::shouldReceive('queue')->once()->andReturn('true');
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Illuminate\Mail\Mailer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
42
        Config::set('mail.to.address', '[email protected]');
43
        Config::set('mail.to.name', 'Mahmoud');
44
45
        $response = $this->apiCall($this->endpoint, 'post', $data, false, $headers);
46
47
        $this->assertEquals($response->getStatusCode(), '202');
48
49
        $this->assertResponseContainKeyValue(['message' => 'Message sent Successfully.'], $response);
50
    }
51
52
}
53