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
Comprehensibility
Best Practice
introduced
by
![]() |
|||
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 |