Dns analytics report (#121)
* Add DNS Analytics report endpoint Add DNS Analytics report endpoint Add DNS Analytics report endpoint * Remove useless response error test * Add tests for DNS analytics report class methods * Implement methods for listing grouped by time metrics report
This commit is contained in:
committed by
GitHub
parent
06de5b0c04
commit
ffc3989607
91
tests/Endpoints/DNSAnalyticsTest.php
Normal file
91
tests/Endpoints/DNSAnalyticsTest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Visual Studio Code.
|
||||
* User: elliot.alderson
|
||||
* Date: 10/02/2020
|
||||
* Time: 04:28 AM
|
||||
*/
|
||||
class DNSAnalyticsTest extends TestCase
|
||||
{
|
||||
public function testGetDNSAnalyticsReportTable()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture(
|
||||
'Endpoints/getDNSAnalyticsReportTable.json'
|
||||
);
|
||||
|
||||
$mock = $this->getMockBuilder(
|
||||
\Cloudflare\API\Adapter\Adapter::class
|
||||
)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo(
|
||||
'zones/023e105f4ecef8ad9ca31a8372d0c353/dns_analytics/report'
|
||||
)
|
||||
);
|
||||
|
||||
$analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
|
||||
$since = '2020-02-01T00:00:00Z';
|
||||
$until = '2020-02-28T23:59:59Z';
|
||||
$filters = 'responseCode==NOERROR AND queryType==A';
|
||||
|
||||
$result = $analytics->getReportTable(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
['queryName', 'queryType', 'responseCode'],
|
||||
['queryCount'],
|
||||
['-queryCount'],
|
||||
$filters,
|
||||
$since,
|
||||
$until
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $result->rows);
|
||||
$this->assertEquals($since, $result->query->since);
|
||||
$this->assertEquals($until, $result->query->until);
|
||||
}
|
||||
|
||||
public function testGetDNSAnalyticsReportByTime()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture(
|
||||
'Endpoints/getDNSAnalyticsReportByTime.json'
|
||||
);
|
||||
|
||||
$mock = $this->getMockBuilder(
|
||||
\Cloudflare\API\Adapter\Adapter::class
|
||||
)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo(
|
||||
'zones/023e105f4ecef8ad9ca31a8372d0c353/dns_analytics/report/bytime'
|
||||
)
|
||||
);
|
||||
|
||||
$analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
|
||||
$since = '2020-02-01T00:00:00Z';
|
||||
$until = '2020-02-28T23:59:59Z';
|
||||
$filters = 'responseCode==NOERROR AND queryType==A';
|
||||
|
||||
$result = $analytics->getReportByTime(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
['queryName', 'queryType', 'responseCode'],
|
||||
['queryCount'],
|
||||
['-queryCount'],
|
||||
$filters,
|
||||
$since,
|
||||
$until,
|
||||
2
|
||||
);
|
||||
|
||||
$this->assertEquals(2, $result->rows);
|
||||
$this->assertEquals($since, $result->query->since);
|
||||
$this->assertEquals($until, $result->query->until);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user