1+ <?php
2+ require_once __DIR__ .'/baseTest.php ' ;
3+
4+ class SendGridTest_GlobalStats extends baseTest
5+ {
6+ public function testGET ()
7+ {
8+ $ code = 200 ;
9+ $ headers = array ('Content-Type ' => 'application/json ' );
10+ $ body = '[
11+ {
12+ "date": "2015-01-01",
13+ "stats": [
14+ {
15+ "metrics": {
16+ "blocks": 1,
17+ "bounce_drops": 0,
18+ "bounces": 0,
19+ "clicks": 0,
20+ "deferred": 1,
21+ "delivered": 1,
22+ "invalid_emails": 1,
23+ "opens": 1,
24+ "processed": 2,
25+ "requests": 3,
26+ "spam_report_drops": 0,
27+ "spam_reports": 0,
28+ "unique_clicks": 0,
29+ "unique_opens": 1,
30+ "unsubscribe_drops": 0,
31+ "unsubscribes": 0
32+ }
33+ }
34+ ]
35+ },
36+ {
37+ "date": "2015-01-02",
38+ "stats": [
39+ {
40+ "metrics": {
41+ "blocks": 0,
42+ "bounce_drops": 0,
43+ "bounces": 0,
44+ "clicks": 0,
45+ "deferred": 0,
46+ "delivered": 0,
47+ "invalid_emails": 0,
48+ "opens": 0,
49+ "processed": 0,
50+ "requests": 0,
51+ "spam_report_drops": 0,
52+ "spam_reports": 0,
53+ "unique_clicks": 0,
54+ "unique_opens": 0,
55+ "unsubscribe_drops": 0,
56+ "unsubscribes": 0
57+ }
58+ }
59+ ]
60+ }
61+ ] ' ;
62+
63+ $ sendgrid = $ this ->buildClient ($ code , $ headers , $ body );
64+ $ start_date = "2015-01-01 " ;
65+ $ response = $ sendgrid ->global_stats ->get ($ start_date );
66+ $ this ->assertEquals ($ code , $ response ->getStatusCode ());
67+ $ this ->assertEquals ($ body , $ response ->getBody ());
68+
69+ $ sendgrid = $ this ->buildClient ($ code , $ headers , $ body );
70+ $ end_date = "2015-01-02 " ;
71+ $ response = $ sendgrid ->global_stats ->get ($ start_date , $ end_date );
72+ $ this ->assertEquals ($ code , $ response ->getStatusCode ());
73+ $ this ->assertEquals ($ body , $ response ->getBody ());
74+
75+ $ sendgrid = $ this ->buildClient ($ code , $ headers , $ body );
76+ $ aggregated_by = "day " ;
77+ $ response = $ sendgrid ->global_stats ->get ($ start_date , $ end_date , $ aggregated_by );
78+ $ this ->assertEquals ($ code , $ response ->getStatusCode ());
79+ $ this ->assertEquals ($ body , $ response ->getBody ());
80+ }
81+
82+ }
0 commit comments