Skip to content

Commit

Permalink
Merge a2ca6a7 into b36babb
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiYang committed Oct 3, 2018
2 parents b36babb + a2ca6a7 commit cf926ce
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
14 changes: 14 additions & 0 deletions Classes/Configuration/ExtensionConfiguration.php
Expand Up @@ -52,6 +52,11 @@ final class ExtensionConfiguration implements SingletonInterface
*/
private static $gitFormat = '';

/**
* @var string
*/
private static $staticVersion = '';

/**
* Fetch absolute version filename.
*
Expand Down Expand Up @@ -86,13 +91,22 @@ public static function getGitFormat(): string
return self::$gitFormat;
}

/**
* @return string
*/
public static function getStaticVersion(): string
{
return self::$staticVersion;
}

public function __construct()
{
self::$configuration = $this->getExtensionConfigurationFromGlobals();

self::$versionFilePath = $this->resolveVersionFilePath();
self::$mode = self::$configuration['mode'];
self::$gitFormat = self::$configuration['gitFormat'];
self::$staticVersion = self::$configuration['staticVersion'];
}

/**
Expand Down
1 change: 1 addition & 0 deletions Classes/Enumeration/ProjectVersionModeEnumeration.php
Expand Up @@ -23,4 +23,5 @@ final class ProjectVersionModeEnumeration
const FILE = '0';
const GIT = '1';
const GIT_FILE_FALLBACK = '2';
const STATIC = '3';
}
11 changes: 11 additions & 0 deletions Classes/Service/ProjectVersionService.php
Expand Up @@ -45,6 +45,9 @@ public function getProjectVersion(): ProjectVersion
$projectVersion = GeneralUtility::makeInstance(ProjectVersion::class);

switch (ExtensionConfiguration::getMode()) {
case ProjectVersionModeEnumeration::STATIC:
$this->setStaticVersion($projectVersion);
break;
case ProjectVersionModeEnumeration::GIT:
$this->setVersionFromGit($projectVersion);
break;
Expand Down Expand Up @@ -124,6 +127,14 @@ protected function isGitAvailable(): bool
$returnCode === 0;
}

/**
* @param ProjectVersion $projectVersion
*/
private function setStaticVersion(ProjectVersion $projectVersion)
{
$projectVersion->setVersion(ExtensionConfiguration::getStaticVersion());
}

/**
* Resolve version by common VERSION-file.
*
Expand Down
56 changes: 54 additions & 2 deletions Tests/Unit/Service/ProjectVersionServiceTest.php
Expand Up @@ -37,8 +37,10 @@ class ProjectVersionServiceTest extends UnitTestCase
private $subject;

private $extensionConfiguration = [
'versionFilePath' => 'VERSION',
'mode' => ProjectVersionModeEnumeration::FILE
'gitFormat' => GitCommandEnumeration::FORMAT_REVISION_BRANCH,
'mode' => ProjectVersionModeEnumeration::FILE,
'staticVersion' => '',
'versionFilePath' => 'VERSION'
];

/**
Expand Down Expand Up @@ -263,6 +265,56 @@ public function gitFormatDataProvider(): array
];
}

/**
* @test
*/
public function getProjectVersionShouldAlwaysSetStaticVersionIfSelected()
{
$this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::STATIC;
$this->setUpExtensionConfiguration();

$projectVersionProphecy = $this->prophesize(ProjectVersion::class);
GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal());

$this->subject->getProjectVersion();

$projectVersionProphecy->setVersion('')->shouldHaveBeenCalledTimes(1);
}

/**
* @test
* @param string $staticVersion
* @dataProvider staticVersionDataProvider
*/
public function getProjectVersionShouldSetStaticVersionFromExtensionConfigurationIfSelected(string $staticVersion)
{
$this->extensionConfiguration['mode'] = ProjectVersionModeEnumeration::STATIC;
$this->extensionConfiguration['staticVersion'] = $staticVersion;
$this->setUpExtensionConfiguration();

$projectVersionProphecy = $this->prophesize(ProjectVersion::class);
GeneralUtility::setSingletonInstance(ProjectVersion::class, $projectVersionProphecy->reveal());

$this->subject->getProjectVersion();

$projectVersionProphecy->setVersion($staticVersion)->shouldHaveBeenCalledTimes(1);
}

public function staticVersionDataProvider(): array
{
return [
'empty static version (default value)' => [
'staticVersion' => ''
],
'some value' => [
'staticVersion' => 'some value'
],
'some extreme long value' => [
'staticVersion' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos hic ipsa labore molestiae nesciunt quo repellendus similique tenetur vitae voluptatem! Dicta dolor minus nostrum ratione voluptas? Ad animi iste sunt!'
]
];
}

protected function setUp()
{
$this->systemEnvironmentBuilderFacadeProphecy = $this->prophesize(SystemEnvironmentBuilderFacade::class);
Expand Down
5 changes: 4 additions & 1 deletion ext_conf_template.txt
@@ -1,8 +1,11 @@
# cat=basic/enable; type=string; label=VERSION file path
versionFilePath = VERSION

# cat=basic/enable; type=options[VERSION File=0,GIT=1,GIT (VERSION file as fallback)=2]; label=Get project version by:
# cat=basic/enable; type=options[VERSION File=0,GIT=1,GIT (VERSION file as fallback)=2,Static Version=3]; label=Get project version by:
mode = 0

# cat=basic/enable; type=options[Revision=0,[revision] branch=1,[revision] tag=2,Branch=3,Tag=4]; label=Get project version by:
gitFormat = 1

# cat=basic/enable; type=string; label=Static version value (will only have effect if 'basic.mode' is set to 'Static Version')
staticVersion =

0 comments on commit cf926ce

Please sign in to comment.