Skip to content

Commit

Permalink
Merge pull request #19 from wunderio/feature/drupal-version
Browse files Browse the repository at this point in the history
Add Drupal Version to stats
  • Loading branch information
ragnarkurmwunder authored Mar 7, 2023
2 parents f51498a + 7741ab1 commit 9d13959
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/UpdatesLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,20 @@ public function generateStatistics(
string $site,
string $env
): array {

$drupal = $statuses['drupal']['version_used'] ?? '???';
if (preg_match('/^(\d+)\.(\d+)\.(\d+)$/', $drupal, $matches)) {
$drupal = sprintf('%02d.%02d.%02d', $matches[1], $matches[2], $matches[3]);
}

$statistics = [
"updates_log" => $version,
"site" => $site,
"env" => $env,
"last_check_epoch" => $this->lastUpdated,
"last_check_human" => gmdate('Y-m-d\Th:i:sZT', $this->lastUpdated),
"last_check_ago" => time() - $this->lastUpdated,
"drupal" => $drupal,
"summary" => [
"CURRENT" => 0,
"NOT_CURRENT" => 0,
Expand Down
18 changes: 16 additions & 2 deletions tests/src/Unit/GenerateStatisticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public function testGenerateStatistics(): void {
$env = 'staging';
$statistics = $this->updatesLog->generateStatistics(
[
'drupal' => ['status' => 'CURRENT', 'version_used' => '3.2.1'],
'x' => ['status' => 'NOT_CURRENT', 'version_used' => 'x'],
'y' => ['status' => 'NOT_SUPPORTED', 'version_used' => 'x'],
'z' => ['status' => 'NOT_SECURE', 'version_used' => 'x'],
'a' => ['status' => 'CURRENT', 'version_used' => 'x'],
'b' => ['status' => 'CURRENT', 'version_used' => 'x'],
'c' => ['status' => '???', 'version_used' => 'x'],

],
$version,
$site,
$env
);
$this->assertEquals(2, $statistics['summary']['CURRENT']);
$this->assertEquals(3, $statistics['summary']['CURRENT']);
$this->assertEquals(1, $statistics['summary']['NOT_CURRENT']);
$this->assertEquals(1, $statistics['summary']['UNKNOWN']);
$this->assertCount(4, $statistics['details']);
Expand All @@ -40,6 +40,20 @@ public function testGenerateStatistics(): void {
$this->assertEquals($version, $statistics['updates_log']);
$this->assertEquals($site, $statistics['site']);
$this->assertEquals($env, $statistics['env']);
$this->assertEquals('03.02.01', $statistics['drupal']);
}

/**
* @covers ::generateStatistics
*/
public function testGenerateStatisticsNoDrupalVer(): void {
$statistics = $this->updatesLog->generateStatistics(
[],
'',
'',
''
);
$this->assertEquals('???', $statistics['drupal']);
}

}

0 comments on commit 9d13959

Please sign in to comment.