1+ <?php namespace tests ;
2+
3+
4+ use Atomx \AccountStore ;
5+ use Atomx \Resources \Report ;
6+
7+ class AtomxAccountStore implements AccountStore {
8+ private $ token = null ;
9+
10+ public function getToken ()
11+ {
12+ return $ this ->token ;
13+ }
14+
15+ public function storeToken ($ token )
16+ {
17+ $ this ->token = $ token ;
18+ }
19+
20+ public function getUsername ()
21+ {
22+ return '' ;
23+ }
24+
25+ public function getPassword ()
26+ {
27+ return '' ;
28+ }
29+
30+ public function getApiBase ()
31+ {
32+ return '' ;
33+ }
34+ }
35+
36+ class ReportTest extends \PHPUnit_Framework_TestCase {
37+ public function testCreateAndDownloadReport ()
38+ {
39+ $ from = date ('Y-m-d 00:00:00 ' , time () - 24 * 60 * 60 );
40+ $ to = date ('Y-m-d 00:00:00 ' , time ());
41+
42+ $ report = new Report (new AtomxAccountStore ());
43+ $ options = array (
44+ 'scope ' => 'advertiser ' ,
45+ 'groups ' => ['campaign_id ' , 'domain_id ' , 'day_timestamp ' ],
46+ 'sums ' => ['impressions ' , 'clicks ' , 'conversions ' , 'campaign_cost ' ],
47+ 'where ' => [['network_id ' , '== ' , '1 ' ]],
48+ 'from ' => $ from ,
49+ 'to ' => $ to ,
50+ 'timezone ' => 'UTC '
51+ );
52+
53+ // $report = $report->run($options);
54+
55+ //var_dump($report);
56+ }
57+
58+ public function testReportIsDone ()
59+ {
60+ $ report = new Report (new AtomxAccountStore ());
61+ $ rData = $ this ->getReportData ();
62+
63+ $ this ->assertEquals (true , $ report ->isReady ($ rData ));
64+ }
65+
66+ public function testDownloadReport ()
67+ {
68+ $ report = new Report (new AtomxAccountStore ());
69+ $ rData = $ this ->getReportData ();
70+
71+ $ streamer = $ report ->download ($ rData );
72+ var_dump ($ streamer ->readLine ());
73+ }
74+
75+ /**
76+ * @return array
77+ */
78+ private function getReportData ()
79+ {
80+ // TODO: Mock the response
81+ $ rData = [
82+ 'success ' => true ,
83+ 'timestamp ' => "2015-08-18T09:13:15.330011 " ,
84+ 'report ' => [
85+ 'error ' => NULL ,
86+ 'is_ready ' => true ,
87+ 'link ' => "/v1/report/7aae3048e3f54c327163c5ef25826abc " ,
88+ 'lines ' => 30003 ,
89+ 'id ' => "7aae3048e3f54c327163c5ef25826abc " ,
90+ 'started ' => 1439889079
91+ ]
92+ ];
93+ return $ rData ;
94+ }
95+ }
0 commit comments