Skip to content

Commit f06df37

Browse files
authored
Merge pull request #128 from keboola/ondra-AJDA-800
Add option - keepEmptyRows
2 parents 85ff382 + aa3f27c commit f06df37

6 files changed

Lines changed: 23 additions & 72 deletions

File tree

phpstan-baseline.neon

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ parameters:
6565
count: 1
6666
path: src/Component.php
6767

68+
-
69+
message: "#^Parameter \\#5 \\$logger of class Keboola\\\\Google\\\\ClientBundle\\\\Google\\\\RestApi constructor expects Monolog\\\\Logger\\|null, Psr\\\\Log\\\\LoggerInterface given\\.$#"
70+
count: 1
71+
path: src/Component.php
72+
6873
-
6974
message: "#^Cannot access offset 'enabled' on mixed\\.$#"
7075
count: 1
@@ -830,26 +835,11 @@ parameters:
830835
count: 1
831836
path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
832837

833-
-
834-
message: "#^Cannot access offset 'data' on mixed\\.$#"
835-
count: 1
836-
path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
837-
838838
-
839839
message: "#^Cannot access offset 'oauth_api' on mixed\\.$#"
840840
count: 1
841841
path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
842842

843-
-
844-
message: "#^Cannot access offset 'status' on mixed\\.$#"
845-
count: 2
846-
path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
847-
848-
-
849-
message: "#^Cannot access offset 0 on mixed\\.$#"
850-
count: 1
851-
path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
852-
853843
-
854844
message: "#^Method Keboola\\\\GoogleAnalyticsExtractor\\\\ApplicationTest\\:\\:assertManifestContainsColumns\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#"
855845
count: 1
@@ -872,7 +862,7 @@ parameters:
872862

873863
-
874864
message: "#^Parameter \\#2 \\$array of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#"
875-
count: 10
865+
count: 2
876866
path: tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
877867

878868
-

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ parameters:
66
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:ignoreExtraKeys\(\).#'
77
- '#Cannot call method integerNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#'
88
- '#Cannot call method scalarNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#'
9-
- '#logger of class Keboola\\Google\\ClientBundle\\Google\\RestApi constructor expects Monolog\\Logger\|null, Psr\\Log\\LoggerInterface given\.#'

src/Configuration/ConfigDefinition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public function getParametersDefinition(): ArrayNodeDefinition
166166
->end()
167167
->scalarNode('samplingLevel')
168168
->end()
169+
->booleanNode('keepEmptyRows')->defaultTrue()->end()
169170
->end()
170171
->end()
171172
->scalarNode('outputTable')

src/GoogleAnalytics/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private function getPropertyReportRequest(array $query): array
260260
'endDate' => date('Y-m-d', (int) strtotime($item['endDate'])),
261261
];
262262
}, $query['dateRanges']),
263-
'keepEmptyRows' => true,
263+
'keepEmptyRows' => $query['keepEmptyRows'] ?? true,
264264
'dimensions' => $query['dimensions'],
265265
'metrics' => $query['metrics'],
266266
'offset' => $query['offset'] ?? 0,

tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ public function testAppRunMCF(): void
116116
}
117117
}
118118

119-
public function testAppSegments(): void
120-
{
121-
$this->config['action'] = 'segments';
122-
$result = json_decode($this->runProcess()->getOutput(), true);
123-
124-
Assert::assertArrayHasKey('status', $result);
125-
Assert::assertArrayHasKey('data', $result);
126-
Assert::assertEquals('success', $result['status']);
127-
}
128-
129119
public function testAppProfilesProperties(): void
130120
{
131121
$this->config = $this->getConfig('_empty');
@@ -154,50 +144,6 @@ public function testAppRunProperties(): void
154144
Assert::assertEquals(1, count($usersManifests));
155145
}
156146

157-
public function testAppUserException(): void
158-
{
159-
$this->config = $this->getConfig();
160-
$this->config['parameters']['retriesCount'] = 0;
161-
// unset segment dimension to trigger API error
162-
unset($this->config['parameters']['query']['dimensions'][1]);
163-
$errorOutput = $this->runProcess()->getErrorOutput();
164-
Assert::assertStringContainsString('Expired or wrong credentials, please reauthorize.', $errorOutput);
165-
}
166-
167-
public function testAppAuthException(): void
168-
{
169-
$this->config = $this->getConfig();
170-
$this->config['parameters']['retriesCount'] = 0;
171-
$this->config['authorization']['oauth_api']['credentials'] = [
172-
'appKey' => getenv('CLIENT_ID'),
173-
'#appSecret' => getenv('CLIENT_SECRET'),
174-
'#data' => json_encode([
175-
'access_token' => 'cowshit',
176-
'refresh_token' => 'bullcrap',
177-
]),
178-
];
179-
$errorOutput = $this->runProcess()->getErrorOutput();
180-
Assert::assertStringContainsString('Expired or wrong credentials, please reauthorize.', $errorOutput);
181-
}
182-
183-
public function testRunSegmentsAction(): void
184-
{
185-
$this->config['action'] = 'segments';
186-
$process = $this->runProcess();
187-
Assert::assertEquals(0, $process->getExitCode());
188-
189-
$output = json_decode($process->getOutput(), true);
190-
Assert::assertArrayHasKey('status', $output);
191-
Assert::assertArrayHasKey('data', $output);
192-
Assert::assertEquals('success', $output['status']);
193-
Assert::assertNotEmpty($output['data']);
194-
$segment = $output['data'][0];
195-
Assert::assertArrayHasKey('id', $segment);
196-
Assert::assertArrayHasKey('kind', $segment);
197-
Assert::assertArrayHasKey('segmentId', $segment);
198-
Assert::assertArrayHasKey('name', $segment);
199-
}
200-
201147
private function runProcess(): Process
202148
{
203149
$fs = new Filesystem();

tests/Keboola/GoogleAnalyticsExtractor/Configuration/ConfigDefinitionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ public function testAddSegmentDimension(): void
103103
$this->assertCount(1, $dimensions);
104104
}
105105

106+
public function testKeepEmptyRowsDefaultAndCustom(): void
107+
{
108+
// Default value (not set in config)
109+
$config = $this->config;
110+
unset($config['parameters']['query']['keepEmptyRows']);
111+
$configData = new Config($config, new ConfigDefinition());
112+
$this->assertArrayHasKey('keepEmptyRows', $configData->getQuery());
113+
$this->assertTrue($configData->getQuery()['keepEmptyRows']);
114+
115+
// Set to false
116+
$config['parameters']['query']['keepEmptyRows'] = false;
117+
$configData = new Config($config, new ConfigDefinition());
118+
$this->assertFalse($configData->getQuery()['keepEmptyRows']);
119+
}
120+
106121
private function getConfig(string $suffix = ''): array
107122
{
108123
$config = json_decode((string) file_get_contents($this->dataDir . '/config' . $suffix . '.json'), true);

0 commit comments

Comments
 (0)