Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

-
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\.#'
1 change: 1 addition & 0 deletions src/Configuration/ConfigDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function getParametersDefinition(): ArrayNodeDefinition
->end()
->scalarNode('samplingLevel')
->end()
->booleanNode('keepEmptyRows')->defaultTrue()->end()
->end()
->end()
->scalarNode('outputTable')
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleAnalytics/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 0 additions & 54 deletions tests/Keboola/GoogleAnalyticsExtractor/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -154,50 +144,6 @@ public function testAppRunProperties(): void
Assert::assertEquals(1, count($usersManifests));
}

public function testAppUserException(): void
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testy pro odstraněný Universal Analytics, pomalu vypínají služby tak musíme odmazávat testy...chtělo by to teda pročistit i kod

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, tenhle test chapu, ten assert byl stejne divnej :D

{
$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);
}
Comment on lines -167 to -181
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ale co je spatne na tomhle testu?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volal se tam ještě starý endpoint na UA který už je dávno deprecated - https://github.com/keboola/google-analytics-extractor/actions/runs/16517331264/job/46710920611#step:4:663


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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down