Skip to content

Commit 9dd19ac

Browse files
committed
Updated test helper and API to add the git version (if available)
1 parent 62d6321 commit 9dd19ac

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/phpFastCache/Api.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public static function getVersion(): string
5050
}
5151

5252
/**
53-
* @param bool $fallbackOnReadme
53+
* @param bool $fallbackOnChangelog
5454
* @param bool $cacheable
5555
* @return string
5656
* @throws \phpFastCache\Exceptions\phpFastCacheLogicException
5757
* @throws \phpFastCache\Exceptions\phpFastCacheIOException
5858
*/
59-
public static function getPhpFastCacheVersion($fallbackOnReadme = true, $cacheable = true): string
59+
public static function getPhpFastCacheVersion($fallbackOnChangelog = true, $cacheable = true): string
6060
{
6161
/**
6262
* Cache the version statically to improve
@@ -77,12 +77,12 @@ public static function getPhpFastCacheVersion($fallbackOnReadme = true, $cacheab
7777
throw new phpFastCacheLogicException('The git command used to retrieve the PhpFastCache version has failed.');
7878
}
7979

80-
if(!$fallbackOnReadme){
80+
if(!$fallbackOnChangelog){
8181
throw new phpFastCacheLogicException('shell_exec is disabled therefore the PhpFastCache version cannot be retrieved.');
8282
}
8383

84-
$readmeFilename = __DIR__ . '/../../CHANGELOG.md';
85-
if(file_exists($readmeFilename)){
84+
$changelogFilename = __DIR__ . '/../../CHANGELOG.md';
85+
if(file_exists($changelogFilename)){
8686
$versionPrefix = '## ';
8787
$changelog = explode("\n", self::getPhpFastCacheChangelog());
8888
foreach ($changelog as $line){
@@ -96,6 +96,23 @@ public static function getPhpFastCacheVersion($fallbackOnReadme = true, $cacheab
9696
throw new phpFastCacheLogicException('shell_exec being disabled we attempted to retrieve the PhpFastCache version through the CHANGELOG.md file but it is not readable or has been removed.');
9797
}
9898

99+
/**
100+
* @return string
101+
* @throws \phpFastCache\Exceptions\phpFastCacheLogicException
102+
*/
103+
public function getPhpFastCacheGitHeadHash()
104+
{
105+
if(function_exists('shell_exec')){
106+
$stdout = shell_exec('git rev-parse --short HEAD');
107+
if(is_string($stdout)){
108+
$hash = trim($stdout);
109+
return "#{$hash}";
110+
}
111+
}
112+
return '';
113+
}
114+
115+
99116
/**
100117
* Return the API changelog, as a string.
101118
* @return string

src/phpFastCache/Helper/TestHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TestHelper
3434
*/
3535
public function __construct($testName)
3636
{
37+
$this->printText('[PhpFastCache CORE v' . Api::getPhpFastCacheVersion() . Api::getPhpFastCacheGitHeadHash() . ']', true);
3738
$this->printText('[PhpFastCache API v' . Api::getVersion() . ']', true);
3839
$this->printText("[Begin Test: '{$testName}']");
3940
$this->printText('---');

0 commit comments

Comments
 (0)