11<?php namespace tests ;
22
3-
4- use Atomx \AccountStore ;
53use 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- }
4+ require_once ('AtomxAccountStore.php ' );
355
366class ReportTest extends \PHPUnit_Framework_TestCase {
377 public function testCreateAndDownloadReport ()
@@ -44,23 +14,25 @@ public function testCreateAndDownloadReport()
4414 'scope ' => 'advertiser ' ,
4515 'groups ' => ['campaign_id ' , 'domain_id ' , 'day_timestamp ' ],
4616 'sums ' => ['impressions ' , 'clicks ' , 'conversions ' , 'campaign_cost ' ],
47- 'where ' => [['network_id ' , '== ' , '1 ' ]],
17+ 'where ' => [['advertiser_network_id ' , '== ' , '1 ' ]],
4818 'from ' => $ from ,
4919 'to ' => $ to ,
5020 'timezone ' => 'UTC '
5121 );
5222
53- // $report = $report->run($options);
23+ // $report = $report->run($options);
5424
55- //var_dump ($report);
25+ //var_export ($report);
5626 }
5727
5828 public function testReportIsDone ()
5929 {
6030 $ report = new Report (new AtomxAccountStore ());
61- $ rData = $ this ->getReportData ();
31+ $ rData = $ report -> status (Report:: getReportId ( $ this ->getReportData ()) );
6232
63- $ this ->assertEquals (true , $ report ->isReady ($ rData ));
33+ var_dump ($ rData );
34+
35+ $ this ->assertEquals (true , Report::isReady ($ rData ));
6436 }
6537
6638 public function testDownloadReport ()
@@ -69,7 +41,21 @@ public function testDownloadReport()
6941 $ rData = $ this ->getReportData ();
7042
7143 $ streamer = $ report ->download ($ rData );
44+
45+ var_dump (Report::numberOfRows ($ rData ));
46+ var_dump (Report::getColumns ($ rData ));
47+
7248 var_dump ($ streamer ->readLine ());
49+
50+ $ imps = 0 ;
51+ $ revenue = 0 ;
52+
53+ while (($ row = $ streamer ->readLine ()) !== false ) {
54+ $ imps += $ row [3 ];
55+ $ revenue += $ row [6 ];
56+ }
57+
58+ var_dump ($ imps , $ revenue );
7359 }
7460
7561 /**
@@ -79,17 +65,50 @@ private function getReportData()
7965 {
8066 // TODO: Mock the response
8167 $ 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- ];
68+ 'success ' => true ,
69+ 'timestamp ' => '2015-09-23T15:30:38.563796 ' ,
70+ 'report ' =>
71+ [
72+ 'link ' => '/v1/report/89130c7cd76c7637195224529bbae9c7 ' ,
73+ 'duration ' => NULL ,
74+ 'started ' => 1443022238 ,
75+ 'lines ' => 0 ,
76+ 'error ' => NULL ,
77+ 'finished ' => NULL ,
78+ 'fast ' => true ,
79+ 'is_ready ' => true ,
80+ 'id ' => '89130c7cd76c7637195224529bbae9c7 ' ,
81+ ],
82+ 'query ' =>
83+ [
84+ 'from ' => '2015-09-22 00:00:00 ' ,
85+ 'timezone ' => 'UTC ' ,
86+ 'sums ' =>
87+ array (
88+ 0 => 'impressions ' ,
89+ 1 => 'clicks ' ,
90+ 2 => 'conversions ' ,
91+ 3 => 'campaign_cost ' ,
92+ ),
93+ 'groups ' =>
94+ array (
95+ 0 => 'campaign_id ' ,
96+ 1 => 'domain_id ' ,
97+ 2 => 'day_timestamp ' ,
98+ ),
99+ 'to ' => '2015-09-23 00:00:00 ' ,
100+ 'where ' =>
101+ array (
102+ 0 =>
103+ array (
104+ 0 => 'advertiser_network_id ' ,
105+ 1 => '== ' ,
106+ 2 => '1 ' ,
107+ ),
108+ ),
109+ 'scope ' => 'advertiser '
110+ ]
111+ ];
93112 return $ rData ;
94113 }
95114}
0 commit comments