diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0d514c7..50883ca 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -840,11 +840,6 @@ parameters: count: 1 path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - - message: "#^Method Keboola\\\\GoogleAnalyticsExtractor\\\\ApplicationTest\\:\\:assertManifestContainsColumns\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#" - count: 1 - path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - message: "#^Method Keboola\\\\GoogleAnalyticsExtractor\\\\ApplicationTest\\:\\:getConfig\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -855,11 +850,6 @@ parameters: count: 1 path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" - count: 1 - path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - message: "#^Parameter \\#2 \\$array of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#" count: 2 diff --git a/src/Extractor/Output.php b/src/Extractor/Output.php index 7fc0044..c2d8e13 100644 --- a/src/Extractor/Output.php +++ b/src/Extractor/Output.php @@ -167,7 +167,11 @@ public function createCsvFile(string $name): CsvFile if (!is_dir($outTablesDir)) { mkdir($outTablesDir, 0777, true); } - return new CsvFile($this->dataDir . '/out/tables/' . $name . '.csv'); + $filename = $this->dataDir . '/out/tables/' . $name . '.csv'; + if (!file_exists($filename)) { + touch($filename); + } + return new CsvFile($filename); } public function createManifest( diff --git a/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php b/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php index f4032ff..a473bce 100644 --- a/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php +++ b/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php @@ -50,72 +50,6 @@ private function getConfig(string $suffix = ''): array return $config; } - public function testAppRunDailyWalk(): void - { - $this->config = $this->getConfig('_antisampling'); - $this->runProcess(); - - $dailyWalk = $this->getManifestFiles('dailyWalk'); - Assert::assertEquals(1, count($dailyWalk)); - - foreach ($dailyWalk as $file) { - /** @var $file SplFileInfo */ - $this->assertManifestContainsColumns($file->getPathname(), [ - 'id', - 'idProfile', - 'date', - 'sourceMedium', - 'landingPagePath', - 'pageviews', - ]); - } - } - - public function testAppRunAdaptive(): void - { - $this->config = $this->getConfig('_antisampling_adaptive'); - $this->runProcess(); - - $adaptive = $this->getManifestFiles('adaptive'); - Assert::assertEquals(1, count($adaptive)); - - foreach ($adaptive as $file) { - /** @var $file SplFileInfo */ - $this->assertManifestContainsColumns($file->getPathname(), [ - 'id', - 'idProfile', - 'date', - 'sourceMedium', - 'landingPagePath', - 'pageviews', - ]); - } - } - - public function testAppRunMCF(): void - { - $this->config = $this->getConfig('_mcf'); - $this->runProcess(); - - $funnelFiles = $this->getManifestFiles('funnel'); - Assert::assertEquals(1, count($funnelFiles)); - - foreach ($funnelFiles as $file) { - /** @var $file SplFileInfo */ - $this->assertManifestContainsColumns($file->getPathname(), [ - 'id', - 'idProfile', - 'mcf:conversionDate', - 'mcf:sourcePath', - 'mcf:mediumPath', - 'mcf:sourceMedium', - 'mcf:totalConversions', - 'mcf:totalConversionValue', - 'mcf:assistedConversions', - ]); - } - } - public function testAppProfilesProperties(): void { $this->config = $this->getConfig('_empty'); @@ -183,13 +117,6 @@ private function getManifestFiles(string $queryName): Finder ; } - private function assertManifestContainsColumns(string $pathname, array $expected): void - { - $manifest = (array) json_decode(file_get_contents($pathname), true, 512, JSON_THROW_ON_ERROR); - Assert::assertArrayHasKey('columns', $manifest); - Assert::assertEquals($expected, $manifest['columns']); - } - public function appRunDataProvider(): Generator { yield 'configRow' => [ diff --git a/tests/data/config_antisampling.json b/tests/data/config_antisampling.json deleted file mode 100644 index 7bfd79a..0000000 --- a/tests/data/config_antisampling.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "parameters": { - "retriesCount": 1, - "outputBucket": "in.c-ex-google-analytics-cfg1", - "profiles": [ - { - "id": 184062725, - "name": "All Web Site Data", - "webPropertyId": "UA-128209249-1", - "webPropertyName": "Keboola Website", - "accountId": 128209249, - "accountName": "Keboola Website" - }, - { - "id": 88156763, - "name": "All Web Site Data", - "webPropertyId": "UA-128209249-1", - "webPropertyName": "status.keboola.com", - "accountId": 128209249, - "accountName": "Keboola Status" - } - ], - "outputTable": "dailyWalk", - "antisampling": "dailyWalk", - "query": { - "metrics": [ - { - "expression": "ga:pageviews" - } - ], - "dimensions": [ - { - "name": "ga:date" - }, - { - "name": "ga:sourceMedium" - }, - { - "name": "ga:landingPagePath" - } - ], - "filtersExpression": "", - "segments": null, - "dateRanges": [ - { - "startDate": "-3 days", - "endDate": "-1 day" - } - ] - } - } -} diff --git a/tests/data/config_antisampling_adaptive.json b/tests/data/config_antisampling_adaptive.json deleted file mode 100644 index b8f568e..0000000 --- a/tests/data/config_antisampling_adaptive.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "parameters": { - "retriesCount": 1, - "outputBucket": "in.c-ex-google-analytics-cfg1", - "profiles": [ - { - "id": 184062725, - "name": "All Web Site Data", - "webPropertyId": "UA-128209249-1", - "webPropertyName": "Keboola Website", - "accountId": 128209249, - "accountName": "Keboola Website" - }, - { - "id": 88156763, - "name": "All Web Site Data", - "webPropertyId": "UA-128209249-1", - "webPropertyName": "status.keboola.com", - "accountId": 128209249, - "accountName": "Keboola Status" - } - ], - "outputTable": "adaptive", - "antisampling": "adaptive", - "query": { - "viewId": "26550866", - "metrics": [ - { - "expression": "ga:pageviews" - } - ], - "dimensions": [ - { - "name": "ga:date" - }, - { - "name": "ga:sourceMedium" - }, - { - "name": "ga:landingPagePath" - } - ], - "filtersExpression": "", - "segments": null, - "dateRanges": [ - { - "startDate": "-3 days", - "endDate": "-1 day" - } - ] - } - } -} diff --git a/tests/data/config_mcf.json b/tests/data/config_mcf.json deleted file mode 100644 index c6c4d3e..0000000 --- a/tests/data/config_mcf.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "parameters": { - "outputBucket": "in.c-ex-google-analytics-cfg1", - "retriesCount": 1, - "profiles": [ - { - "id": 184062725, - "name": "All Web Site Data", - "webPropertyId": "UA-128209249-1", - "webPropertyName": "Keboola Website", - "accountId": 128209249, - "accountName": "Keboola Website" - }, - { - "id": 88156763, - "name": "All Web Site Data", - "webPropertyId": "UA-128209249-1", - "webPropertyName": "status.keboola.com", - "accountId": 128209249, - "accountName": "Keboola Status" - } - ], - "outputTable": "funnel", - "endpoint": "mcf", - "antisampling": "dailyWalk", - "query": { - "samplingLevel": "FASTER", - "maxResults": 100, - "metrics": [ - { - "expression": "mcf:totalConversions" - }, - { - "expression": "mcf:totalConversionValue" - }, - { - "expression": "mcf:assistedConversions" - } - ], - "dimensions": [ - { - "name": "mcf:conversionDate" - }, - { - "name": "mcf:sourcePath" - }, - { - "name": "mcf:mediumPath" - }, - { - "name": "mcf:sourceMedium" - } - ], - "filtersExpression": "", - "dateRanges": [ - { - "startDate": "-1 week", - "endDate": "-1 day" - } - ] - } - } -} diff --git a/tests/functional/download-empty-data/expected/data/out/files/.gitkeep b/tests/functional/download-empty-data/expected/data/out/files/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/download-empty-data/expected/data/out/tables/empty-data.csv b/tests/functional/download-empty-data/expected/data/out/tables/empty-data.csv new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/download-empty-data/expected/data/out/tables/empty-data.csv.manifest b/tests/functional/download-empty-data/expected/data/out/tables/empty-data.csv.manifest new file mode 100644 index 0000000..a2ec643 --- /dev/null +++ b/tests/functional/download-empty-data/expected/data/out/tables/empty-data.csv.manifest @@ -0,0 +1 @@ +{"destination":"in.c-keboola-ex-google-analytics-v4-01k6mq8atddf0xbr48p2b9st4h.empty-data","incremental":true,"columns":["id","idProperty","campaignId","campaignName","city","cityId","active1DayUsers","active28DayUsers"],"primary_key":["id"],"column_metadata":{"id":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"idProperty":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"campaignId":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"campaignName":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"city":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"cityId":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"active1DayUsers":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"active28DayUsers":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}]}} \ No newline at end of file diff --git a/tests/functional/download-empty-data/expected/data/out/tables/properties.csv b/tests/functional/download-empty-data/expected/data/out/tables/properties.csv new file mode 100644 index 0000000..1b7864b --- /dev/null +++ b/tests/functional/download-empty-data/expected/data/out/tables/properties.csv @@ -0,0 +1 @@ +"properties/403517979","Website - GA4","accounts/128209249","Keboola Website" diff --git a/tests/functional/download-empty-data/expected/data/out/tables/properties.csv.manifest b/tests/functional/download-empty-data/expected/data/out/tables/properties.csv.manifest new file mode 100644 index 0000000..331dcfe --- /dev/null +++ b/tests/functional/download-empty-data/expected/data/out/tables/properties.csv.manifest @@ -0,0 +1 @@ +{"destination":"in.c-keboola-ex-google-analytics-v4-01k6mq8atddf0xbr48p2b9st4h.properties","incremental":true,"columns":["propertyKey","propertyName","accountKey","accountName"],"primary_key":["propertyKey"],"column_metadata":{"propertyKey":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"propertyName":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"accountKey":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}],"accountName":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"STRING"}]}} \ No newline at end of file diff --git a/tests/functional/download-empty-data/expected/data/out/usage.json b/tests/functional/download-empty-data/expected/data/out/usage.json new file mode 100644 index 0000000..7121ffb --- /dev/null +++ b/tests/functional/download-empty-data/expected/data/out/usage.json @@ -0,0 +1 @@ +[{"metric":"API Calls","value":1}] \ No newline at end of file diff --git a/tests/functional/download-empty-data/source/data/config.json b/tests/functional/download-empty-data/source/data/config.json new file mode 100644 index 0000000..edfd181 --- /dev/null +++ b/tests/functional/download-empty-data/source/data/config.json @@ -0,0 +1,54 @@ +{ + "authorization": { + "oauth_api": { + "credentials": { + "appKey": "%env(string:CLIENT_ID)%", + "#appSecret": "%env(string:CLIENT_SECRET)%", + "#data": "%env(string:CREDENTIALS_DATA)%" + } + } + }, + "parameters": { + "outputTable": "empty-data", + "query": { + "metrics": [ + { + "name": "active1DayUsers" + }, + { + "name": "active28DayUsers" + } + ], + "dimensions": [ + { + "name": "campaignId" + }, + { + "name": "campaignName" + }, + { + "name": "city" + }, + { + "name": "cityId" + } + ], + "dateRanges": [ + { + "startDate": "2015-08-14", + "endDate": "2015-08-15" + } + ] + }, + "endpoint": "data-api", + "outputBucket": "in.c-keboola-ex-google-analytics-v4-01k6mq8atddf0xbr48p2b9st4h", + "properties": [ + { + "accountKey": "accounts/128209249", + "accountName": "Keboola Website", + "propertyKey": "properties/403517979", + "propertyName": "Website - GA4" + } + ] + } +} \ No newline at end of file