Skip to content

Commit d02dbd0

Browse files
committed
Improved/added tests
1 parent 2778a27 commit d02dbd0

2 files changed

Lines changed: 128 additions & 0 deletions

File tree

tests/ReportStreamerTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace tests;
2+
3+
4+
use Atomx\ReportStreamer;
5+
use GuzzleHttp\Stream\Stream;
6+
7+
class ReportStreamerTest extends \PHPUnit_Framework_TestCase {
8+
public function testGetLineAndOverflow()
9+
{
10+
$stream = Stream::factory("test\t123\ntest2\t123");
11+
12+
$streamer = new ReportStreamer($stream);
13+
14+
$line = $streamer->readLine();
15+
$line2 = $streamer->readLine();
16+
17+
$this->assertEquals(['test', 123], $line);
18+
$this->assertEquals(['test2', 123], $line2);
19+
}
20+
21+
public function testBreakEnd()
22+
{
23+
$stream = Stream::factory("test\t\ntest2\n");
24+
25+
$streamer = new ReportStreamer($stream);
26+
27+
$line = $streamer->readLine();
28+
$line2 = $streamer->readLine();
29+
30+
$this->assertEquals(["test", ''], $line);
31+
$this->assertEquals(["test2"], $line2);
32+
}
33+
}

tests/ReportTest.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)