diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fc7908..7b04753 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,3 +29,5 @@ jobs: timezone: Europe/Brussels - run: vendor/bin/paratest + env: + DEMO_COMPANY_SECRET_KEY: ${{ secrets.DEMO_COMPANY_SECRET_KEY }} diff --git a/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV1.php b/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV1.php index a5086f9..02cfb2f 100644 --- a/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV1.php +++ b/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV1.php @@ -31,4 +31,13 @@ class UsageForObjectV1 * @var int */ public $numFirstBookingsOrSelections; + + public function __construct(string $object = null, int $numFirstBookings = null, \DateTime $firstBookingDate = null, int $numFirstSelections = null, int $numFirstBookingsOrSelections = null) + { + $this->object = $object; + $this->numFirstBookings = $numFirstBookings; + $this->firstBookingDate = $firstBookingDate; + $this->numFirstSelections = $numFirstSelections; + $this->numFirstBookingsOrSelections = $numFirstBookingsOrSelections; + } } diff --git a/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV2.php b/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV2.php index 7413089..ee879c9 100644 --- a/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV2.php +++ b/src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV2.php @@ -21,4 +21,11 @@ class UsageForObjectV2 * @var array */ public $usageByReason; + + public function __construct(string $object = null, int $numUsedObjects = null, array $usageByReason = null) + { + $this->object = $object; + $this->numUsedObjects = $numUsedObjects; + $this->usageByReason = $usageByReason; + } } diff --git a/src/Reports/Usage/DetailsForMonth/Chart.php b/src/Reports/Usage/DetailsForMonth/Chart.php index 14268bb..1457097 100644 --- a/src/Reports/Usage/DetailsForMonth/Chart.php +++ b/src/Reports/Usage/DetailsForMonth/Chart.php @@ -16,4 +16,10 @@ class Chart * @var string */ public $key; + + public function __construct(string $name = null, string $key = null) + { + $this->name = $name; + $this->key = $key; + } } diff --git a/src/Reports/Usage/DetailsForMonth/Event.php b/src/Reports/Usage/DetailsForMonth/Event.php index 880df31..5fec074 100644 --- a/src/Reports/Usage/DetailsForMonth/Event.php +++ b/src/Reports/Usage/DetailsForMonth/Event.php @@ -16,4 +16,16 @@ class Event * @var string */ public $key; + + /** + * @var boolean + */ + public $deleted; + + public function __construct(int $id = null, string $key = null, bool $deleted = null) + { + $this->id = $id; + $this->key = $key; + $this->deleted = $deleted; + } } diff --git a/src/Reports/Usage/DetailsForMonth/UsageByChart.php b/src/Reports/Usage/DetailsForMonth/UsageByChart.php index bc8e8c5..9720c30 100644 --- a/src/Reports/Usage/DetailsForMonth/UsageByChart.php +++ b/src/Reports/Usage/DetailsForMonth/UsageByChart.php @@ -16,4 +16,10 @@ class UsageByChart * @var UsageByEvent[] */ public $usageByEvent; + + public function __construct(Chart $chart = null, array $usageByEvent = null) + { + $this->chart = $chart; + $this->usageByEvent = $usageByEvent; + } } diff --git a/src/Reports/Usage/DetailsForMonth/UsageByEvent.php b/src/Reports/Usage/DetailsForMonth/UsageByEvent.php index a4997fb..afc268f 100644 --- a/src/Reports/Usage/DetailsForMonth/UsageByEvent.php +++ b/src/Reports/Usage/DetailsForMonth/UsageByEvent.php @@ -16,4 +16,14 @@ class UsageByEvent * @var int */ public $numUsedObjects; + + /** + * @param Event $event + * @param int $numUsedObjects + */ + public function __construct(Event $event = null, int $numUsedObjects = null) + { + $this->event = $event; + $this->numUsedObjects = $numUsedObjects; + } } diff --git a/src/Reports/Usage/DetailsForMonth/UsageDetails.php b/src/Reports/Usage/DetailsForMonth/UsageDetails.php index 02c61cc..8f331b8 100644 --- a/src/Reports/Usage/DetailsForMonth/UsageDetails.php +++ b/src/Reports/Usage/DetailsForMonth/UsageDetails.php @@ -16,4 +16,10 @@ class UsageDetails * @var UsageByChart[] */ public $usageByChart; + + public function __construct(int $workspace = null, array $usageByChart = null) + { + $this->workspace = $workspace; + $this->usageByChart = $usageByChart; + } } diff --git a/src/Reports/Usage/SummaryForMonths/Month.php b/src/Reports/Usage/SummaryForMonths/Month.php index 65e1f8a..d8373a4 100644 --- a/src/Reports/Usage/SummaryForMonths/Month.php +++ b/src/Reports/Usage/SummaryForMonths/Month.php @@ -27,5 +27,4 @@ public function serialize(): string { return $this->year . '-' . str_pad($this->month, 2, '0', STR_PAD_LEFT); } - } diff --git a/src/Reports/Usage/SummaryForMonths/UsageSummaryForAllMonths.php b/src/Reports/Usage/SummaryForMonths/UsageSummaryForAllMonths.php new file mode 100644 index 0000000..6291bef --- /dev/null +++ b/src/Reports/Usage/SummaryForMonths/UsageSummaryForAllMonths.php @@ -0,0 +1,29 @@ +usageCutoffDate = $usageCutoffDate; + $this->usage = $usage; + } +} diff --git a/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php b/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php index b1d50a2..98b6554 100644 --- a/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php +++ b/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php @@ -17,4 +17,13 @@ class UsageSummaryForMonth */ public $numUsedObjects; + /** + * @param Month $month + * @param int $numUsedObjects + */ + public function __construct(Month $month = null, int $numUsedObjects = null) + { + $this->month = $month; + $this->numUsedObjects = $numUsedObjects; + } } diff --git a/src/Reports/Usage/UsageReports.php b/src/Reports/Usage/UsageReports.php index 0e0ee1a..d4453d4 100644 --- a/src/Reports/Usage/UsageReports.php +++ b/src/Reports/Usage/UsageReports.php @@ -8,6 +8,7 @@ use Seatsio\Reports\Usage\DetailsForEventInMonth\UsageForObjectV2; use Seatsio\Reports\Usage\DetailsForMonth\UsageDetails; use Seatsio\Reports\Usage\SummaryForMonths\Month; +use Seatsio\Reports\Usage\SummaryForMonths\UsageSummaryForAllMonths; use Seatsio\Reports\Usage\SummaryForMonths\UsageSummaryForMonth; use Seatsio\SeatsioJsonMapper; @@ -24,15 +25,12 @@ public function __construct(Client $client) $this->client = $client; } - /** - * @return UsageSummaryForMonth[] - */ - public function summaryForAllMonths(): array + public function summaryForAllMonths(): UsageSummaryForAllMonths { - $res = $this->client->get('/reports/usage'); + $res = $this->client->get('/reports/usage?version=2'); $json = Utils::jsonDecode($res->getBody()); $mapper = SeatsioJsonMapper::create(); - return $mapper->mapArray($json, array(), UsageSummaryForMonth::class); + return $mapper->map($json, new UsageSummaryForAllMonths()); } /** diff --git a/tests/Reports/ChartReportsSummaryTest.php b/tests/Reports/Charts/ChartReportsSummaryTest.php similarity index 99% rename from tests/Reports/ChartReportsSummaryTest.php rename to tests/Reports/Charts/ChartReportsSummaryTest.php index 0f34416..fc8072e 100644 --- a/tests/Reports/ChartReportsSummaryTest.php +++ b/tests/Reports/Charts/ChartReportsSummaryTest.php @@ -1,6 +1,6 @@ skipTestIfDemoCompanySecretKeyNotSet(); + $client = $this->createSeatsioClient($this->demoCompanySecretKey()); + + $report = $client->usageReports->summaryForAllMonths(); + + self::assertNotNull($report->usageCutoffDate); + self::assertGreaterThan(0, count($report->usage)); + self::assertEquals(new Month(2014, 2), $report->usage[0]->month); + } + + public function testUsageReportForMonth() + { + $this->skipTestIfDemoCompanySecretKeyNotSet(); + $client = $this->createSeatsioClient($this->demoCompanySecretKey()); + + $report = $client->usageReports->detailsForMonth(new Month(2021, 11)); + + self::assertGreaterThan(0, count($report)); + self::assertGreaterThan(0, count($report[0]->usageByChart)); + $expected = new UsageByEvent(new Event(580293, "largeStadiumEvent", false), 143); + self::assertEquals([$expected], $report[0]->usageByChart[0]->usageByEvent); + } + + public function testUsageReportForEventInMonth() + { + $this->skipTestIfDemoCompanySecretKeyNotSet(); + $client = $this->createSeatsioClient($this->demoCompanySecretKey()); + + $report = $client->usageReports->detailsForEventInMonth(580293, new Month(2021, 11)); + + self::assertGreaterThan(0, count($report)); + $expected = new UsageForObjectV1('102-9-14', 0, null, 1, 1); + self::assertEquals($expected, $report[0]); + } + + private function skipTestIfDemoCompanySecretKeyNotSet(): void + { + if (!$this->isDemoCompanySecretKeySet()) { + $this->markTestSkipped("DEMO_COMPANY_SECRET_KEY environment variable not set"); + } + } +} diff --git a/tests/SeatsioClientTest.php b/tests/SeatsioClientTest.php index cb12808..8bc4b50 100644 --- a/tests/SeatsioClientTest.php +++ b/tests/SeatsioClientTest.php @@ -123,4 +123,14 @@ protected function waitForStatusChanges(Event $event, $numStatusChanges) } } } + + protected function demoCompanySecretKey() + { + return getenv("DEMO_COMPANY_SECRET_KEY"); + } + + protected function isDemoCompanySecretKeySet() + { + return getenv("DEMO_COMPANY_SECRET_KEY") !== false; + } }