| Conditions | 1 |
| Paths | 1 |
| Total Lines | 32 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function testContactUs() |
||
| 20 | { |
||
| 21 | $visitor = $this->getVisitor(); |
||
| 22 | |||
| 23 | $headers['visitor-id'] = $visitor->visitor_id; |
||
|
|
|||
| 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'); |
||
| 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 | |||
| 53 |
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:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.