DNSAnalyticsTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Created by Visual Studio Code.
  4. * User: elliot.alderson
  5. * Date: 10/02/2020
  6. * Time: 04:28 AM
  7. */
  8. class DNSAnalyticsTest extends TestCase
  9. {
  10. public function testGetDNSAnalyticsReportTable()
  11. {
  12. $response = $this->getPsr7JsonResponseForFixture(
  13. 'Endpoints/getDNSAnalyticsReportTable.json'
  14. );
  15. $mock = $this->getMockBuilder(
  16. \Cloudflare\API\Adapter\Adapter::class
  17. )->getMock();
  18. $mock->method('get')->willReturn($response);
  19. $mock
  20. ->expects($this->once())
  21. ->method('get')
  22. ->with(
  23. $this->equalTo(
  24. 'zones/023e105f4ecef8ad9ca31a8372d0c353/dns_analytics/report'
  25. )
  26. );
  27. $analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
  28. $since = '2020-02-01T00:00:00Z';
  29. $until = '2020-02-28T23:59:59Z';
  30. $filters = 'responseCode==NOERROR AND queryType==A';
  31. $result = $analytics->getReportTable(
  32. '023e105f4ecef8ad9ca31a8372d0c353',
  33. ['queryName', 'queryType', 'responseCode'],
  34. ['queryCount'],
  35. ['-queryCount'],
  36. $filters,
  37. $since,
  38. $until
  39. );
  40. $this->assertEquals(1, $result->rows);
  41. $this->assertEquals($since, $result->query->since);
  42. $this->assertEquals($until, $result->query->until);
  43. }
  44. public function testGetDNSAnalyticsReportByTime()
  45. {
  46. $response = $this->getPsr7JsonResponseForFixture(
  47. 'Endpoints/getDNSAnalyticsReportByTime.json'
  48. );
  49. $mock = $this->getMockBuilder(
  50. \Cloudflare\API\Adapter\Adapter::class
  51. )->getMock();
  52. $mock->method('get')->willReturn($response);
  53. $mock
  54. ->expects($this->once())
  55. ->method('get')
  56. ->with(
  57. $this->equalTo(
  58. 'zones/023e105f4ecef8ad9ca31a8372d0c353/dns_analytics/report/bytime'
  59. )
  60. );
  61. $analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
  62. $since = '2020-02-01T00:00:00Z';
  63. $until = '2020-02-28T23:59:59Z';
  64. $filters = 'responseCode==NOERROR AND queryType==A';
  65. $result = $analytics->getReportByTime(
  66. '023e105f4ecef8ad9ca31a8372d0c353',
  67. ['queryName', 'queryType', 'responseCode'],
  68. ['queryCount'],
  69. ['-queryCount'],
  70. $filters,
  71. $since,
  72. $until,
  73. 2
  74. );
  75. $this->assertEquals(2, $result->rows);
  76. $this->assertEquals($since, $result->query->since);
  77. $this->assertEquals($until, $result->query->until);
  78. }
  79. }