Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-version: ['7.4', '8.0']
php-version: ['8.1', '8.2']

runs-on: ${{ matrix.operating-system }}

Expand Down
5 changes: 2 additions & 3 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
$psr12Rules = [
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'braces' => ['allow_single_line_closure' => true],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'function_typehint_space' => true,
'type_declaration_spaces' => true,
'new_with_braces' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_whitespace_in_blank_line' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_space_after_construct' => false,
'single_space_around_construct' => false,
'single_trait_insert_per_statement' => true,
];

Expand Down
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
}
],
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"ocramius/package-versions": true,
"phpstan/extension-installer": true
}
},
"require": {
"php": "^7.4 || ^8.0",
"php": "~8.1",
"google/apiclient": "^2.8",
"jangregor/phpstan-prophecy": "^0.8.1",
"wizaplace/php-etl": "^1.3"
},
"autoload": {
Expand All @@ -24,13 +28,14 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17",
"infection/infection": "^0.20.2",
"friendsofphp/php-cs-fixer": "^3.7",
"infection/infection": "^0.26",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload-dev": {
Expand Down
15 changes: 9 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# WARNING: DO NOT ADD ANY EXCLUSION. THE ONES ALREADY HERE ARE FOR THE LEGACY CODE.
parameters:
level: 6
paths:
- src
- tests
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
level: 6
paths:
- src
- tests
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- message: '/Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::.*/'
path: tests/Extractors/GoogleAnalyticsTest.php
27 changes: 11 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
beStrictAboutCoversAnnotation="true">

<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" beStrictAboutCoversAnnotation="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
6 changes: 2 additions & 4 deletions src/Extractors/GoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@
*/
class GoogleAnalytics extends Extractor
{
private const REPORT_PAGE_SIZE = 1000;

/**
* @var array
* @var array<string>
*/
protected $availableOptions = ['startDate', 'endDate', 'views', 'properties', 'dimensions', 'metrics'];

Expand Down Expand Up @@ -354,7 +352,7 @@ private function setHeaders(\Google_Service_AnalyticsReporting_Report $report):
$this->dimensionHeaders = $header->getDimensions();
$headerEntries = $header->getMetricHeader()->getMetricHeaderEntries();
$this->metricHeaders = array_map(
function (\Google_Service_AnalyticsReporting_MetricHeaderEntry $headerEntry) {
function (\Google_Service_AnalyticsReporting_MetricHeaderEntry $headerEntry): string {
return $headerEntry->getName();
},
$headerEntries
Expand Down
32 changes: 19 additions & 13 deletions tests/Extractors/GoogleAnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpEtl\GoogleAnalytics\Extractors\Request;
use PhpEtl\GoogleAnalytics\Tests\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Wizaplace\Etl\Extractors\Extractor;

/**
Expand All @@ -42,6 +43,10 @@
*/
class GoogleAnalyticsTest extends TestCase
{
use ProphecyTrait {
ProphecyTrait::prophesize as phpspecProphesize;
}

private const GA_DATE = 'ga:date';
private const GA_PAGE_VIEWS = 'ga:pageviews';
private const GA_AVG_PAGE_LOAD_TIME = 'ga:avgPageLoadTime';
Expand Down Expand Up @@ -117,7 +122,7 @@ public function defaultOptions(): void
$i = 0;
/** @var \Wizaplace\Etl\Row $row */
foreach ($this->extractor->extract() as $row) {
static::assertEquals($expected[$i++], ($row->toArray()));
static::assertEquals($expected[$i++], $row->toArray());
}
static::assertEquals(3, $i);
}
Expand Down Expand Up @@ -416,19 +421,19 @@ private function mockReport(): \Google_Service_AnalyticsReporting_Report

private function mockAnalyticsService(int $sites = 0): \Google_Service_Analytics
{
$profile = $this->prophesize(\Google_Service_Analytics_ProfileSummary::class);
$profile = $this->phpspecProphesize(\Google_Service_Analytics_ProfileSummary::class);
$profile->getId()->willReturn('12345');
$profile->getName()->willReturn($this->profile);

$secondProfile = $this->prophesize(\Google_Service_Analytics_ProfileSummary::class);
$secondProfile = $this->phpspecProphesize(\Google_Service_Analytics_ProfileSummary::class);
$secondProfile->getId()->willReturn('123456');
$secondProfile->getName()->willReturn('No Data');

$propertySummary = $this->prophesize(\Google_Service_Analytics_WebPropertySummary::class);
$propertySummary = $this->phpspecProphesize(\Google_Service_Analytics_WebPropertySummary::class);
$propertySummary->getName()->willReturn($this->site);
$propertySummary->getProfiles()->willReturn([$profile->reveal()]);

$secondProperty = $this->prophesize(\Google_Service_Analytics_WebPropertySummary::class);
$secondProperty = $this->phpspecProphesize(\Google_Service_Analytics_WebPropertySummary::class);
$secondProperty->getName()->willReturn('not-a-site.example.com');
$secondProperty->getProfiles()->willReturn([$secondProfile->reveal(), $profile->reveal()]);

Expand All @@ -437,18 +442,18 @@ private function mockAnalyticsService(int $sites = 0): \Google_Service_Analytics
$properties[] = $propertySummary->reveal();
}

$accountSummary = $this->prophesize(\Google_Service_Analytics_AccountSummary::class);
$accountSummary = $this->phpspecProphesize(\Google_Service_Analytics_AccountSummary::class);
$accountSummary->getWebProperties()->willReturn($properties);

$accountSummaries = $this->prophesize(\Google_Service_Analytics_AccountSummaries::class);
$accountSummaries = $this->phpspecProphesize(\Google_Service_Analytics_AccountSummaries::class);
$accountSummaries->getItems()->willReturn([$accountSummary->reveal()]);

$mgmtAcctSummary = $this->prophesize(\Google_Service_Analytics_Resource_ManagementAccountSummaries::class);
$mgmtAcctSummary->listManagementAccountSummaries()->willReturn($accountSummaries->reveal());
$mgmtSummary = $this->phpspecProphesize(\Google_Service_Analytics_Resource_ManagementAccountSummaries::class);
$mgmtSummary->listManagementAccountSummaries()->willReturn($accountSummaries->reveal());

$analyticsService = $this->prophesize(\Google_Service_Analytics::class);
$analyticsService = $this->phpspecProphesize(\Google_Service_Analytics::class);
$return = $analyticsService->reveal();
$return->management_accountSummaries = $mgmtAcctSummary->reveal();
$return->management_accountSummaries = $mgmtSummary->reveal();

return $return;
}
Expand All @@ -466,7 +471,7 @@ private function mockReportingService(GetReportsResponse $response): \Google_Ser
$mock = $this->createMock(\Google_Service_AnalyticsReporting_Resource_Reports::class);
$mock->method('batchGet')->willReturn($response);

$client = $this->prophesize(\Google_Client::class);
$client = $this->phpspecProphesize(\Google_Client::class);
$reportingService = new \Google_Service_AnalyticsReporting($client->reveal());
$reportingService->reports = $mock;

Expand All @@ -475,7 +480,8 @@ private function mockReportingService(GetReportsResponse $response): \Google_Ser

private function mockReportingRequest(string $endDate = '2020-12-15'): ReportRequest
{
$mock = $this->prophesize(ReportRequest::class);
/** @var \Prophecy\Prophecy\ObjectProphecy|ReportRequest $mock */
$mock = $this->phpspecProphesize(ReportRequest::class);
$mock->setPageSize(1000)->shouldBeCalled();
$mock->setDateRanges(Request::dateRange($this->options['startDate'], $endDate))->shouldBeCalled();
$mock->setDimensions(Request::dimensions(['ga:date']))->shouldBeCalled();
Expand Down
3 changes: 3 additions & 0 deletions tests/Extractors/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RequestTest extends TestCase
{
/**
* @test
*
* @covers ::metrics
*/
public function testMetrics(): void
Expand All @@ -42,6 +43,7 @@ public function testMetrics(): void

/**
* @test
*
* @covers ::dateRange()
*/
public function testDateRange(): void
Expand All @@ -53,6 +55,7 @@ public function testDateRange(): void

/**
* @test
*
* @covers ::dimensions
*/
public function testDimensions(): void
Expand Down