From e1f2dcc136e4469dc4f9c1dd984c69c6aad08833 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 17 Nov 2023 23:31:23 +0100 Subject: [PATCH] Create MatomoTrackerBuilderTest --- .../test/Matomo/MatomoTrackerBuilderTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 module/Core/test/Matomo/MatomoTrackerBuilderTest.php diff --git a/module/Core/test/Matomo/MatomoTrackerBuilderTest.php b/module/Core/test/Matomo/MatomoTrackerBuilderTest.php new file mode 100644 index 00000000..b7550bad --- /dev/null +++ b/module/Core/test/Matomo/MatomoTrackerBuilderTest.php @@ -0,0 +1,49 @@ +expectException(RuntimeException::class); + $this->expectExceptionMessage( + 'Cannot create MatomoTracker. Either site ID, base URL or api token are not defined', + ); + $this->builder($options)->buildMatomoTracker(); + } + + public static function provideInvalidOptions(): iterable + { + yield [new MatomoOptions()]; + yield [new MatomoOptions(baseUrl: 'base_url')]; + yield [new MatomoOptions(apiToken: 'api_token')]; + yield [new MatomoOptions(siteId: 5)]; + yield [new MatomoOptions(baseUrl: 'base_url', apiToken: 'api_token')]; + yield [new MatomoOptions(baseUrl: 'base_url', siteId: 5)]; + yield [new MatomoOptions(siteId: 5, apiToken: 'api_token')]; + } + + #[Test] + public function trackerIsCreated(): void + { + $tracker = $this->builder()->buildMatomoTracker(); + + self::assertEquals('api_token', $tracker->token_auth); + self::assertEquals(5, $tracker->idSite); + } + + private function builder(?MatomoOptions $options = null): MatomoTrackerBuilder + { + $options ??= new MatomoOptions(enabled: true, baseUrl: 'base_url', siteId: 5, apiToken: 'api_token'); + return new MatomoTrackerBuilder($options); + } +}