Completed
Push — issue/AZ_53_respond_to_spam_ev... ( b7bb66...684b25 )
by Dominik
02:16
created

MailgunEventTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCannotSetAsUnknown() 0 10 1
A testSetMessageHeaders() 0 11 1
A messageHeadersJsonString() 0 17 1
1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\Tests\Entity;
4
5
use Azine\MailgunWebhooksBundle\Entity\MailgunEvent;
6
7
class MailgunEventTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * Do not allow country or region to be set to 'Unknown'
11
     */
12
    public function testCannotSetAsUnknown()
13
    {
14
        $event = new MailgunEvent();
15
16
        $event->setCountry('Unknown');
17
        $this->assertNull($event->getCountry());
18
19
        $event->setRegion('Unknown');
20
        $this->assertNull($event->getRegion());
21
    }
22
23
    /**
24
     * Test decoding of Json into messageHeaders property
25
     *
26
     * @dataProvider messageHeadersJsonString
27
     *
28
     * @param string $jsonStringHeaders
29
     */
30
    public function testSetMessageHeaders($jsonStringHeaders)
31
    {
32
        // force strict error-checking. PHPunit will convert to exceptions
33
        $oldErrorlevel = error_reporting(-1);
34
35
        $event = new MailgunEvent();
36
        $actual = $event->setMessageHeaders($jsonStringHeaders);
37
        $this->assertSame($event, $actual);
38
39
        error_reporting($oldErrorlevel);
40
    }
41
42
    /**
43
     * Return sample JSON strings to be decoded.
44
     *
45
     * @return array one or more strings of JSON to parse
46
     */
47
    public function messageHeadersJsonString()
48
    {
49
        $tests[0][] = <<<'EOT'
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tests was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tests = 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...
50
{"geolocation":{"country":"Unknown","region":"Unknown","city":"Unknown"},
51
"tags":[],"ip":"12.123.12.12","log-level":"info","id":"_mGv6HusfhsdbjnR-wGGzx",
52
"campaigns":[],"user-variables":{},"recipient-domain":"example.com",
53
"timestamp":1506682072.767605,
54
"client-info":{"client-os":"Windows","device-type":"desktop","client-name":"Firefox",
55
"client-type":"browser",
56
"user-agent":"Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)"},
57
"message":{"headers":{
58
"message-id":"[email protected]"}},
59
"recipient":"[email protected]","event":"opened"}
60
EOT;
61
62
        return $tests;
63
    }
64
}
65