diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6c2ccdf..0d514c7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -65,6 +65,11 @@ parameters: count: 1 path: src/Component.php + - + message: "#^Parameter \\#5 \\$logger of class Keboola\\\\Google\\\\ClientBundle\\\\Google\\\\RestApi constructor expects Monolog\\\\Logger\\|null, Psr\\\\Log\\\\LoggerInterface given\\.$#" + count: 1 + path: src/Component.php + - message: "#^Cannot access offset 'enabled' on mixed\\.$#" count: 1 @@ -830,26 +835,11 @@ parameters: count: 1 path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - - message: "#^Cannot access offset 'data' on mixed\\.$#" - count: 1 - path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - message: "#^Cannot access offset 'oauth_api' on mixed\\.$#" count: 1 path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - - message: "#^Cannot access offset 'status' on mixed\\.$#" - count: 2 - path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - - - - message: "#^Cannot access offset 0 on mixed\\.$#" - 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 @@ -872,7 +862,7 @@ parameters: - message: "#^Parameter \\#2 \\$array of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#" - count: 10 + count: 2 path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php - diff --git a/phpstan.neon b/phpstan.neon index f4e84b5..4fd8eb3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,4 +6,3 @@ parameters: - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:ignoreExtraKeys\(\).#' - '#Cannot call method integerNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#' - '#Cannot call method scalarNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#' - - '#logger of class Keboola\\Google\\ClientBundle\\Google\\RestApi constructor expects Monolog\\Logger\|null, Psr\\Log\\LoggerInterface given\.#' diff --git a/src/Configuration/ConfigDefinition.php b/src/Configuration/ConfigDefinition.php index 904ca16..df96050 100644 --- a/src/Configuration/ConfigDefinition.php +++ b/src/Configuration/ConfigDefinition.php @@ -166,6 +166,7 @@ public function getParametersDefinition(): ArrayNodeDefinition ->end() ->scalarNode('samplingLevel') ->end() + ->booleanNode('keepEmptyRows')->defaultTrue()->end() ->end() ->end() ->scalarNode('outputTable') diff --git a/src/GoogleAnalytics/Client.php b/src/GoogleAnalytics/Client.php index 9cd2101..d540814 100644 --- a/src/GoogleAnalytics/Client.php +++ b/src/GoogleAnalytics/Client.php @@ -260,7 +260,7 @@ private function getPropertyReportRequest(array $query): array 'endDate' => date('Y-m-d', (int) strtotime($item['endDate'])), ]; }, $query['dateRanges']), - 'keepEmptyRows' => true, + 'keepEmptyRows' => $query['keepEmptyRows'] ?? true, 'dimensions' => $query['dimensions'], 'metrics' => $query['metrics'], 'offset' => $query['offset'] ?? 0, diff --git a/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php b/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php index 5591778..f4032ff 100644 --- a/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php +++ b/tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php @@ -116,16 +116,6 @@ public function testAppRunMCF(): void } } - public function testAppSegments(): void - { - $this->config['action'] = 'segments'; - $result = json_decode($this->runProcess()->getOutput(), true); - - Assert::assertArrayHasKey('status', $result); - Assert::assertArrayHasKey('data', $result); - Assert::assertEquals('success', $result['status']); - } - public function testAppProfilesProperties(): void { $this->config = $this->getConfig('_empty'); @@ -154,50 +144,6 @@ public function testAppRunProperties(): void Assert::assertEquals(1, count($usersManifests)); } - public function testAppUserException(): void - { - $this->config = $this->getConfig(); - $this->config['parameters']['retriesCount'] = 0; - // unset segment dimension to trigger API error - unset($this->config['parameters']['query']['dimensions'][1]); - $errorOutput = $this->runProcess()->getErrorOutput(); - Assert::assertStringContainsString('Expired or wrong credentials, please reauthorize.', $errorOutput); - } - - public function testAppAuthException(): void - { - $this->config = $this->getConfig(); - $this->config['parameters']['retriesCount'] = 0; - $this->config['authorization']['oauth_api']['credentials'] = [ - 'appKey' => getenv('CLIENT_ID'), - '#appSecret' => getenv('CLIENT_SECRET'), - '#data' => json_encode([ - 'access_token' => 'cowshit', - 'refresh_token' => 'bullcrap', - ]), - ]; - $errorOutput = $this->runProcess()->getErrorOutput(); - Assert::assertStringContainsString('Expired or wrong credentials, please reauthorize.', $errorOutput); - } - - public function testRunSegmentsAction(): void - { - $this->config['action'] = 'segments'; - $process = $this->runProcess(); - Assert::assertEquals(0, $process->getExitCode()); - - $output = json_decode($process->getOutput(), true); - Assert::assertArrayHasKey('status', $output); - Assert::assertArrayHasKey('data', $output); - Assert::assertEquals('success', $output['status']); - Assert::assertNotEmpty($output['data']); - $segment = $output['data'][0]; - Assert::assertArrayHasKey('id', $segment); - Assert::assertArrayHasKey('kind', $segment); - Assert::assertArrayHasKey('segmentId', $segment); - Assert::assertArrayHasKey('name', $segment); - } - private function runProcess(): Process { $fs = new Filesystem(); diff --git a/tests/Keboola/GoogleAnalyticsExtractor/Configuration/ConfigDefinitionTest.php b/tests/Keboola/GoogleAnalyticsExtractor/Configuration/ConfigDefinitionTest.php index 1dd0939..dde2c37 100644 --- a/tests/Keboola/GoogleAnalyticsExtractor/Configuration/ConfigDefinitionTest.php +++ b/tests/Keboola/GoogleAnalyticsExtractor/Configuration/ConfigDefinitionTest.php @@ -103,6 +103,21 @@ public function testAddSegmentDimension(): void $this->assertCount(1, $dimensions); } + public function testKeepEmptyRowsDefaultAndCustom(): void + { + // Default value (not set in config) + $config = $this->config; + unset($config['parameters']['query']['keepEmptyRows']); + $configData = new Config($config, new ConfigDefinition()); + $this->assertArrayHasKey('keepEmptyRows', $configData->getQuery()); + $this->assertTrue($configData->getQuery()['keepEmptyRows']); + + // Set to false + $config['parameters']['query']['keepEmptyRows'] = false; + $configData = new Config($config, new ConfigDefinition()); + $this->assertFalse($configData->getQuery()['keepEmptyRows']); + } + private function getConfig(string $suffix = ''): array { $config = json_decode((string) file_get_contents($this->dataDir . '/config' . $suffix . '.json'), true);